--This article will introduce how to configure Mysql master-slave synchronization and read-write separation, and use the middleware ProxySQL to achieve more efficient database access.
Server Information#
Mysql
Master Server (A): 192.168.1.1
Backup Server (B): 192.168.1.2
Backup Server (C): 192.168.1.3
Middleware
Middleware Server (D): 192.168.1.4
Mysql Master-Slave Synchronization and Read-Write Separation Configuration#
Master Database Configuration#
Execute the following commands on the master server (A):
`# Create slave access account
grant replication slave on . to 'slave'@'%' identified by '123456';
Check the master server status
mysql> show master status;
+------------------+-----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+-----------+--------------+------------------+-------------------+
| mysql-bin.000006 | 438 | | | |
+------------------+-----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
`
Slave Server Configuration#
Execute the following commands on the slave server:
Stop the slave server#
Configure the master server information#
Start the slave server
Check the slave server status
If the slave server status displays the following content, it means the startup was successful:
ProxySQL Configuration#
Installation
Go to [https://github.com/sysown/proxysql/releases] to download the ProxySQL installation package.
Upload the installation package to the server and execute the following command to install:
Verify the Installation Status#
Execute the following command to verify the ProxySQL installation status:
Start the Service#
Execute the following command to start the ProxySQL service:
Enter the ProxySQL Local Server#
Execute the following command to enter the ProxySQL local server:
Add Master and Slave Servers#
Execute the following command in the ProxySQL local server to add master and slave servers:
Add Master and Slave Accounts (ProxySQL)#
Execute the following command in the ProxySQL local server to add master and slave accounts:
Add Rule Routes#
Execute the following command in the ProxySQL local server to add rule routes:
Check Connection Status and Hit Rate#
Execute the following command in the ProxySQL local server to check the connection status and hit rate:
With the above configuration and commands, you can achieve Mysql master-slave synchronization and read-write separation, and use the ProxySQL middleware to optimize database access. Other users can learn and understand how to configure and use these features from this article.