MySql主从复制配置,你了解吗?来看这篇,全懂了( 四 )
MySQL [(none)]> flush privileges;
Query OK, 0 rows affected (0.03 sec)
MySQL [(none)]> create user repl@'%' identified by 'repl';
Query OK, 0 rows affected (0.04 sec)
MySQL [(none)]> grant replication slave on *.* to 'repl'@'%';
Query OK, 0 rows affected (0.05 sec)
MySQL [(none)]> flush privileges;
Query OK, 0 rows affected (0.03 sec)
MySQL [(none)]> quit;
Bye
[root@localhost bin]#
两台MySQL数据库做主从配置,假设情况如下:
主机名
IP地址
角色
参数server-id
同步用户名
同步密码
pmondbs01
.81.49
主
1
repl
repl
pmondbs02
.81.50
从
10
repl
repl
数据库基本配置参考7.2、7.3 。
数据库主从配置参数server-id的值务必不能一样 。
参数server-id的值与前面章节保持一致 。
检查.81.49并设置server-id参数值 。
[root@pmondbs01 bin]# vi /etc/my.cnf
[mysqld]
server-id = 1
如果server-id参数值未设置为1,设置之后重启MySQL数据库,设置server-id参数值参考7.2安装MySQL 。
检查.81.50并设置server-id参数值 。
[root@pmondbs02 bin]# vi /etc/my.cnf
[mysqld]
server-id = 10
如果server-id参数值未设置为10,设置之后重启MySQL数据库,设置server-id参数值参考7.2安装MySQL 。
重启MySQL使用命令
执行顺序
命令
说明
1
service mysqld stop
停止MySQL
2
service mysqld start
启动MySQL
执行示意,以在服务器pmondbs01上为例
[root@pmondbs01 ~] # service mysql stop
[root@pmondbs01 ~] # service mysql start
1. 登录81.49 MySQL数据库,执行show master status,检查并记录Master状态 。记录File、Position,File为mysql-bin.000003,Position为194 。
使用命令
执行顺序
命令
说明
1
cd /usr/local/mysql/bin
进入MySQL安装目录的bin目录下
2
./mysql -uroot -p
启动MySQL客户端
3
password
输入root账号密码,进入MySQL命令行客户端 。
4
show master status;
查看Master状态
执行示意
[root@pmondbs01 ~]# cd /usr/local/mysql/bin
[root@pmondbs01 bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.22-log
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MySQL [(none)]>show master status;
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+
| mysql-bin.000002 | 3842 | | | 15aa5540-31fc-11ea-9d2d-84139f30d4bd:1-14,
4a871e1c-31eb-11ea-81b2-84139f30d4f5:13-15 |
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
MySQL [(none)]>
2. 登录.81.50 MySQL数据库,执行show master status,检查并记录Master状态 。记录File、Position,File为mysql-bin.000003,Position为194 。
使用命令
执行顺序
命令
说明
1
cd /usr/local/mysql/bin
进入MySQL安装目录的bin目录下
2
./mysql -uroot -p
启动MySQL客户端
3
password
输入root账号密码,进入MySQL命令行客户端 。
4
show master status;
查看Master状态
执行示意
[root@pmondbs02 ~]# cd /usr/local/mysql/bin
[root@pmondbs02 bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.22-log
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MySQL [(none)]>show master status;
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+
推荐阅读
- Mysql主从模式搭建
- 可是国内的永乐大钟,却无法复制 永乐大钟
- DNA的复制是你想象不到的更精彩 dna复制特点
- 空白代码复制粘贴?空白昵称代码如何复制
- 附:解决办法 电脑复制后不能粘贴是什么原因
- 冒险岛怪盗幻影偷什么技能啊?拒绝复制的 怪盗幻影女郎
- 奥黛丽·赫本|奥黛丽赫本:一代女神,无法复制的经典
- 文玩|文玩圈中珍贵的复制品,不但不是仿品,还具有收藏价值
- 王志文|王志文带儿子拍亲子照,爷俩就像复制粘贴一样,这孩子有点像邓伦
- iphone如何导出通讯录,苹果通讯录复制到sim卡教程