好记忆也需烂 2020-04-17
2、检查数据库当前状态
[ ~]# lsof -i :3306
[ ~]# lsof -i :3306
3、设置server-id的值并开启binlog功能参数(主库51上上操作)
1)修改主库的配置文件。执行vi /etc/my.cnf
[mysqld]
server_id = 1
log_bin = /application/mysql/logs/oldboy-bin
2)检查配置参数之后的结果:
[ ~]# egrep "server_id|log_bin" /etc/my.cnf
3)重启主库mysql服务:
[ ~]# /etc/init.d/mysqld restart
4)登录数据库检查参数的更改情况:
[ ~]# mysql -e "show variables like ‘log_bin‘;"
[ ~]# mysql -e "show variables like ‘server_id‘;"
4、在主库上创建用于主从复制的账号
1)登录主库(172.16.1.51),命令如下
[ ~]# mysql --为了方便操作,密码已写入my.cnf配置文件
2)建立用于从库复制的账号及对应的权限
mysql> grant replication slave on . to ‘rep‘@‘172.168.1.%‘ identified by ‘oldboy123‘;
mysql> flush privileges;
3)检查主库创建的rep复制账号
mysql> select user,host from mysql.user;
mysql> show grants for ‘172.16.1.%‘;
5、对主库锁表只读后进行备份
1)对主库锁表只读(当前窗口不要关掉)的命令如下:
mysql> flush table with read lock;
mysql> show variables like ‘%timeout%‘;
2)锁表后查看查看主库只读(当前窗口不要关掉)的命令如下: