这两天,做一个别的系统,想把数据写到数据库中,但是发现用安装的原有的二进制mysql,缺包,我用软连做到系统下,但是还是不行,
最终决定安装源代码的mysql,安装后就用我需要的包了。
我这里安装的是mysql-5.0.24版本,
下载地址:
安装mysql-5.0.24.tar.gz
说明:
--sysconfdir=/usr/local/conf 指定my.cnf路径 #而且这个目录是要创建的
tar -zxvf mysql-5.0.24.tar.gz
cd mysql-5.0.24
./configure --prefix=/usr/local/mysql --with-embedded-server --without-debug --enable-assembler --with-charset=utf8 --with-extra-charsets=all --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --sysconfdir=/usr/lcoal/conf
make && make install
make clean
mkdir /usr/lcoal/mysql/tmp
mkdir /usr/local/mysql/var
groupadd mysql
useradd -g mysql mysql
cd /usr/server
chmod 750 mysql -r
chgrp mysql mysql -r
chown mysql mysql/var -r
chown mysql mysql/tmp -r
cp support-files/my-medium.cnf.cn /usr/local/conf/my.cnf
现在如果直接启动会出现错误,我们需要修改my.cnf文件
如下修改:
[client]
port = 3306
socket = /usr/local/mysql/tmp/mysql.sock
[mysqld]
port = 3306
socket = /usr/local/mysql/tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/var
然后开始安装
/usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/var
启动mysql
/usr/local/mysql/bin/mysqld_safe --user=mysql &
至此我们的源码安装mysql就完成了
我们可以使用脚本启动,可以做一个mysql的脚本放到/usr/local/mysql下,
vi mysql
#!/bin/sh
mysql_port=3306
mysql_username="admin" #这里可以是root用户,也可以是你给定的一个用户来作为启动用户。
mysql_password="123456"
function_start_mysql()
{
printf "Starting MySQL...\n"
/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/conf/my.cnf 2>&1 > /dev/null &
}
function_stop_mysql()
{
printf "Stoping MySQL...\n"
/usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /usr/local/mysql/tmp/mysql.sock shutdown
}
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 5
function_start_mysql
}
function_kill_mysql()
{
kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')
kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')
}
if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
printf "Usage: /usr/local/mysql/mysql {start|stop|restart|kill}\n"
fi
保存退出。
我们直接可以/usr/loca/mysql/mysql start来做启动。
#我安装编译时候出现过一个错误:
/usr/bin/ld: cannot find -lz
这个问题是缺少zlib库的问题,但是我查看我有这个库,我系统是centOS,所以我直接yum ,它告诉我已经安装了,编译mysql的时候还是出现这个错误,我索性安装了一个源码的zlib包,然后再编译就过去了,感觉的zlib库损坏。
阅读(1228) | 评论(0) | 转发(0) |