MYSQL主從搭建

主從版本一致
master端
[root@puppetmaster ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
log-bin = mysql-bin //[必須]啓用二進制日誌
server-id=1 //[必須]服務器唯一ID,默認是1,
# Default to using old password format for compatibility with mysql3.x
# clients (those using the mysqlclient10 compatibilitypackage).
old_passwords=1

# Disabling symbolic-links is recommended to prevent assortedsecurity risks;
# to do so, uncomment this line:
# symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


授權(在主服務器上進行) GRANT REPLICATION SLAVE ON *.* to'slave1'@'192.168.188.143identified by '123456';
mysql>flush privileges;

mysql>flush tables with read lock;

將從庫的database導入 mysql -u root -p dashboard </home/dashboard.sql(必須有dashboard庫 如沒有則創建 created databasedashboard;)

主庫 mysql 解鎖
mysql>unlock tables;

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


配置從服務器 mysql> change master tomaster_host='192.168.188.151', master_user='slave1',master_password='123456', master_log_file='mysql-bin.000002',master_log_pos=373;

從服務器上my.cnf
也啓動二進制日誌
[root@logserver-SW ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
server-id = 2
# Default to using old password format for compatibility with mysql3.x
# clients (those using the mysqlclient10 compatibilitypackage).
old_passwords=1

# Disabling symbolic-links is recommended to prevent assortedsecurity risks;
# to do so, uncomment this line:
# symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

正確執行後再執行: mysql> startslave;


mysql> show slave status\G

mysql> show slave status\G;
*************************** 1. row***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.188.151
Master_User: slave1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 373
Relay_Log_File: mysqld-relay-bin.000004
Relay_Log_Pos: 510
Relay_Master_Log_File: mysql-bin.000002
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: 373
Relay_Log_Space: 510
Until_Condition: None

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章