5.2.4创建管理MySQL数据库的shell脚本
vim /data/mysql/mysql
输入以下内容
#!/bin/sh
mysql_username="admin"
mysql_password="12345678"
function_start_mysql()
{
printf "Starting MySQL...\n"
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/data/mysql/my.cnf 2>&1 > /dev/null &
}
function_stop_mysql()
{
printf "Stoping MySQL...\n"
/usr/local/webserver/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' | awk '{printf $2}')
kill -9 $(ps -ef | grep 'libexec/mysqld' | 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: /data/mysql/mysql {start|stop|restart|kill}\n"
fi
加上可执行权限
chmod +x /data/mysql/mysql
5.2.5创建一个具有root权限的用户(admin)和密码(12345678)
启动数据库
/data/mysql/mysql start
通过命令行登录管理MySQL服务器(不用密码)
/usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
创建账号
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678';
FLUSH PRIVILEGES;
停止数据库
/data/mysql/mysql stop
phpmyadmin管理
可能phpmyadmin连接不上mysql,这是由于原来安装了MYSQL,需要修改php.ini,加上以下这个
mysql.default_socket =/tmp/mysql.sock
部署成功后,我们价网的速度明显快多了。