ubuntu mysql 主從複製

 

1.主服務開啓log_binmysql

# vim /etc/mysql/my.cnf
....
server-id               = 55
log_bin                 = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M
...

修改完mysql配置後重啓mysqllaravel

# service mysql restart

受權從機權限sql

mysql > grant replication slave on *.* to slave@120.78.62.47 identified by "123456";

刷新權限數據庫

mysql> flush privileges;

查看主狀態vim

mysql> show master status
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 |     2821 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

重啓mysql#

#service mysql restart

2.從機bash

開啓備份ide

# vim /etc/mysql/my.cnf

 

server-id               = 33
log_bin                 = /var/log/mysql/mysql-bin.log

重啓mysqlspa

# service mysql restart

 

mysql> change master to 
     master_host='47.52.100.111',
     master_user='slave',
     master_log_file='mysql-bin.000012',
     master_password='123456',
     master_log_pos=106028;

 

若是報錯rest

ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log

請刪除文件:code

/var/lib/mysql/master.info
/var/lib/mysql/relay-log.info

開啓主從備份並查看

mysql > start slave
mysql > show slave status\G;
 
....
            Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
...

表示成功

複製數據庫

因爲備份數據並無初始起來,緣由也查了不少,沒有解決,想到了個折中的辦法:複製數據庫,

mysqldump bshop-test -uroot -p123456 --add-drop-table | mysql bshop -uroot -p23456

bshop-test爲被複制對象,而後再複製回來,達到數據初始數據一致

mysqldump bshop -uroot -p123456 --add-drop-table | mysql bshop-test -uroot -p123456
相關文章
相關標籤/搜索