You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.7 KiB

1 month ago
#/bin/bash
set -x
OldPath="/var/log/mysql"
TargetPath="/data/mysql/binlog"
if [ -d ${TargetPath} ] ;then
echo "TargetPath is exists"
exit -1
fi
echo "let's do it"
# 检查一下服务器进程有没有停了
SogCount=`ps -ef|grep -i SogLoader|grep -v grep|grep -v changeMysql |wc -l`
if [ ${SogCount} != 0 ] ;then
echo "error ; P sog is not stop"
exit -1;
fi
echo "change mysql binlog path";
echo "stoping mysql"
sudo service mysql stop
#检查一下MySQL有没有没正常停掉
Pmysql=`ps -ef |grep -i mysql |grep -v grep|grep -v changeMysql |wc -l`
if [ ${Pmysql} != 0 ] ;
then
echo " error ; P myslq is not stop"
fi
netstat -tl | grep mysql
sudo cp -rf ${OldPath} ${TargetPath}
if [ ! -d ${TargetPath} ] ;then
echo "TargetPath not Creat"
exit -1
fi
sudo chown -R mysql:mysql ${TargetPath}
sudo chmod 775 -R ${TargetPath}
#更改mysql配置
sudo sed -i -e 's/^log-bin.*/log-bin = \/data\/mysql\/binlog\/mysql-bin.log/g' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo sed -i -e 's/^log_bin.*/log_bin = \/data\/mysql\/binlog\/mysql-bin.log/g' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo sed -i -e 's/^log-error.*/log-error = \/data\/mysql\/binlog\/error.log/g' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo sed -i -e 's/^log_error.*/log_error = \/data\/mysql\/binlog\/error.log/g' /etc/mysql/mysql.conf.d/mysqld.cnf
#路径赋予权限
sudo sed -i '/\/var\/log\/mysql\/\*\* rw,/a\ \/data\/mysql\/binlog\/ r,\n \/data\/mysql\/binlog\/** rw,' /etc/apparmor.d/usr.sbin.mysqld
#权限生效
sudo /etc/init.d/apparmor restart
sudo service mysql start
Pmysql=`ps -ef |grep -i mysql |grep -v grep|grep -v changeMysql |wc -l`
if [ ${Pmysql} = 0 ] ;then
echo " error ; P myslq is not start"
fi
netstat -tl | grep mysql