Mysql 主從配置

來源:互聯網
上載者:User

標籤:mysql 主從配置

mysql主從伺服器:

主:192.168.121.128

從:192.168.121.129



主從伺服器分別作以下操作:

版本一致

初始化表,並在後台啟動mysql

修改root的密碼

mysqladmin -u root password "newpass"

mysql主從檔案的配置:

#master主設定檔添加以下2行:


cat /etc/my.cnf 

log-bin=mysql-bin//[必須]啟用二進位日誌

server-id=128//[必須]伺服器唯一ID,預設是1,一般取IP最後一段

#slave設定檔添加以下2行:

cat /etc/my.cnf

log-bin=mysql-bin//[不是必須]啟用二進位日誌

server-id=129 //[必須]伺服器唯一ID,預設是1,一般取IP最後一段



主庫操作:


#mysql -uroot -p


GRANT REPLICATION SLAVE ON *.* to ‘mysync‘@‘192.168.121.129‘ identified by ‘123456‘;


mysql> show master status;

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

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

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

| mysql-bin.000001 |      264 |              |                  |

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

1 row in set (0.00 sec)




從庫操作:


mysql> change master to master_host=‘192.168.121.128‘,master_user=‘mysync‘,master_password=‘123456‘,master_log_file=‘mysql-bin.000001‘,master_log_pos=

Query OK, 0 rows affected (0.03 sec)


mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)


mysql> show slave status;


#看到下面資訊證明主從ok。

Slave_IO_Running: Yes

Slave_SQL_Running: Yes




本文出自 “LINUX Super夢” 部落格,請務必保留此出處http://215687833.blog.51cto.com/6724358/1892751

Mysql 主從配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.