1.新建备份目录
shell
mkdir -p /data/mysql_dump/
#查找mysql配置位置
find / -name "my.cnf"
find / -name "mysql.sock"
find / -name "mysqldump"
2.定时任务
bash
#每天凌晨备份一次
echo "00 00 * * * root /data/mysql_bak.sh" >> /etc/crontab
cat > /data/mysql_bak.sh <<-'EOF'
#!/bin/bash
export MYSQL_PWD=LAGWcePJ6#JZ#7
/data/app/mysql/bin/mysqldump -uroot --all-databases --single-transaction > /data/mysql_dump/mysql_`date +%Y%m%d`.sql
#本地备份拷贝到文件服务器一份
rsync -avzu --progress /data/mysql_dump/*sql root@10.10.10.4:/data/mysql_dump/10.10.10.3
#del
find /data/mysql_dump/ -mtime +7 -name '*.sql' -exec rm -rf {} \;
EOF
#授权
chmod +x /data/mysql_bak.sh
#root免密参考
ssh-keygen -t rsa -P ''
for i in ceph1 ceph2 ceph3; ; do ssh-copy-id -i ~/.ssh/id_rsa.pub root@$i; done
#验证免密
for i in ceph1 ceph2 ceph3; do ssh root@$i hostname; done
#服务器更换了密码,进入文件,删除ip,重新 拷贝免密文件
vim /root/.ssh/known_hosts
3.强制root改密
shell
vim /etc/my.cnf
[mysqld]
skip-grant-tables
#重启mysql
systemctl restart mysqld && systemctl status mysqld
#登入mysql
#mysql -u root -p123456
mysql -u root -p
use mysql;
select host,user from user where user='root';
alter user 'root'@'%localhost' identified by 'LAGWcePJ6#JZ#7';
grant all privileges on *.* to 'root'@'localhost' with grant option;
flush privileges;
#报错ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%localhost'
#ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
flush privileges;
set password for root@localhost=password('LAGWcePJ6#JZ#7');
flush privileges;
exit
systemctl restart mysqld && systemctl status mysqld