新聞中心
此文章主要介紹的是在linux操作系統(tǒng)下正確建立MySQL鏡像數(shù)據(jù)庫的實際操作步驟,教你在linux操作系統(tǒng)下正確建立MySQL鏡像數(shù)據(jù)庫的實際操作步驟在實際操作是經(jīng)常被用到了,所以你對其有更多的了解還是好的。

網(wǎng)站建設哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、微信小程序、集團企業(yè)網(wǎng)站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了蕪湖免費建站歡迎大家使用!
MySQL(和PHP搭配之最佳組合)版本:4.1
環(huán)境介紹:主庫 192.168.0.205 從庫 192.168.0.206
1、主庫創(chuàng)建/etc/my.cnf,修改[MySQL(和PHP搭配之最佳組合)d]里邊的鍵值增加
- server-id=1
- log-bin=binlog_name
2、主庫增加用戶,用于從庫讀取主庫日志。
- grant replication slave,reload,super on *.* to ’slave’@’192.168.0.206’ identified by ’123456’
3、從庫連接主庫進行測試。
/opt/MySQL(和PHP搭配之最佳組合)/bin/MySQL(和PHP搭配之最佳組合) -u slave -p -h 192.168.0.205
4、停從庫,修改從庫/etc/my.cnf,增加選項:
[MySQL(和PHP搭配之最佳組合)d] server-id=2 master-host=192.168.0.205 master-user=slave master-password=123456
5、啟動從庫,進行主從庫數(shù)據(jù)同步
/opt/MySQL(和PHP搭配之最佳組合)/share/MySQL(和PHP搭配之最佳組合)/MySQL(和PHP搭配之最佳組合) start
/opt/MySQL(和PHP搭配之最佳組合)/bin/MySQL(和PHP搭配之最佳組合) -u root -p
MySQL(和PHP搭配之最佳組合)>load data from master;
說明:這一步也可以用數(shù)據(jù)庫倒入或者直接目錄考過來。
6、進行測試:
主庫創(chuàng)建表,
MySQL(和PHP搭配之最佳組合)>create database sampdb; MySQL(和PHP搭配之最佳組合)>create table new (name char(20),phone char(20)); MySQL(和PHP搭配之最佳組合)>insert into new (’abc,’0532555555’);
打開從庫,察看:
/opt/MySQL(和PHP搭配之最佳組合)/bin/MySQL(和PHP搭配之最佳組合) -u root -p MySQL(和PHP搭配之最佳組合)>show database; MySQL(和PHP搭配之最佳組合) sampdb test MySQL(和PHP搭配之最佳組合)>use sampdb; MySQL(和PHP搭配之最佳組合)>show tables; new
說明主從數(shù)據(jù)庫創(chuàng)建成功。
7、主從數(shù)據(jù)庫相關命令:
slave stop; slave start ; 開始停止從數(shù)據(jù)庫。
show slave status\G; 顯示從庫正讀取哪一個主數(shù)據(jù)庫二進制日志
purge master logs to ’binlog.000004’; 此命令非常小心,刪除主數(shù)據(jù)庫沒用的二進制日志文件。如果誤刪除,那么從庫就沒有辦法自動更新了。
change master; 從服務器上修改參數(shù)使用。
文章名稱:MySQL鏡像數(shù)據(jù)庫的正確建立在linux之下
當前鏈接:http://fisionsoft.com.cn/article/cdeehdj.html


咨詢
建站咨詢
