溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

linux操作系統(tǒng)下建立mysql鏡像數(shù)據(jù)庫(轉(zhuǎn))

發(fā)布時(shí)間:2020-08-08 13:33:18 來源:ITPUB博客 閱讀:209 作者:BSDLite 欄目:MySQL數(shù)據(jù)庫
linux操作系統(tǒng)下建立mysql鏡像數(shù)據(jù)庫(轉(zhuǎn))[@more@]  MySQL 版本:4.1

  環(huán)境介紹:主庫 192.168.0.205 從庫 192.168.0.206

  1、主庫創(chuàng)建/etc/my.cnf,修改[mysqld]里邊的鍵值增加



  server-id=1   log-bin=binlog_name



  2、主庫增加用戶,用于從庫讀取主庫日志。

  grant replication slave,reload,super on *.* to ’slave’@’192.168.0.206’ identified by ’123456’

  3、從庫連接主庫進(jìn)行測試。



/opt/mysql/bin/mysql -u slave -p -h 192.168.0.205



  4、停從庫,修改從庫/etc/my.cnf,增加選項(xiàng):

[mysqld] server-id=2 master-host=192.168.0.205 master-user=slave master-password=123456



  5、啟動(dòng)從庫,進(jìn)行主從庫數(shù)據(jù)同步


/opt/mysql/share/mysql/mysql start /opt/mysql/bin/mysql -u root -p mysql>load data from master;



  說明:這一步也可以用數(shù)據(jù)庫倒入或者直接目錄考過來。

  6、進(jìn)行測試:

  主庫創(chuàng)建表,

mysql>create database sampdb; mysql>create table new (name char(20),phone char(20)); mysql>insert into new (’abc,’0532555555’);



  打開從庫,察看:

/opt/mysql/bin/mysql -u root -p mysql>show database; mysql sampdb test mysql>use sampdb; mysql>show tables; new 說明主從數(shù)據(jù)庫創(chuàng)建成功。



  7、主從數(shù)據(jù)庫相關(guān)命令:


slave stop; slave start ; 開始停止從數(shù)據(jù)庫。 show slave statusG; 顯示從庫正讀取哪一個(gè)主數(shù)據(jù)庫二進(jìn)制日志




  purge master logs to ’binlog.000004’; 此命令非常小心,刪除主數(shù)據(jù)庫沒用的二進(jìn)制日志文件。如果誤刪除,那么從庫就沒有辦法自動(dòng)更新了。

  change master; 從服務(wù)器上修改參數(shù)使用。
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI