mysql主从配置

2018-10-26  本文已影响29人  云龙789

mysql主从配置本质就是读取二进制文件

主服务器中

/etc/mysql/mysql.conf.d/mysqld.cnf

server-id               = 1
log_bin                 = /var/log/mysql/mysql-bin.log
relay_log               = /var/log/mysql/mysql-relay-bin.log  #这个是同步信息的日志

保存并重启数据库 service mysql restart

在数据库中

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      154 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

为从服务器创建一个数据库账号 slave_user 密码 password

create user 'slave_user'@'192.168.10.10' identified by 'xiaolong'
赋值权限
grant  privileges on *.* to  'slave_user'@'192.168.10.10'
我不知道为什么有些教材中是
grant  privileges  salve on *.* to  'slave_user'@'192.168.10.10'
更新数据库权限 
mysql>flush privileges;

从服务器中

server-id               = 2 # 此处的值不能与 master 服务器里面的意义
log_bin                 = /var/log/mysql/mysql-bin.log
relay_log               = /var/log/mysql/mysql-relay-bin.log

mysql 终端执行:
 change master to 
master_host = '192.168.10.10',
master_user='xiaolong',
master_password='xiaolong',
master_log_file='mysql-bin.000002',
master_log_pos=154;

start slave; // 开启从数据

在从服务器中,为主服务器开启一个数据库账号密码,并赋值相应的权限

change master to 
master_host = '47.90.84.146',
master_user='xiaolong',
master_password='xiaolong',
master_log_file='mysql-bin.000001',
master_log_pos=154;
 这里面的信息值,都是主服务器上的

停止从服务器 stop slave start slave
未完待续。。。

上一篇下一篇

猜你喜欢

热点阅读