目录
一、MySQL57版本配置+Linux6/7中
1、配置启动脚本及自动启动——方式1——service start mysql
(1)利用mysql.server进行修改
[root@mysql51 mysql]# cd /mysql/app/mysql/support-files/ [root@mysql51 support-files]# cp mysql.server mysql.server.bak
注:如果数据库有多个实例,可以将mysql改为多个,比如mysql3306,mysql3307,没mysql3308等,配置多个自动启动实例。
(2)编辑mysql.server中的参数增加值
vi /mysql/app/mysql/support-files/mysql.server
basedir=/mysql/app/mysql #默认识别/usr/local/mysql datadir=/mysql/data/3306/data mysqld_pid_file_path=/mysql/data/3306/mysql.pid
(3)替换启动文件mysql中的/usr/local/mysql/data为/mysql/data/3306/data
sed -i 's/\/usr\/local\/mysql\/data/\/mysql\/data\/3306\/data/g' mysql.server
(4)替换启动文件mysql中的/usr/local/mysql为/mysql/app/mysql
sed -i 's/\/usr\/local\/mysql/\/mysql\/app\/mysql/g' mysql.server
(5)修改启动位置--my.cnf的定位
vi /mysql/app/mysql/support-files/mysql.server
将如下参数:
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
改为:
$bindir/mysqld_safe --defaults-file=/mysql/data/3306/my.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
(6)拷贝mysql.server文件到/etc/init.d中
注:如果数据库有多个实例,可以将mysql改为多个,比如mysql3306,mysql3307,没mysql3308等,配置多个自动启动实例。
[root@mysql51 support-files]# cp /mysql/app/mysql/support-files/mysql.server/etc/init.d/mysql
自动启动;chkconfig --level 35 mysql on
(7)启停验证,日志查看
[root@mysql51 ~]# service mysql start [root@mysql51 ~]# service mysql stop
注:在启动服务时,可能会遇到The server quit without updating PID file (/mysql/data/3306/mysql.pid).[FAILED]问题,处理方法见:https://www.topunix.com/post-8978.html
(8)配置chkconfig自动启动
[root@mysql51 ~]# chkconfig --list|grep mysql [root@mysql51 ~]# chkconfig --level 35 mysql on
--重启服务器,发现已经自动启动了
--mysql进程查看
2、配置启动脚本及自动启动——方式2
(1)配置msyql.start脚本
/mysql/app/mysql/bin/mysqld_safe --defaults-file=/mysql/data/3306/my.cnf --user=msyql &
(2)加入自动启动
vi /etc/rc.local /mysql/data/3306/mysql.start
(3)数据库关闭(处理完12的过期密码问题后,才可以正常关闭服务)
[root@mysql51 mysql]# mysqladmin -uroot -p shutdown -S /mysql/data/3306/mysql.sock
二、MySQL57版本自启动配置+Linux7/8中——systemctl start mysqld
1.利用mysql.server修改
cp /mysql/app/mysql/support-files/mysql.server /mysql/app/mysql/support-files/mysql.server.bak
2.编辑mysql中的参数增加值-修改本机对应配置
vi /mysql/data/mysql.server
basedir=/mysql/app/mysql datadir=/mysql/data/3306/data mysqld_pid_file_path=/mysql/data/3306/mysql.pid if test -z "$basedir" then basedir=/mysql/app/mysql bindir=/mysql/app/mysql/bin if test -z "$datadir" then datadir=/mysql/data/3306/data fi sbindir=/mysql/app/mysql/bin libexecdir=/mysql/app/mysql/bin else bindir="$basedir/bin" if test -z "$datadir" then datadir="/mysql/app/3306/data" fi sbindir="$basedir/sbin" libexecdir="$basedir/libexec" fi
将如下参数:
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
改为:
$bindir/mysqld_safe --defaults-file=/mysql/data/3306/my.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
3.下载mysqld配置
cd /mysql/data wget https://download.topunix.com/MySQL/config-MySQL5.7/mysqld.service
4.修改对应配置(如果mysql.server在其他目录下)
vi /mysql/data/mysqld.service ExecStart=/mysql/app/mysql/support-files/mysql.server start
5.拷贝文件到Linux 7的/usr/lib/systemd/system/目录下
# set the auto start on linux server started
cp /mysql/data/mysqld.service /usr/lib/systemd/system/
6.配置自动启动
systemctl disable mysqld systemctl enable mysqld
7.测试停止mysqld服务
systemctl daemon-reload systemctl stop mysqld systemctl start mysqld systemctl status mysqld 注:如果出现stop后无法真正停止,需要手动kill掉进程,重新启动就ok了。
三、MySQL8.0版本自启动配置+Linux7/8中
1、配置启动脚本及自动启动方式-1(推荐使用)——systemctl start mysqld
(1)下载mysql.server启动配置文件
cd /mysql/data wget https://download.topunix.com/MySQL/config-MySQL8.0/mysql.server
(2)修改本机对应配置
vi /mysql/data/mysql.server
basedir=/mysql/app/mysql datadir=/mysql/data/3306/data mysqld_pid_file_path=/mysql/data/3306/mysql.pid if test -z "$basedir" then basedir=/mysql/app/mysql bindir=/mysql/app/mysql/bin if test -z "$datadir" then datadir=/mysql/data/3306/data fi sbindir=/mysql/app/mysql/bin libexecdir=/mysql/app/mysql/bin else bindir="$basedir/bin" if test -z "$datadir" then datadir="/mysql/app/3306/data" fi sbindir="$basedir/sbin" libexecdir="$basedir/libexec" fi
(3)备份support-files中的mysql.sever,并移入下载的mysql.server
cd /mysql/app/mysql/support-files/ mv mysql.server mysql.server.bak mv /mysql/data/mysql.server /mysql/app/mysql/support-files/ chown mysql:mysql /mysql/app/mysql/support-files/mysql.server chmod +x /mysql/app/mysql/support-files/mysql.server
(4)下载mysqld配置
cd /mysql/data wget https://download.topunix.com/MySQL/config-MySQL8.0/mysqld.service
(5)修改对应配置(如果mysql.server在其他目录下)
vi /mysql/data/mysqld.service ExecStart=/mysql/app/mysql/support-files/mysql.server start
(6)拷贝文件到Linux 7的/usr/lib/systemd/system/目录下
# set the auto start on linux server started
cp /mysql/data/mysqld.service /usr/lib/systemd/system/
(7)配置自动启动
systemctl disable mysqld systemctl enable mysqld
(8)测试停止mysqld服务
systemctl daemon-reload systemctl stop mysqld systemctl start mysqld systemctl status mysqld 注:如果出现stop后无法真正停止,需要手动kill掉进程,重新启动就ok了。
2、配置启动脚本及自动启动方式-2(8.0不推荐使用)
(1)通过写脚本:
echo "/mysql/app/mysql/bin/mysqld_safe --defaults-file=/mysql/data/3306/my.cnf --user=mysql &" >/mysql/app/mysql/bin/mysql.start chown mysql:mysql /mysql/app/mysql/bin/mysql.start chmod +x /mysql/app/mysql/bin/mysql.start
(2)配置开机自动启动:
vi /etc/rc.d/rc.local /mysql/app/mysql/bin/mysql.start