================================= 只是本人在搭建MYSQL主從服務器的筆記 ,不必定很好,高手能夠飄過 ================================= 雙主架構 master A <--> master B 第一步;改配置文件 ->默認位置/etc/my.cnf master的 [mysqld] log-bin=mysql-bin # 開啓二進制日誌 server-id=2 #ID的區分,兩臺主機的ID要不同 slave的 [mysqld] server-id=3 而後重啓服務 第二步:受權
MySQL報錯:The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
The MySQL server is running with the --skip-grant-tables option so it cannot execute this statementmysql
解決辦法:linux
mysql> set global read_only=0;
(關掉新主庫的只讀屬性)sqlflush privileges;
數據庫set global read_only=1;(讀寫屬相)服務器
flush privileges;架構
master上受權,super和replication slave都是複製要用的權限 mysql> grant super,replication slave on *.* to 'jerry'@'10.1.1.7' identified by '123'; mysql> flush privileges; mysql> show master status; --只有打開二進制日誌,這句命令纔有結果,表示當前數據庫的二進制日誌寫到什麼位置 +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 563 | | | +------------------+----------+--------------+------------------+ slave端的配置 mysql> slave stop; --若是沒有啓過slave,這一步也是非必要的 Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> show warnings; +-------+------+--------------------------------+ | Level | Code | Message | +-------+------+--------------------------------+ | Note | 1255 | Slave already has been stopped | +-------+------+--------------------------------+ //此處爲從的設置:須要master先受權 mysql> change master to -> master_user='jerry', -> master_password='123', -> master_host='10.1.1.6', --主的IP -> master_port=3306, --端口,若是爲3307就要換成3307 -> master_log_file='mysql-bin.000001', --主上面查到的文件名 -> master_log_pos=563; --主上面查到的位置號 change master to master_user='jerry',master_password='123',master_host='10.1.1.6',master_port=3306,master_log_file='mysql-bin.000001',master_log_pos=563; mysql> start slave; Query OK, 0 rows affected (0.00 sec) mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.1.1.6 Master_User: li Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 563 Relay_Log_File: mysql55-relay-bin.000002 Relay_Log_Pos: 253 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes --這裏兩個YES,表示兩個線程OK 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: 563 Relay_Log_Space: 411 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 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 2 1 row in set (0.00 sec) ................................... ***** Slave_IO_Running 爲NO,多爲受權或者防火牆設置的問題。此處通常爲SQL鏈接問題所至 ================================= 以上爲一主一從的設置方法,若是要設置雙主,就是所主從的關係變下,更新再設置一遍就是又主 注意點: 1. 受權記得要清下權限 flush privileags; 2. 記得防火牆的設置,主從服務器要PING得通 3. selinux (這個,我常常會忘記這塊的設置) =================================