mysql master slave 主從同步
mysql master slave 主從同步
下面cli中
$
為普通許可權,#
為root許可權。
模式1
Master:SerA IP:10.0.2.81
Slave:SerB IP:10.0.2.82
A: my.cnf
server-id=1
#master
log-bin=mysql-bin
binlog-do-db=dbname # 需要備份的資料庫名, 多個則重複設定
A: mysql cmd
mysql> GRANT all privileges ON *.* TO 'backup'@'10.0.2.82' IDENTIFIED BY '123456'
mysql> flush privileges;
匯出 dbname 資料庫
$ mysqldump -uroot -p dbname > dbname.sql
重啟mysql伺服器
# service mysql restart
A: mysql cmd
mysql> show grants; -- 檢視許可權生效 --
mysql> show master status\G; -- 錄下 FILE & Position 的值 --
記下 file & Position 的值,在配置 slave時會用到
許可權(需要時執行)
mysql> show grants; -- 檢視許可權 --
mysql> GRANT FILE,SELECT,REPLICATION SLAVE ON *.* TO 'backup'@'10.0.2.82' IDENTIFIED BY '123456';
mysql> flush privileges;
B: my.cnf
server-id=2
#master
log-bin=mysql-bin
#slave
replicate-do-db=dbname # 需要備份的資料庫名, 多個則重複設定
master-connect-retry=60 # 伺服器拓機重連 預設60s
slave-net-timeout=60 # 60s同步
B: mysql cmd
-- 新增 master 伺服器 --
mysql> stop slave;
mysql> change master to
master_host='10.0.2.81',
master_port=3306,
master_user='backup',
master_password='123456'
master_log_file='mysql-bin.000002',
master_log_pos=98;
-- 其中 file & pos 到 A 的 master中找 --
mysql> start slave;
mysql> show slave status\G;
-- Slave_IO_Running和Slave_SQL_Running的狀態都必須是YES --
mysql> show master stauts\G;
-- 匯入資料 --
mysql> stop slave;
mysql> create database `dbname`;
mysql> use dbname;
mysql> source /pwd/dbname.sql;
mysql> start slave;
如果需要則重啟mysql伺服器
# service mysql restart
模式2
A: my.cnf
default-character-set=utf8
server-id = 1
# master
log-bin=mysql-bin
binlog-do-db=dbname # 需要備份的資料庫名, 多個則重複設定
binlog-ignore-db=dbname # 不需要備份的資料庫
B: my.cnf
server-id =2 # 不可重複
# master
log-bin=mysql-bin
relay-log=relay-bin
relay-log-index=relay-bin-index
# slave
master-host ='ip'
master-user =root
master-password =passwd
master-port =3306
master-connect-retry=30 # s
slave-net-timeout=60 # 60s同步
replicate-do-db=dbname # 需要備份的資料庫名, 多個則重複設定
其餘參考模式1
password 重置
$ mysqladmin -uroot -p oldpassword newpasswd
$ mysql -uroot -p user
mysql> UPDATE user SET password=PASSWORD(”new password”) WHERE user=’root’;
區域網訪問 許可權
mysql> grant all privileges on *.* to root@"ip" identified by 'password' with grant option;
sql> flush privileges;
相關文章
- mysql 同步 master-slave薦MySqlAST
- MySQL Master/Slave Master/MasterMySqlAST
- Mysqldump實現mysql的master-slave主從複製MySqlAST
- MySQL 5.5.x 配置Master-Slave主從複製MySqlAST
- 故障案例:主從同步報錯Fatal error: The slave I/O thread stops because master and slave have equal MySQL server主從同步ErrorthreadASTMySqlServer
- Innobackupex實現mysql線上搭建master-slave主從複製MySqlAST
- MySQL master/slaveMySqlAST
- CentOS中MySQL5.6 資料庫主從(Master/Slave)同步安裝與配置詳解CentOSMySql資料庫AST
- MYSQL的master/slave資料同步配置(轉)MySqlAST
- MySQ 資料庫主從同步安裝與配置詳解(Master/Slave)資料庫主從同步AST
- Mysql 5.6 Master和Slave 主備切換MySqlAST
- MySql的Master/SlaveMySqlAST
- mysql主從同步(4)-Slave延遲狀態監控MySql主從同步
- MYSQL5的master slave資料同步配置(轉)MySqlAST
- MySQL主從同步報Client requested master to start replication from positionMySql主從同步clientAST
- mysql master和slave配置MySqlAST
- mysql slave 轉為 masterMySqlAST
- MySQL 5.5 Master/Slave 配置MySqlAST
- Mysql Slave群切換MasterMySqlAST
- Mysql Slave群切換Master (=)MySqlAST
- mysql主從同步MySql主從同步
- 【MongoDB】主從複製(Master-Slave Replication)簡單實現MongoDBAST
- MySQL主從同步配置MySql主從同步
- MySQL master and slave have equal MySQL server UUIDsMySqlASTServerUI
- MySQL錯誤之mysql.slave_master_infoMySqlAST
- mysql建立master/slave詳細步驟MySqlAST
- 利用mysql slave 修復master MyISAM tableMySqlAST
- mysql5.6,master/slave架構,master,不寫bingo原因,無法開啟同步複製MySqlAST架構Go
- 5.6.25 MySql主從 Tmaster and slave have equal MySQL srver UUIDs;MySqlASTUI
- MySQL 資料主從同步MySql主從同步
- MySql主從同步介紹MySql主從同步
- Mysql 主從同步實戰MySql主從同步
- mysql主從同步機制MySql主從同步
- Redis master and slaveRedisAST
- mysql主從同步(5)-同步延遲狀態考量(seconds_behind_master和pt-heartbea)MySql主從同步AST
- zabbix應用-監控mysql slave 主從狀態MySql
- MYSQL資料庫主從同步(一主一從)MySql資料庫主從同步
- 主從同步設定的重要引數log_slave_updates主從同步