{"id":7759,"date":"2018-10-08T12:25:00","date_gmt":"2018-10-08T04:25:00","guid":{"rendered":"http:\/\/rmohan.com\/?p=7759"},"modified":"2018-10-08T12:25:17","modified_gmt":"2018-10-08T04:25:17","slug":"mysql-master-slave","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7759","title":{"rendered":"MySQL master-slave and proxy server"},"content":{"rendered":"<p><strong>MySQL master-slave principle and process<\/strong><\/p>\n<p><strong>principle<\/strong><\/p>\n<p>MySQL Replication is an asynchronous replication process (mysql5.1.7 or later is divided into asynchronous replication and semi-synchronous modes), copied from a Mysql instace (we call it Master) to another Mysql instance (we call it Slave) . Implementation of the Master and Slave The entire replication process is mainly done by three threads, two threads (Sql thread and IO thread) on the Slave side and another thread (IO thread) on the Master side.<\/p>\n<p>To implement MySQL Replication, you must first open the Binary Log (mysql-bin.xxxxxx) function on the Master side, otherwise it will not be implemented. Because the entire copy process is actually the various operations recorded in the log that Slave takes the log from the Master and then executes it in its own complete sequence. Open MySQL&#8217;s Binary Log by adding the &#8220;-log-bin&#8221; parameter option during the startup of MySQL Server, or by adding the &#8220;log-bin&#8221; parameter to the mysqld parameter group in the configuration file (parameter part of the [mysqld] ID) item.<\/p>\n<p><strong>Basic process<\/strong><\/p>\n<p>1.Slave The IO thread above connects to the Master and requests the contents of the log after the specified location of the specified log file (or the log from the beginning);<\/p>\n<p>2. After receiving the request from the IO thread of the slave, the master reads the log information after the specified location of the specified log according to the request information through the IO thread responsible for the copy, and returns it to the IO thread of the slave. In addition to the information contained in the log, the return information includes the name of the Binary Log file on the Master side and the location in the Binary Log.<\/p>\n<p>3. After receiving the information, the IO thread of the Slave writes the received log content to the end of the Relay Log file (mysql-relay-bin.xxxxxx) on the Slave end, and reads the bin-log of the Master. The file name and location are recorded in the master-info file so that the next time you read it, you can clearly tell the Master &#8220;Which location I need to start from a bin-log, please send it to me&#8221;<\/p>\n<p>4.Slave&#8217;s SQL thread detects the newly added content in the Relay Log, and immediately parses the contents of the log file into executable Query statements when the Master side is actually executed, and executes the Query on its own. In this way, the same Query is actually executed on the Master side and the Slave side, so the data at both ends is exactly the same.<\/p>\n<p>Several modes of MySQL replication<\/p>\n<p>Starting with MySQL 5.1.12, you can do this in three modes:<\/p>\n<p>\u2013 based on statement-based replication (SBR),<\/p>\n<p>\u2013 row-based replication (RBR),<\/p>\n<p>\u2013 mixed-based replication (MBR)<\/p>\n<p>Accordingly, there are three formats for binlog: STATEMENT, ROW, MIXED. In the MBR mode, the SBR mode is the default.<\/p>\n<p>Set master-slave replication mode:<br \/>\nlog-bin=mysql-bin<\/p>\n<p>#binlog_format=&#8221;STATEMENT&#8221;<\/p>\n<p>#binlog_format=&#8221;ROW&#8221;<\/p>\n<p>binlog_format=&#8221;MIXED&#8221;<\/p>\n<p>It is also possible to dynamically modify the format of the binlog at runtime. For example<br \/>\nmysql&gt; SET SESSION binlog_format = &#8216;STATEMENT&#8217;;<\/p>\n<p>mysql&gt; SET SESSION binlog_format = &#8216;ROW&#8217;;<\/p>\n<p>mysql&gt; SET SESSION binlog_format = &#8216;MIXED&#8217;;<\/p>\n<p>mysql&gt; SET GLOBAL binlog_format = &#8216;STATEMENT&#8217;;<\/p>\n<p>Mysql master-slave replication configuration<\/p>\n<p>Version: mysql5.7 CentOS 7.2<\/p>\n<p>Scenario description:<br \/>\nPrimary database server: 192.168.1.100, MySQL is installed, and there is no application data.<br \/>\nFrom the database server: 192.168.1.200, MySQL is already installed and there is no application data.<\/p>\n<p>1 Operations on the primary server<\/p>\n<p>Start mysql service<br \/>\nservice mysqld start<\/p>\n<p>Log in to the MySQL server via the command line<br \/>\nmysql -uroot -p&#8217;new-password&#8217;<\/p>\n<p>Authorize copy permissions to the database server 192.168.1.200<br \/>\nmysql&gt; GRANT REPLICATION SLAVE ON *.* to &#8216;rep1&#8217;@&#8217;192.168.1.200&#8217; identified by &#8216;password&#8217;;<\/p>\n<p>Query the status of the primary database<\/p>\n<p>When configuring the slave server,<br \/>\nmysql&gt; show master status;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;- +&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;-+<br \/>\n| File| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;- &#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;-+<br \/>\n| mysql-master-bin.000001 | 154 | | | |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+- &#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;-+<\/p>\n<p>Need to pay attention here, if the query returns<br \/>\nmysql&gt; show slave status;<br \/>\nEmpty set (0.01 sec)<\/p>\n<p>This is because the bin-log is not enabled, you need to modify the \/etc\/my.cnf file<br \/>\nserver-id =1<br \/>\nlog-bin=mysql-master-bin<\/p>\n<p>Also need to pay attention to when modifying the file. After mysql5.7, you need to specify the server-id when you open the binlog. Otherwise, you will get an error.<\/p>\n<p>2 Configuring the slave server<\/p>\n<p>Modify the configuration file from the server \/opt\/mysql\/etc\/my.cnf<\/p>\n<p>Change server-id = 1 to server-id = 2 and make sure the ID is not used by other MySQL services.<\/p>\n<p>Start mysql service<br \/>\nservice mysqld start<\/p>\n<p>Login to manage MySQL server<br \/>\nmysql -uroot -p&#8217;new-password&#8217;<\/p>\n<p>change master to<br \/>\nmaster_host=&#8217;192.168.1.100&#8242;,<br \/>\nmaster_user=&#8217;root&#8217;,<br \/>\nmaster_password=&#8217;mohan..&#8217;,<br \/>\nmaster_log_file=&#8217;mysql-master-bin.000001&#8242;,<br \/>\nmaster_log_pos=154;<\/p>\n<p>Start the slave synchronization process<br \/>\nmysql&gt; start slave after the correct execution ;<\/p>\n<p>Note that there is another pit here.<br \/>\nEven if the start slave is successful, the master-slave copy is still failing.<br \/>\n1. Error message<br \/>\nmysql&gt; show slave staus;<\/p>\n<p>Last_IO_Error: Fatal error: The slave I\/O thread stops because master and slave have Equal MySQL server UUIDs;<br \/>\nThese UUIDs must be different for replication to work.<\/p>\n<p>2. View the master-slave server_id variable<br \/>\nmaster_mysql&gt; show variables like &#8216;server_id&#8217;;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;+- &#8212;&#8212;+<br \/>\n| Variable_name | Value |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+<br \/>\n| server_id | 33|<br \/>\n+&#8212;&#8212;- &#8212;&#8212;&#8211;+&#8212;&#8212;-+<\/p>\n<p>slave_mysql&gt; show variables like &#8216;server_id&#8217;;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;- +<br \/>\n| Variable_name | Value |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+<br \/>\n| server_id | 11|<br \/>\n+&#8212;&#8212;&#8212;&#8212;- &#8211;+&#8212;&#8212;-+<br \/>\n&#8212; From the above situation, the master has used a different server_id<\/p>\n<p>3 from mysql , solve the fault<br \/>\n### view auto.cnf file<br \/>\n[root@dbsrv1 ~] cat \/data\/mysqldata\/auto.cnf ### uuid<br \/>\n[Auto]<br \/>\nServer-uuid = 62ee10aa-b1f7-11e4-90ae-080 027 615 026<\/p>\n<p>[dbsrv2 the root @ ~] More \/data\/mysqldata\/auto.cnf # ### from the uuid, there really is repeated, because the cloned Virtual machine, only change server_id not<br \/>\n[auto]<br \/>\nserver-uuid=62ee10aa-b1f7-11e4-90ae-080027615026<\/p>\n<p>[root@dbsrv2 ~]# mv \/data\/mysqldata\/auto.cnf \/data\/mysqldata\/auto.cnf.bk # ##Rename the file<br \/>\n[root@dbsrv2 ~]# service mysql restart ### Restart mysql<br \/>\nShutting down MySQL.[ OK ]<br \/>\nStarting MySQL.[ OK ]<br \/>\n[root@dbsrv2 ~]# more \/data\/mysqldata\/auto.cnf ###Automatically generate a new auto.cnf file after reboot, ie new UUID<br \/>\n[auto]<br \/>\nserver-uuid=6ac0fdae-b5d7-11e4-a9f3-0800278ce5c9<\/p>\n<p>slave<\/p>\n<p>[root@dbsrv1 ~]# mysql -uroot -pxxx -e &#8220;show slave status\\G&#8221;|grep Running<br \/>\nWarning: Using a password on the command line interface can be insecure.<br \/>\nSlave_IO_Running: Yes<br \/>\nSlave_SQL_Running: Yes<br \/>\nSlave_SQL_Running_State: Slave has read all relay log; waiting for the slave I\/O thread to update it<\/p>\n<p>###uuid<br \/>\nmaster_mysql&gt; show variables like &#8216;server_uuid&#8217;;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| Variable_name | Value|<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| server_uuid | 62ee10aa-b1f7-11e4-90ae-080027615026 |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n1 row in set (0.00 sec)<\/p>\n<p>master_mysql&gt; show slave hosts;<br \/>\n+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| Server_id | Host | Port | Master_id | Slave_UUID |<br \/>\n+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n|33 | | 3306 |11 | 62ee10aa-b1f7-11e4-90ae-080027615030 |<br \/>\n|22 | | 3306 |11 | 6ac0fdae-b5d7-11e4-a9f3-0800278ce5c9 |<br \/>\n+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/p>\n<p>The values ??of Slave_IO_Running and Slave_SQL_Running must be YES to indicate that the status is normal.<\/p>\n<p>If the application data already exists on the primary server, the following processing is required when performing the master-slave replication:<br \/>\n(1) The primary database performs the lock table operation, and the data is not allowed to be written again.<br \/>\nmysql&gt; FLUSH TABLES WITH READ LOCK;<\/p>\n<p>(2) View the status of the main database<br \/>\nmysql&gt; show master status;<\/p>\n<p>(3) Record the values ??of FILE and Position.<br \/>\nCopy the data file of the primary server (the entire \/opt\/mysql\/data directory) to the secondary server. It is recommended to compress it through the tar archive and then transfer it to the secondary server.<\/p>\n<p>(4) cancel the main database lock<br \/>\nmysql&gt; UNLOCK TABLES;<\/p>\n<p>3 Verify master-slave replication<\/p>\n<p>Create the database first_db on the primary server<br \/>\nmysql&gt; create database first_db;<br \/>\nQuery Ok, 1 row affected (0.01 sec)<\/p>\n<p>Create a table first_tb on the primary server<br \/>\nmysql&gt; create table first_tb(id int(3),name char(10));<br \/>\nQuery Ok, 1 row affected (0.00 sec)<\/p>\n<p>Insert the record<br \/>\nmysql&gt; insert into first_tb values ??(001, \u201cmyself\u201d) in the table first_tb on the primary server ;<br \/>\nQuery Ok, 1 row affected (0.00 sec)<\/p>\n<p>Viewing from the server<\/p>\n<p>mysql&gt; show databases;<\/p>\n<p>MySQL read and write separation configuration under CentOS 7.2<br \/>\nMySQL read and write separation configuration<\/p>\n<p>Environment: CentOS 7.2 MySQL 5.7<\/p>\n<p>Scene Description:<br \/>\nDatabase Master Primary Server: 192.168.1.100<br \/>\nDatabase Slave Slave Server: 192.168.1.200<br \/>\nMySQL-Proxy Dispatch Server: 192.168.1.210<\/p>\n<p>The following operations are performed on the 192.168.1.210 MySQL-Proxy scheduling server.<\/p>\n<p>1. Check the software package required by the system<\/p>\n<p>You need to configure the EPEL YUM source<br \/>\nwget before installation https:\/\/mirrors.ustc.edu.cn\/epel\/\/7\/x86_64\/Packages\/e\/epel-release-7-11.noarch.rpm<br \/>\nrpm -ivh epel-release-7 -11.noarch.rpm<br \/>\nyum clean all<br \/>\nyum update<\/p>\n<p>yum install -y gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libmcrypt* libtool* flex* pkgconfig* libevent* glib*<\/p>\n<p>2. Compile and install lua<\/p>\n<p>The read-write separation of MySQL-Proxy is mainly implemented by the rw-splitting.lua script, so you need to install lua.<\/p>\n<p>Lua can<br \/>\ndownload the source package from http:\/\/www.lua.org\/download.html in the following way.<\/p>\n<p>Search for the relevant rpm package from rpm.pbone.net<br \/>\ndownload. Fedora . RedHat .com\/pub\/fedora\/epel\/5\/i386\/lua-5.1.4-4.el5.i386.rpm<br \/>\ndownload.fedora.redhat.com\/ Pub\/fedora\/epel\/5\/x86_64\/lua-5.1.4-4.el5.x86_64.rpm<\/p>\n<p>Here we recommend to use the source package to install<br \/>\ncd \/opt\/install<br \/>\nwget http:\/\/www.lua.org\/ftp\/lua-5.1.4.tar.gz<br \/>\ntar zvfx lua-5.1.4.tar.gz<br \/>\ncd lua-5.1 .4<br \/>\nmake linux<br \/>\nmake install<br \/>\nmkdir \/usr\/lib\/pkgconfig\/<br \/>\ncp \/opt\/install\/lua-5.1.4\/etc\/lua.pc \/usr\/lib\/pkgconfig\/<br \/>\nexport PKG_CONFIG_PATH=$PKG_CONFIG_PATH:\/usr\/lib\/pkgconfig<\/p>\n<p>Attention problem<\/p>\n<p>When compiling, the problem is that there is a lack of dependencies** readline**, then readline depends on ncurses, so you must first install two software<br \/>\nyum install -y readline-devel ncurses-devel<\/p>\n<p>3. Install and configure MySQL-Proxy<\/p>\n<p>Download mysql-proxy<\/p>\n<p>???http:\/\/dev.mysql.com\/downloads\/mysql-proxy\/<br \/>\nwget https:\/\/downloads.mysql.com\/archives\/get\/file\/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit.tar.gz<br \/>\ntar zxvf mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit.tar.gz<br \/>\nmv zxvf mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit \/usr\/local\/mysql-proxy<\/p>\n<p>** Configure mysql-proxy, create the main configuration file **<br \/>\ncd \/usr\/local\/mysql-proxy<br \/>\nmkdir lua #Create script storage directory<br \/>\nmkdir logs #Create log directory<br \/>\ncp share \/ doc \/ mysql-proxy \/ rw-splitting.lua . \/lua #copy read and write separation configuration file<br \/>\nvi \/etc\/mysql-proxy.cnf #Create configuration file<br \/>\n[mysql-proxy]<br \/>\nuser=root<br \/>\n#Run mysql-proxy user admin-username=proxyuser #??mysql user<br \/>\nadmin- Password=123456 #user&#8217;s password<br \/>\nproxy-address=192.168.1.210:4040 #mysql-proxyRun ip and port, no port, default 4040<br \/>\nproxy-read-only-backend-addresses=192.168.1.200 #Specify backend from slave Read the data<br \/>\nproxy-backend-addresses=192.168.1.100 #Specify the backend master master write data<br \/>\nproxy-lua-script=\/usr\/local\/mysql-proxy\/lua\/rw-splitting.lua #Specify the read-write separation configuration file Location<br \/>\nadmin-lua-script=\/usr\/local\/mysql-proxy\/lua\/admin.lua #Specify the management script<br \/>\nlog-file=\/var\/log\/mysql-proxy.log #log location<br \/>\nLog-level=info #definition log log level<br \/>\ndaemon=true#run<br \/>\nkeepalive=true in daemon mode #mysql-proxy crash, try to restart<\/p>\n<p>There is a pit here.<\/p>\n<p>The comments in the configuration file should be completely deleted, otherwise it may cause some characters that cannot be recognized.<br \/>\nThis is not the most pit, the most pit is: even if you delete the comment, remove the extra white space, you may still report the following error:<br \/>\n2018-09-21 06:39:40: (critical) Key file contains key &#8220;daemon &#8221; Which has a value that cannot be interpreted.&#8221;<\/p>\n<p>2018-09-21 06:52:22: (critical) Key file contains key \u201ckeepalive\u201d which has a value that cannot be interpreted.<\/p>\n<p>The reason for the above problem is daemon=true, keepalive=true is not written now, to be changed to:<br \/>\ndaemon=1<br \/>\nkeepalive=1<\/p>\n<p>Execute permissions to the configuration file<\/p>\n<p>chmod 660 \/etc\/mysql-porxy.cnf<br \/>\nConfiguring the admin.lua file<\/p>\n<p>In the \/etc\/mysql-proxy.cnf configuration file, the management file of \/usr\/local\/mysql-proxy\/lua\/admin.lua is still not created yet. So, now you need to edit and create the admin.lua file. For this version of mysql-proxy-0.8.5, I found the following admin.lua script, which is valid for this version:<\/p>\n<p>vim \/usr\/local\/mysql-proxy\/lua\/admin.lua<br \/>\nfunction set_error(errmsg)<br \/>\nproxy.response = {<br \/>\ntype = proxy.MYSQLD_PACKET_ERR,<br \/>\nerrmsg = errmsg or &#8220;error&#8221;<br \/>\n}<br \/>\nend<br \/>\nfunction read_query(packet)<br \/>\nif packet:byte() ~= proxy.COM_QUERY then<br \/>\nset_error(&#8220;[admin] we only handle text-based queries (COM_QUERY)&#8221;)<br \/>\nreturn proxy.PROXY_SEND_RESULT<br \/>\nend<br \/>\nlocal query = packet:sub(2)<br \/>\nlocal rows = { }<br \/>\nlocal fields = { }<br \/>\nif query:lower() == &#8220;select * from backends&#8221; then<br \/>\nfields = {<br \/>\n{ name = &#8220;backend_ndx&#8221;,<br \/>\ntype = proxy.MYSQL_TYPE_LONG },<br \/>\n{ name = &#8220;address&#8221;,<br \/>\ntype = proxy.MYSQL_TYPE_STRING },<br \/>\n{ name = &#8220;state&#8221;,<br \/>\ntype = proxy.MYSQL_TYPE_STRING },<br \/>\n{ name = &#8220;type&#8221;,<br \/>\ntype = proxy.MYSQL_TYPE_STRING },<br \/>\n{ name = &#8220;uuid&#8221;,<br \/>\ntype = proxy.MYSQL_TYPE_STRING },<br \/>\n{ name = &#8220;connected_clients&#8221;,<br \/>\ntype = proxy.MYSQL_TYPE_LONG },<br \/>\n}<br \/>\nfor i = 1, #proxy.global.backends do<br \/>\nlocal states = {<br \/>\n&#8220;unknown&#8221;,<br \/>\n&#8220;up&#8221;,<br \/>\n&#8220;down&#8221;<br \/>\n}<br \/>\nlocal types = {<br \/>\n&#8220;unknown&#8221;,<br \/>\n&#8220;rw&#8221;,<br \/>\n&#8220;ro&#8221;<br \/>\n}<br \/>\nlocal b = proxy.global.backends[i]<br \/>\nrows[#rows + 1] = {<br \/>\ni,<br \/>\nb.dst.name, &#8212; configured backend address<br \/>\nstates[b.state + 1], &#8212; the C-id is pushed down starting at 0<br \/>\ntypes[b.type + 1], &#8212; the C-id is pushed down starting at 0<br \/>\nb.uuid, &#8212; the MySQL Server&#8217;s UUID if it is managed<br \/>\nb.connected_clients &#8212; currently connected clients<br \/>\n}<br \/>\nend<br \/>\nelseif query:lower() == &#8220;select * from help&#8221; then<br \/>\nfields = {<br \/>\n{ name = &#8220;command&#8221;,<br \/>\ntype = proxy.MYSQL_TYPE_STRING },<br \/>\n{ name = &#8220;description&#8221;,<br \/>\ntype = proxy.MYSQL_TYPE_STRING },<br \/>\n}<br \/>\nrows[#rows + 1] = { &#8220;SELECT * FROM help&#8221;, &#8220;shows this help&#8221; }<br \/>\nrows[#rows + 1] = { &#8220;SELECT * FROM backends&#8221;, &#8220;lists the backends and their state&#8221; }<br \/>\nelse<br \/>\nset_error(&#8220;use &#8216;SELECT * FROM help&#8217; to see the supported commands&#8221;)<br \/>\nreturn proxy.PROXY_SEND_RESULT<br \/>\nend<br \/>\nproxy.response = {<br \/>\ntype = proxy.MYSQLD_PACKET_OK,<br \/>\nresultset = {<br \/>\nfields = fields,<br \/>\nrows = rows<br \/>\n}<br \/>\n}<br \/>\nreturn proxy.PROXY_SEND_RESULT<br \/>\nend<\/p>\n<p>** Modify the read-write separation configuration file**<br \/>\nvim \/usr\/local\/mysql-proxy\/lua\/rw-splitting.luaif not proxy.global.config.rwsplit<br \/>\nproxy.global.config.rwsplit = {<br \/>\nmin_idle_connections = 1, #default When there are more than 4 connections, the read\/write separation starts, and 1<br \/>\nmax_idle_connections = 1, #<br \/>\ndefault8 , changed to 1 is_debug = false<br \/>\n}<br \/>\nend<\/p>\n<p>mysql-proxy<br \/>\n\/usr\/local\/mysql-proxy\/bin\/mysql-proxy &#8211;defaults-file=\/etc\/mysql-proxy.cnf<\/p>\n<p>netstat -tupln | grep 4000 #killall -9 has been started mysql-proxy #close mysql-proxy<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL master-slave principle and process<\/p>\n<p>principle<\/p>\n<p>MySQL Replication is an asynchronous replication process (mysql5.1.7 or later is divided into asynchronous replication and semi-synchronous modes), copied from a Mysql instace (we call it Master) to another Mysql instance (we call it Slave) . Implementation of the Master and Slave The entire replication process is mainly done [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7759"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7759"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7759\/revisions"}],"predecessor-version":[{"id":7761,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7759\/revisions\/7761"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}