free -h
cd /
ls -lrth
service mysql status
mysql -uroot -p
source /etc/profile
cd /data/log
cat error.err | grep "password is generated for root@localhost"
alter user user() identified by 'Etve3grTfEFso6jl';
主库设置:
备份主库mysql 文件,
du -sh mysql命令查看数据目录大小,
du -sh *|sort -rn|grep 'G' 过滤大于G的
tail -n 20 20240416.sql ,查看文件最后20行
mysqldump -uroot -p --single-transaction --master-data=2 -R -E --triggers -hlocalhost -A >20240412.sql
在执行mysqldump命令时候报如下错误:
[root@localhost ~]# mysqldump -uroot -p******* --all-databases> all.sql
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/data/mysql/mysql.sock' (2) when trying to connect
找到正确的套接字的路径:
[root@localhost ~]# netstat -ln | grep mysql
unix 2 [ ACC ] STREAM LISTENING 2447213870 /data/mysql/data/mysql.sock
再运行dump命令:
mysqldump --socket=/data/mysql/data/mysql.sock -uroot -p --single-transaction --master-data=2 -hlocalhost -A >20240416.sql
--传输备份文件到从服务器
scp 20230905bak.sql root@10.51.1.132:/root
scp 20240416.sql root@10.50.104.162:/backup
mysqldump -uetl_user -p --single-transaction --master-data=2 -R -E --triggers -hlocalhost -A >20230905bak.sql
如果要将mysql 数据库进行备份:
mysqldump -uetl_user -p mysql > mysql20230904bak.sql
看内容
less 20240416.sql
注释GTID
从库还原数据执行:
mysql -uroot -pAbc12345!@# -h127.0.0.1 --登录mysql
source /backup/20240416.sql --还原mysql备份文件
reset master;
stop slave ;
reset slave all;
--GTID配置
SET @@GLOBAL.GTID_PURGED='2f97bf10-0acd-11ea-912f-6c92bf64e6fa:1-8396510,
444d8cf8-6d79-11ea-87e6-00505690d903:1-6853230,
444d8cf8-6d79-11ea-87e6-00505690d908:1-100549285,
759ef2f1-adf1-11e9-a354-501d939ca2ae:1-59073';
change master to master_host='10.51.1.133',master_user='root',master_password='Etve3grTfEFso6jl',master_port=3306,MASTER_AUTO_POSITION = 1;
---pos配置
change master to master_host='10.50.104.161',master_user=root,master_password='4aeakcfCPK89xmZnoFMsC99!3gvsyskY',master_log_file='mysql-bin.000239',master_log_pos=355304605;
start slave;
show slave status \G
如果在其他服务器访问 从库报错1130 - Host '10.50.98.33' is not allowed to connect to this MySQL server,需要授权
grant all privileges on . to 'db_server'@'%' identified by 'FH6mnMBc!OCXzVH' with grant option;
FLUSH PRIVILEGES;