mysql数据库(DBMS+数据库)
系统:rock8.8
mysql:mariabd-server 10.3
前提:
关闭SElinux
关闭防火墙
时间同步
安装mariabd
yum -y install mariadb-server
准备三个实例的目录
mkdir -pv
/mysql/{3306,3307,3308}/{data,etc,socket,log,bin,pid}
生成数据文件
mysql_install_db --user=mysql --datadir=/mysql/3306/data
mysql_install_db --user=mysql --datadir=/mysql/3307/data
mysql_install_db --user=mysql --datadir=/mysql/3308/data
准备配置文件
vim /mysql/3306/etc/my.cnf
[mysqld]
port=3306
datadir=/mysql/3306/data
socket=/mysql/3306/socket/mysql.sock
log-error=/mysql/3306/log/mysql.log
pid-file=/mysql/3306/pid/mysql.pid
sed 's/3306/3307/' /mysql/3306/etc/my.cnf > /mysql/3307/etc/my.cnf #写入其他配置文件
准备启动脚本
vim /mysql/3306/bin/mysqld
#!/bin/bash
port=3306
mysql_user="root"
mysql_pwd="root"
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} -S ${mysql_sock}
# ${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
sed 's/3306/3308/' /mysql/3306/bin/mysqld > /mysql/3308/bin/mysqld
sed 's/3306/3307/' /mysql/3306/bin/mysqld > /mysql/3307/bin/mysqld #复制其他实例
启动服务
/mysql/3306/bin/mysqld start 或 mysql -uroot -proot -P3306
修改root密码
mysqladmin -uroot -S /mysql/3306/socket/mysql.sock password 'root' #将启动脚本也一起修改,启用密码
如果需要开机启动
/etc/rc.d/rc.load
/mysql/3306/bin/mysqld start