标签:数据库 code size pid tar soc yum 配置 dev
实验:基于YUM安装的多实例yum install mariadb
mkdir /mysql/{3306,3307,3308}/{data,,socket,log,bin,pid} -pv
chown -R mysql.mysql /mysql
mysql_install_db --datadir=/mysql/3306/data/ --user=mysql
mysql_install_db --datadir=/mysql/3307/data/ --user=mysql
mysql_install_db --datadir=/mysql/3308/data/ --user=mysql
cp /etc/my.cnf /mysql/3306/etc
vim /mysql/3306/etc/my.cnf
[mysqld]
port=3306 加一行
datadir=/mysql/3306/data
socket=/mysql/3306/socket/mysql.sock
[mysqld_safe]
log-error=/mysql/3306/log/mariadb.log
pid-file=/mysql/3306/pid/mariadb.pid
cp /mysql/3306/etc/my.cnf /mysql/3307/etc/my.cnf
/mysql/3307/etc/my.cnf
cp /mysql/3306/etc/my.cnf /mysql/3308/etc/my.cnf
/mysql/3308/etc/my.cnf
vim /mysql/{3306,3307,3308}/bin/mysqld
cat /mysq/3306/bin/mysqld
#!/bin/bash
port=3306
mysql_user="root"
mysql_pwd=" "
cmd_path="/usr/bin"
mysql_basedir="/mysql"
mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"
function_start_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "Starting MySQL...\n"
${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null &
else
printf "MySQL is running...\n"
exit
fi
}
function_stop_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "MySQL is stopped...\n"
exit
else
printf "Stoping MySQL...\n"
${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
fi
}
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 2
function_start_mysql
}
case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n"
esac
chmod +x /mysql/{3306,3307,3308}/bin/mysqld
/mysql/{3306,3307,3308}/bin/mysqld start
/mysql/{3306,3307,3308}/bin/mysqld stop
记得更改脚本端口号
mysql -S /mysql/{3306,3307,3308}/socket/mysql.sock
mysqladmin -S /mysql/{3306,3307,3308}/socket/mysql.sock password ‘centos‘
vim /mysql/{3306,3307,3308}/bin/mysqld 加上对应centos口令
标签:数据库 code size pid tar soc yum 配置 dev
原文地址:https://blog.51cto.com/14234933/2388877