日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql master-slave_mysql 同步 master-slave

發布時間:2025/5/22 数据库 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql master-slave_mysql 同步 master-slave 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

mysql 同步 master-slave

這么一個簡單問題,在ubuntu居然搞了兩天,終于搞定了。

中途出了點問題,搞的郁悶一天的問題就是 change master? 語句,好了下面就開始講正題吧。

linux OS: ubuntu server 8.04.1

software: mysql5.0.51

mysql1? : 192.168.6.4??? //master

mysql2? : 192.168.6.5??? //slave

安裝步驟

1. 分別在兩臺機器上安裝mysql-server

shell > apt-get install mysql-server

2.修改 mysql1 master 的配置文件

vim /etc/mysql/my.cnf

找到 bind-address = 127.0.0.1

改為 bind-address = 0.0.0.0

找到

#server-id?????????????? = 1

#log_bin???????????????? = /var/log/mysql/mysql-bin.log

去掉 注釋符號

server-id?????????????? = 1

log_bin???????????????? = /var/log/mysql/mysql-bin.log

default-character-set?? = utf8???? #新加上的為了保持編碼一至防止出錯

3.改好后保存退出,然后建立一個slave服務器的用戶賬號

root@msyql1:/# mysql -uroot -p

mysql>? grant replication slave,replication client on *.* to ludy@'192.168.6.5' identified by 'ypmwbg';

mysql >? grant replication slave on *.* to ludy@192.168.6.5 identified by 'ypmwbg';???? //給予權限

到這里要注意了,我的兩臺數據庫都是空的.

重啟mysql服務

4.修改 mysql2 服務器slave的 my.cnf配置文件

找到 bind-address??????????? = 127.0.0.1

替換 bind-address??????????? = 0.0.0.0

找到

#server-id?????????????? = 1

#log_bin???????????????? = /var/log/mysql/mysql-bin.log

把 注釋符號去掉 改為如下

server-id?????????????? = 2

master-host???????????? = 192.168.6.4

master-user???????????? = ludy

master-password???????? = ypmwbg

master-port???????????? = 3306

log_bin???????????????? = /var/log/mysql/mysql-bin.log

log-slave-updates

skip-slave-start

配置完后 重新啟動mysql

然后進入 mysql1 master 服務器

root@msyql:~# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.? Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 5.0.51a-3ubuntu5.4-log (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show master status;

+------------------+----------+--------------+------------------+

| File???????????? | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| mysql-bin.000001 |????? 98? |????????????? |????????????????? |

+------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

記錄下來以后 進入 mysql2 slave mysql

root@msyql2:~# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.? Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 5.0.51a-3ubuntu5.4-log (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>? change master to master_log_file='mysql-bin.000001', master_log_pos=98;

//這個地方就是記錄下來的 mysql1 master 的數據

mysql > start slave;? //啟動slave 服務

mysql > show slave status\G

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.6.4

Master_User: ludy

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000001

Read_Master_Log_Pos: 181

Relay_Log_File: mysqld-relay-bin.000003

Relay_Log_Pos: 235

Relay_Master_Log_File: mysql-bin.000001

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 181

Relay_Log_Space: 235

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

1 row in set (0.01 sec)

哈哈 ???? Slave_IO_Running: Yes

Slave_SQL_Running: Yes

說明啟動成功

然后在 master 新建 一個數據庫看看

root@msyq1l:/# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.? Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 5.0.51a-3ubuntu5.4-log (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database chenggong;

Query OK, 1 row affected (0.00 sec)

在 salve 查看看是否同步

mysql> show databases;

+--------------------+

| Database?????????? |

+--------------------+

| information_schema |

| chenggong????????? |?? //同步了哈哈 ~

| mysql????????????? |

| test?????????????? |

+--------------------+

4 rows in set (0.01 sec)

好了就寫這么多,如果你作 master-slave 的時候 你的master 數據里有數據那么

你必須 在? 我寫的 第三步與第四步中加入一下步驟:

接 上文 第三步進入master數據庫的Mysql控制臺執行

mysql >FLUSH TABLES WITH READ LOCK; ? //鎖表

然后從新打開一個 終端 拷貝 master 的所有的數據到 slave 服務器覆蓋

讀取? master 二進制文件與偏移量

mysql > show master status;

同樣 要記錄下 file 與 position 的值

然后解鎖

mysql > unlock tables;

?著作權歸作者所有:來自51CTO博客作者Deidara的原創作品,如需轉載,請注明出處,否則將追究法律責任

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的mysql master-slave_mysql 同步 master-slave的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。