久综合色-久综合网-玖草影视-玖草资源在线-亚洲黄色片子-亚洲黄色片在线观看

Hello! 歡迎來到小浪云!


在MySQL中設(shè)置主從復(fù)制入門實例


avatar
小浪云 2024-10-28 176

在MySQL中設(shè)置主從復(fù)制入門實例

mysql復(fù)制示例:一個master將向單個slave發(fā)送信息。為了使進程工作,您將需要兩個IP地址:主服務(wù)器之一和從屬設(shè)備之一。

本教程將使用以下IP地址:

 12.34.56.789-主數(shù)據(jù)庫  12.23.34.456-從數(shù)據(jù)庫 
登錄后復(fù)制

本文假設(shè)您具有sudo權(quán)限的用戶并且已安裝mysql。 如果你沒有mysql,你可以用這個命令安裝:

 sudo apt-get install mysql-server mysql-client 
登錄后復(fù)制
第一步 – 配置主數(shù)據(jù)庫

打開主服務(wù)器上的mysql配置文件。

 sudo nano /etc/mysql/my.cnf  一旦進入該文件,我們需要進行一些更改。  第一步是找到如下所示的部分,將服務(wù)器綁定到本地主機:  bind-address            = 127.0.0.1 將標準IP地址替換為服務(wù)器的IP地址。  bind-address            = 12.34.56.789  下一個配置更改是指位于[mysqld]部分中的server-id。 您可以為此點選擇任何數(shù)字(可能更容易從1開始),但該數(shù)字必須是唯一的,并且不能與復(fù)制組中的任何其他服務(wù)器標識匹配。 我要去打電話這個1。  確保此行已取消注釋。  server-id               = 1 移動到log_bin行。 這是保存復(fù)制的真實細節(jié)的地方。 從屬程序?qū)?fù)制在日志中注冊的所有更改。 對于這一步,我們只需要取消注釋引用log_bin的行:  log_bin                 = /var/log/mysql/mysql-bin.log 最后,我們需要指定將在從服務(wù)器上復(fù)制的數(shù)據(jù)庫。 您可以通過為所有您需要的數(shù)據(jù)庫重復(fù)此行,包括多個數(shù)據(jù)庫。  binlog_do_db            = newdatabase 完成所有更改后,繼續(xù)保存并退出配置文件。  刷新MySQL。 
登錄后復(fù)制
 sudo service mysql restart 
登錄后復(fù)制
登錄后復(fù)制

接下來的步驟將在MySQL shell中進行,本身。

打開MySQL shell。

 mysql -u root -p 
登錄后復(fù)制

我們需要給從屬權(quán)限。 您可以使用此行命名您的從屬并設(shè)置其密碼。 命令應(yīng)采用以下格式:

 GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'password'; 
登錄后復(fù)制
 FLUSH PRIVILEGES; 
登錄后復(fù)制

下一部分是有點bit。。 為了完成任務(wù),你需要在除了你已經(jīng)使用了幾步倒行一打開一個新窗口或標簽 。

在當前標簽頁切換到“newdatabase”。

 USE newdatabase; 
登錄后復(fù)制

接下來,鎖定數(shù)據(jù)庫以防止任何新的更改:

 FLUSH TABLES WITH READ LOCK; 
登錄后復(fù)制

然后輸入:

 SHOW MASTER STATUS; 
登錄后復(fù)制

你會看到一個表應(yīng)該看起來像這樣:

 mysql> SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 |      107 | newdatabase  |                  | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec) 
登錄后復(fù)制

這是從數(shù)據(jù)庫將開始復(fù)制的位置。 記錄這些數(shù)字,他們將在以后有用。

如果在同一個窗口中進行任何新的更改,數(shù)據(jù)庫將自動解鎖。 因此,您應(yīng)該打開新的選項卡或窗口,然后繼續(xù)下一步。

繼續(xù)數(shù)據(jù)庫仍然鎖定,在新窗口中使用mysqldump導(dǎo)出數(shù)據(jù)庫(確保您在bash shell中而不是在MySQL中鍵入此命令)。

 mysqldump -u root -p --opt newdatabase > newdatabase.sql 
登錄后復(fù)制

現(xiàn)在,返回到您的原始窗口,解鎖數(shù)據(jù)庫(使它們可寫入)。 通過退出shell完成。

 UNLOCK TABLES; QUIT; 
登錄后復(fù)制

現(xiàn)在你已經(jīng)完成了master數(shù)據(jù)庫的配置。

第二步 – 配置從數(shù)據(jù)庫

配置主數(shù)據(jù)庫之后。 你可以把它放在一邊,我們現(xiàn)在將開始配置從數(shù)據(jù)庫。

