CentOS 5.4 x86_64 编译安装 MySQL 完全笔记
MySQL编译安装笔记
大前提,你的Linux系统要搭建好GCC的编译环境。
使用CentOS的话可以:
yum -y install gcc
yum -y install gcc-c++
添加MySQL用户组和用户
grounadd mysql
useradd -g mysql mysql
MySQL编译安装依赖的软件包:
cd /tmp
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.7.tar.gz
tar -zvxf ncurses-5.7.tar.gz
cd ncurses-5.7
./configure --prefix=/usr --with-shared --without-debug
make
make install
创建管理MySQL数据库的shell脚本:
vi /usr/local/mysql/mysql
输入以下内容并保存(这里的用户名root和密码123456接下来的步骤会创建):
#!/bin/sh
mysql_port=3306
mysql_username="root"
mysql_password="123456"
function_start_mysql()
{
printf "Starting MySQL...\n"
/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/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 /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
赋予MySQL数据库的shell脚本可执行权限:
chmod +x /usr/local/mysql/mysql
启动MySQL:
/usr/local/mysql/mysql start
通过命令行登录管理MySQL服务器(提示输入密码时直接回车):
/usr/local/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
输入以下SQL语句,创建一个具有root权限的用户(root)和密码(123456):
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY '123456';
停止MySQL命令:
/usr/local/mysql/mysql stop