mysql运营_为线上运营Mysql数据库设置从库
一、為mysql運營主庫添加一個repl 賬號
[root@zabbix_server ~]# mysql -uroot -p -S /var/lib/mysql/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 15778982Server version:5.7.25MySQL Community Server (GPL)
Copyright (c)2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type'help;' or '\h' for help. Type '\c' to clearthe current input statement.
mysql>
mysql> grant replication slave,replication client on *.* to 'repl'@'%' identified by 'xxxxxxxxxx';
二、修改主庫my.cnf
增加以下字段
server_id=IP+PORT ? 標識服務器ID
log-bin=master-221 設置log_bin日志文件名
binlog_format=row 指定日志格式為row
server_id=693306log-bin=master-18-69binlog_format=row
三、重啟主庫mysql
停止mysql實例
[root@server-1 ~]# mysqladmin -uroot -p -S /home/mysql-5.7.26/mysql.sock shutdown
重啟mysql實例
[root@server-1 ~]# mysqld_safe --defaults-file=/etc/mysql/my.cnf &
進入mysql
[root@server-1 ~]# mysql -uroot -p -S /home/mysql-5.7.26/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 4Server version:5.7.26-log Source distribution
Copyright (c)2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type'help;' or '\h' for help. Type '\c' to clearthe current input statement.
mysql>
查看server_id變量
mysql> show variables like '%servier_id%';
Empty set (0.01sec)
mysql> show variables like '%server_id%';+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| server_id | 693306 |
| server_id_bits | 32 |
+----------------+--------+
2 rows in set (0.01sec)
mysql>
已經看到server_id變量已經成功設置。
四、修改從庫my.cnf
添加server_id=IP+PORT
server_id=713306
五、重啟mysql
[root@localhost mysql]# systemctl restart mysqld
[root@localhost mysql]#
進入mysql,查看server_id變量
[root@localhost data]# mysql -uroot -p -S /home/mysql-5.7.26/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 2Server version:5.7.26MySQL Community Server (GPL)
Copyright (c)2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type'help;' or '\h' for help. Type '\c' to clearthe current input statement.
mysql> show variables like '%server_id%';+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| server_id | 713306 |
| server_id_bits | 32 |
+----------------+--------+
2 rows in set (0.01sec)
mysql>
已經變成我們設置值了,
六、接下來執行從庫命令
mysql>change master to-> master_host='172.28.18.69',-> master_port=3306,-> master_user='repl',-> master_password='Zaq1xsw@',-> master_log_file='master-18-69.000001',-> master_log_pos=419;
Query OK,0 rows affected, 2 warnings (0.10sec)
mysql>
這里的?master_log_file和master_log_pos值,我們可以在主庫上運行如下命令得到
mysql>show master status\G;*************************** 1. row ***************************File: master-18-69.000001Position:419Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: d24d8a53-880d-11e9-b1f3-842b2b5cdc15:1-7,
ee3e292b-866b-11e9-9df8-14feb5dc2c77:1-23
1 row in set (0.00sec)
ERROR:
No query specified
mysql>
執行成功后,我們啟動從庫操作
mysql>start slave;
Query OK,0 rows affected (0.00sec)
mysql>
查詢從庫狀態
mysql>show slave status\G;*************************** 1. row ***************************Slave_IO_State: Waitingformaster to send event
Master_Host:172.28.18.69Master_User: repl
Master_Port:3306Connect_Retry:60Master_Log_File: master-18-69.000001Read_Master_Log_Pos:1593Relay_Log_File: localhost-relay-bin.000002Relay_Log_Pos:1497Relay_Master_Log_File: master-18-69.000001Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:0Last_Error:
Skip_Counter:0Exec_Master_Log_Pos:1593Relay_Log_Space:1708Until_Condition: None
Until_Log_File:
Until_Log_Pos:0Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:0Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:0Last_IO_Error:
Last_SQL_Errno:0Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:693306Master_UUID: ee3e292b-866b-11e9-9df8-14feb5dc2c77
Master_Info_File:/home/mysql-5.7.26/data/master.infoSQL_Delay:0SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waitingfor moreupdates
Master_Retry_Count:86400Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: d24d8a53-880d-11e9-b1f3-842b2b5cdc15:1-79,
ee3e292b-866b-11e9-9df8-14feb5dc2c77:1-15Auto_Position:0Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:1 row in set (0.00sec)
ERROR:
No query specified
mysql>
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
從庫啟動成功,同步成功
Exec_Master_Log_Pos: 1593
目前同步到主庫數據庫文件位置:1593
在主庫上進入mysql,并查看主庫狀態
mysql>show master status\G;*************************** 1. row ***************************File: master-18-69.000001Position:1593Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: d24d8a53-880d-11e9-b1f3-842b2b5cdc15:1-7,
ee3e292b-866b-11e9-9df8-14feb5dc2c77:1-23
1 row in set (0.00sec)
ERROR:
No query specified
mysql>
同樣主庫文件最后位置也是1593,說明從庫同步設置完畢
總結
以上是生活随笔為你收集整理的mysql运营_为线上运营Mysql数据库设置从库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python websocket爬虫_p
- 下一篇: vue点击按钮怎么跳转图片_vue-ro