登錄到從服務(wù)器,打開MySQL shell并創(chuàng)建要從主服務(wù)器復(fù)制的新數(shù)據(jù)庫(然后退出):

 CREATE DATABASE newdatabase; EXIT; 導(dǎo)入先前從主數(shù)據(jù)庫導(dǎo)出的數(shù)據(jù)庫。  mysql -u root -p newdatabase   Now we need to configure the slave configuration in the same way as we did the master:  sudo nano /etc/mysql/my.cnf  We have to make sure that we have a few things set up in this configuration. The first is the server-id. This number, as mentioned before needs to be unique. Since it is set on the default (still 1), be sure to change it’s something different.  server-id               = 2  Following that, make sure that your have the following three criteria appropriately filled out:  relay-log               = /var/log/mysql/mysql-relay-bin.log log_bin                 = /var/log/mysql/mysql-bin.log binlog_do_db            = newdatabase  You will need to add in the relay-log line: it is not there by default. Once you have made all of the necessary changes, save and exit out of the slave configuration file.  Restart MySQL once again:  sudo service mysql restart  The next step is to enable the replication from within the MySQL shell.  Open up the the MySQL shell once again and type in the following details, replacing the values to match your information:  CHANGE MASTER TO MASTER_HOST='12.34.56.789',MASTER_USER='slave_user', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=  107;  This command accomplishes several things at the same time:  It designates the current server as the slave of our master server.  It provides the server the correct login credentials Last of all, it lets the slave server know where to start replicating from; the master log file and log position come from the numbers we wrote down previously.   With that—you have configured a master and slave server.   Activate the slave server:  START SLAVE;  You be able to see the details of the slave replication by typing in this command. The G rearranges the text to make it more readable.  SHOW SLAVE STATUSG   If there is an issue in connecting, you can try starting slave with a command to skip over it:  SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; SLAVE START;   All done.   See More  MySQL replication has a lot different options, and this was just a brief overview.  If you have any further questions about the specific capabilities of MySQL, feel free to post your questions in our Q&A Forum and we’ll be happy to answer them.   By Etel Sverdlov 
登錄后復(fù)制

現(xiàn)在我們需要以與我們做主機相同的方式配置從機配置:

 sudo nano /etc/mysql/my.cnf  我們必須確保我們在這個配置中設(shè)置了一些東西。 第一個是服務(wù)器標識。 這個數(shù)字,如前所述需要是唯一的。 因為它被設(shè)置為默認(仍然是1),一定要改變它的東西不同。  server-id               = 2 之后,請確保您已正確填寫以下三個條件:  relay-log               = /var/log/mysql/mysql-relay-bin.log log_bin                 = /var/log/mysql/mysql-bin.log binlog_do_db            = newdatabase 
登錄后復(fù)制

您將需要在中繼日志行中添加:默認情況下不存在。 一旦完成所有必要的更改,保存并退出從配置文件。

再次重新啟動MySQL:

 sudo service mysql restart 
登錄后復(fù)制
登錄后復(fù)制

下一步是在MySQL shell中啟用復(fù)制。

再次打開MySQL shell,輸入以下詳細信息,替換值以匹配您的信息:

 CHANGE MASTER TO MASTER_HOST='12.34.56.789',MASTER_USER='slave_user', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=  107; 
登錄后復(fù)制

命令同時完成幾個事情:

它將當前服務(wù)器指定為我們的主服務(wù)器的從屬。

它為服務(wù)器提供正確的登錄憑據(jù)

最后,它讓從服務(wù)器知道從哪里開始復(fù)制; 主日志文件和日志位置來自我們之前寫下的數(shù)字。

這樣,您已經(jīng)配置了主服務(wù)器和從服務(wù)器

激活從服務(wù)器:

 START SLAVE; 
登錄后復(fù)制

通過鍵入此命令,您可以看到從復(fù)制的詳細信息。 G重新排列文本,使其更易讀。

 SHOW SLAVE STATUSG 
登錄后復(fù)制

如果在連接中存在問題,可以嘗試使用命令啟動從器件以跳過它:

 SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; SLAVE START;  
登錄后復(fù)制

全做完了。

相關(guān)閱讀

主站蜘蛛池模板: 日韩国产精品欧美一区二区 | 中文字幕乱码中文乱码51精品 | 久久久久久久91精品免费观看 | 精品动漫一区二区 | 欧美日本色 | 永久毛片| 日本精品一在线观看视频 | 国外免费一级 | 日本三级香港三级人妇 m | 日本久久99 | 精品国产成人在线 | 欧美久久久久久久一区二区三区 | 久久国产视频网站 | 国产毛片久久久久久国产毛片 | 欧美在线视频免费观看 | 国产欧美日本在线 | 特黄特色一级特色大片中文 | 热久久伊人 | 一本色道久久爱 | 国产成人精品免费视频大全软件 | 国产精品久久久久久久久久久久 | 黄色三级视频在线 | 亚洲精品一区二区在线观看 | 久草首页在线 | 国产一区二区三区四区五区tv | 国产一级爱 | 在线观看一级片 | 久久草在线精品 | 欧美日韩生活片 | 亚洲伊人久久综合影院2021 | 欧美视频在线看 | 国产成人精品日本亚洲专区6 | 日韩精品亚洲一级在线观看 | 色视频在线免费 | 91精品91| 久久精品国产99久久6动漫欧 | 波多野结衣一区在线观看 | 欧美成人性色生活片免费在线观看 | 交性视频免费看 | 国产永久免费视频m3u8 | 在线91精品国产免费 |