%3CLINGO-SUB%20id%3D%22lingo-sub-1490357%22%20slang%3D%22en-US%22%3ESet%20up%20ProxySQL%20clustering%20to%20connect%20efficiently%20to%20Azure%20Database%20for%20MySQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1490357%22%20slang%3D%22en-US%22%3E%3CH1%20id%3D%22toc-hId-474690104%22%20id%3D%22toc-hId-474690104%22%3E%3CSPAN%3EIntroduction%3C%2FSPAN%3E%3C%2FH1%3E%0A%3CP%3ECustomers%20who%20have%20read%20our%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-mysql%2Fconnecting-efficiently-to-azure-database-for-mysql-with-proxysql%2Fba-p%2F1279842%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Eprevious%20blogs%3C%2FA%3E%20frequently%20raise%20an%20important%20question%3A%20How%20should%20we%20configure%20ProxySQL%20in%20a%20highly%20available%20setup%20to%20get%20maximum%20performance%20and%20scale%20from%20our%20Azure%20Database%20for%20MySQL%20service.%20In%20this%20post%2C%20I%20hope%20to%20provide%20detail%20that%20will%20help%20to%20address%20the%20question.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImportant%3C%2FSTRONG%3E%3A%20This%20post%20is%20a%20part%20of%20a%20multi-post%20blog%20series%20related%20to%20configuring%20ProxySQL%20with%20Azure%20Database%20for%20MySQL.%20We%20highly%20recommend%20that%20you%20read%20the%20previous%20posts%20in%20this%20series%20(shown%20below)%20to%20have%20more%20context%20about%20use%20cases%20for%20ProxySQL%20with%20Azure%20Database%20for%20MySQL%20servers.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-mysql%2Fload-balance-read-replicas-using-proxysql-in-azure-database-for%2Fba-p%2F880042%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3ELoad%20balance%20read%20replicas%20using%20ProxySQL%20in%20Azure%20Database%20for%20MySQL%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-mysql%2Fconnecting-efficiently-to-azure-database-for-mysql-with-proxysql%2Fba-p%2F1279842%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EConnecting%20efficiently%20to%20Azure%20Database%20for%20MySQL%20with%20ProxySQL%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-mysql%2Fdeploy-proxysql-as-a-service-on-kubernetes-using-azure-database%2Fba-p%2F1105959%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EDeploy%20ProxySQL%20as%20a%20service%20on%20Kubernetes%20using%20Azure%20Database%20for%20MySQL%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EMost%20of%20the%20time%2C%20you%20configure%20ProxySQL%20on%20a%20separate%20server%2C%20and%20all%20the%20connections%20are%20routed%20from%20the%20application%20to%20the%20ProxySQL%20server.%20ProxySQL%20in%20turn%20directs%20all%20the%20connections%20to%20database%20server%20depending%20on%20the%20query%20rules%20configured%20(illustrated%20in%20figure%201).%20There%20are%20some%20concerns%20with%20using%20this%20approach%2C%20as%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EProxySQL%20becomes%20a%20single%20point%20of%20failure%20for%20the%20application%2C%20potentially%20impacting%20the%20application%E2%80%99s%20availability.%3C%2FLI%3E%0A%3CLI%3EThe%20ProxySQL%20server%20can%20become%20a%20resource%20bottleneck%2C%20limiting%20performance%20and%20scale.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EOne%20way%20to%20address%20these%20concerns%20is%20to%20configure%20ProxySQL%20on%20the%20application%20side%20(illustrated%20in%20figure%26nbsp%3B2).%20By%20collocating%20ProxySQL%20with%20the%20application%20VMs%2C%20you%20also%20reduce%20cost.%20One%20of%20the%20downsides%20of%20this%20solution%20is%20the%20need%20to%20manually%20synchronize%20the%20ProxySQL%20configuration%20across%20application%20VMs%20or%20pods.%20While%20this%20works%20for%20many%20customers%2C%20if%20ProxySQL%20configuration%20changes%20are%20less%20frequent%20(as%20is%20the%20case%20in%20most%20scenarios)%2C%20it%20can%20become%20a%20challenge%20in%20a%20complex%20setup.%20You%20can%20mitigate%20this%20problem%20and%20also%20build%20a%20highly%20available%20and%20scalable%20architecture%20with%20ProxySQL%20by%20using%20%3CA%20href%3D%22https%3A%2F%2Fproxysql.com%2Fblog%2Fproxysql-cluster%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EProxySQL%20native%20clustering%3C%2FA%3E%20(as%20illustrated%20in%20figure%203).%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImportant%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EThis%20feature%20is%20experimental%20in%20ProxySQL%20and%20subject%20to%20change.%20We%20strongly%20recommend%20to%20think%20carefully%20before%20using%20it%20in%20production.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorambhatna_2%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22ambhatna_0-1593120927866.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F201211iE0D0CD6BA9C420D8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22ambhatna_0-1593120927866.png%22%20alt%3D%22ambhatna_0-1593120927866.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThis%20blog%20post%20shows%20how%20to%20configure%20native%20ProxySQL%20clustering%20as%20shown%20in%20Figure%203.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENote%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EProxySQL%20is%20an%20open%20source%20community%20tool.%20It%20is%20supported%20by%20Microsoft%20on%20a%20best%20effort%20basis.%20In%20order%20to%20get%20production%20support%20with%20authoritative%20guidance%2C%20you%20can%20evaluate%20and%20reach%20out%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-ProxySQL%20Product%20support.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId--1332764359%22%20id%3D%22toc-hId--1332764359%22%3E%26nbsp%3B%3C%2FH1%3E%0A%3CH1%20id%3D%22toc-hId-1154748474%22%20id%3D%22toc-hId-1154748474%22%3E%3CSPAN%3EPrerequisites%3C%2FSPAN%3E%3C%2FH1%3E%0A%3CP%3EFor%20the%20example%20in%20this%20post%2C%20we%E2%80%99ll%20be%20setting%20up%20a%20cluster%20with%20three%20nodes%20and%20configuring%20the%20ProxySQL%20server%20to%20split%20the%20read%20and%20write%20workloads%20to%20designated%20Azure%20Database%20for%20MySQL%20servers.%20Prerequisites%20for%20this%20effort%20are%20outlined%20in%20the%20post%20-ERR%3AREF-NOT-FOUND-Load%20balance%20read%20replicas%20using%20ProxySQL%20in%20Azure%20Database%20for%20MySQL%2C%20the%20difference%20being%20that%20we%E2%80%99ll%20use%20three%20Linux%20VMs%20running%20Ubuntu%20as%20three%20nodes%20for%20ProxySQL%20cluster.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1845309948%22%20id%3D%22toc-hId-1845309948%22%3EConfiguring%20ProxySQL%20native%20clustering%3C%2FH2%3E%0A%3CP%3E%3CSTRONG%3EPerform%20below%20steps%20on%20all%20three%20Linux%20VMs.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ETo%20install%20ProxySQL%2C%20in%20the%20post%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-mysql%2Fload-balance-read-replicas-using-proxysql-in-azure-database-for%2Fba-p%2F880042%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3ELoad%20balance%20read%20replicas%20using%20ProxySQL%20in%20Azure%20Database%20for%20MySQL%3C%2FA%3E%2C%20refer%20to%20the%20detail%20in%20the%20section%20%E2%80%9CInstalling%20ProxySQL%20on%20Ubuntu%20VM%E2%80%9D.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EAfter%20installing%20ProxySQL%2C%20update%20the%20proxysql%20config%20file%20located%20at%20%2Fetc%2Fproxysql.cnf%20with%20the%20cluster%20details%2C%20and%20add%20the%20information%20about%20the%20servers%20hosting%20ProxySQL%3A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%20class%3D%22lia-indent-padding-left-60px%22%3Eadmin_variables%3D%3CBR%20%2F%3E%7B%3CBR%20%2F%3Eadmin_credentials%3D%22admin%3Aadmin%3Bcluster1%3Asecret1pass%22%3CBR%20%2F%3E%23%20mysql_ifaces%3D%22127.0.0.1%3A6032%3B%2Ftmp%2Fproxysql_admin.sock%22%3CBR%20%2F%3Emysql_ifaces%3D%220.0.0.0%3A6032%22%3CBR%20%2F%3E%23%20refresh_interval%3D2000%3CBR%20%2F%3E%23%20debug%3Dtrue%3CBR%20%2F%3E%3CSTRONG%3Ecluster_username%3D%22cluster1%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecluster_password%3D%22secret1pass%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecluster_check_interval_ms%3D200%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecluster_check_status_frequency%3D100%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecluster_mysql_query_rules_save_to_disk%3Dtrue%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecluster_mysql_servers_save_to_disk%3Dtrue%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecluster_mysql_users_save_to_disk%3Dtrue%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecluster_proxysql_servers_save_to_disk%3Dtrue%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecluster_mysql_query_rules_diffs_before_sync%3D3%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecluster_mysql_servers_diffs_before_sync%3D3%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecluster_mysql_users_diffs_before_sync%3D3%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecluster_proxysql_servers_diffs_before_sync%3D3%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%7D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-60px%22%3E%3CSTRONG%3Eproxysql_servers%20%3D%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E(%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%7B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ehostname%3D%22VM_1_Public_IP%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Eport%3D6032%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecomment%3D%22proxysql100%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%7D%2C%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%7B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ehostname%3D%22%20VM_2_Public_IP%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Eport%3D6032%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecomment%3D%22proxysql200%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%7D%2C%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%7B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ehostname%3D%22%20VM_3_Public_IP%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Eport%3D6032%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ecomment%3D%22proxysql300%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%7D%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImportant%3C%2FSTRONG%3E%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIn%20the%20proxysql.cnf%20file%2C%20only%20add%20the%20%3CSTRONG%3Ebolded%3C%2FSTRONG%3E%20configuration%20information%20above.%20Also%2C%20ensure%20that%20the%20VMs%20can%20communicate%20with%20each%20other%20using%20inbound%20and%20outbound%20rules.%3C%2FLI%3E%0A%3CLI%3EMake%20sure%20that%20-ERR%3AREF-NOT-FOUND-Azure%20VM%20are%20part%20of%20availability%20set%20to%20protect%20from%20datacenter%20level%20failure%20and%20update.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E2.%20Execute%20the%20below%20step%20to%20re-initialize%20ProxySQL%20from%20the%20config%20file%20(after%20first%20startup%20the%20DB%20file%20is%20used%20instead%20of%20the%20proxysql.cnf%20config%20file)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EService%20proxysql%20initial%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENote%3C%2FSTRONG%3E%3A%3C%2FP%3E%0A%3CP%3EIn%20the%20previous%20section%2C%20we%20configured%20ProxySQL%20native%20clustering.%20This%20ensures%20that%20changes%20to%20one%20ProxySQL%20node%20will%20be%20propagated%20to%20all%20nodes%20in%20the%20cluster.%20From%20now%20onwards%2C%20please%20perform%20the%20ProxySQL%20specific%20changes%20to%20only%20one%20of%20the%20nodes%20in%20the%20ProxySQL%20cluster.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-37855485%22%20id%3D%22toc-hId-37855485%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--1769598978%22%20id%3D%22toc-hId--1769598978%22%3E%3CSPAN%3ESetting%20up%20the%20ProxySQL%3C%2FSPAN%3E%3C%2FH2%3E%0A%3COL%3E%0A%3CLI%3E%3CSPAN%3E%3CSPAN%3EConnect%20to%20the%20ProxySQL%20administration%20interface%20with%20the%20default%20password%20%E2%80%98admin%E2%80%99.%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Emysql%20%E2%80%93u%20admin%20%E2%80%93p%20admin%20-h127.0.0.1%20-P6032%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CSPAN%3EAdd%20the%20reader%20and%20writer%20nodes%20ProxySQL%20server%20pool.%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Einsert%20into%20mysql_servers(hostgroup_id%2Chostname%2Cport%2Cweight%2Ccomment)%20values(1%2C'mydemomasterserver.mysql.database.azure.com'%2C3306%2C1%2C'Write%20Group')%3B%0A%20%0Ainsert%20into%20mysql_servers(hostgroup_id%2Chostname%2Cport%2Cweight%2Ccomment)%20values(2%2C'mydemoreplicaserver.mysql.database.azure.com'%2C3306%2C1%2C'Read%20Group')%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CSPAN%3EEnable%20SSL%20support%20in%20ProxySQL%20server%20pool%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EUPDATE%20mysql_servers%20SET%20use_ssl%3D1%20WHERE%20hostgroup_id%3D1%3B%0AUPDATE%20mysql_servers%20SET%20use_ssl%3D1%20WHERE%20hostgroup_id%3D2%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22toc-hId-717913855%22%20id%3D%22toc-hId-717913855%22%3E%3CSPAN%3ECreating%20the%20MySQL%20users%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EIn%20ProxySQL%2C%20the%20user%20connects%20to%20ProxySQL%20and%20in%20turn%20ProxySQL%20passes%20the%20connection%20to%20the%20MySQL%20node.%20To%20allow%20ProxySQL%20to%20access%20to%20the%20MySQL%20database%2C%20we%20need%20to%20create%20a%20user%20on%20MySQL%20database%20with%20the%20same%20credentials%20as%20on%20the%20ProxySQL%20server.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSPAN%3E%3CSPAN%3ECreate%20a%20new%20user%20%E2%80%98mydemouser%E2%80%99%20with%20the%20password%20%E2%80%98secretpassword%E2%80%99%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3ECREATE%20USER%20'mydemouser'%40'%25'%20IDENTIFIED%20BY%20'%20secretpassword'%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CSPAN%3EGrant%20%E2%80%98mydemouser%E2%80%99%20privileges%20to%20fully%20access%20the%20MySQL%20server%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EGRANT%20ALL%20PRIVILEGES%20ON%20*.*%20TO%20'%20mydemouser'%40'%25'%20WITH%20GRANT%20OPTION%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CSPAN%3EApply%20the%20changes%20to%20the%20permissions%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EFLUSH%20PRIVILEGES%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22toc-hId--1089540608%22%20id%3D%22toc-hId--1089540608%22%3E%3CSPAN%3ECreating%20the%20ProxySQL%20user%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3E%3CSTRONG%3ENote%3C%2FSTRONG%3E%3A%20Perform%20the%20action%20below%20on%20%3CSTRONG%3Eonly%20one%3C%2FSTRONG%3E%20of%20the%20nodes%20in%20the%20ProxySQL%20cluster.%3C%2FP%3E%0A%3CP%3EAllow%20the%20%E2%80%98mydemouser%E2%80%99%20user%20to%20connect%20to%20ProxySQL%20server.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Einsert%20into%20mysql_users(username%2Cpassword%2Cdefault_hostgroup%2Ctransaction_persistent)values('mydemouser'%2C'%20secretpassword'%2C1%2C1)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1397972225%22%20id%3D%22toc-hId-1397972225%22%3E%3CSPAN%3EConfigure%20Monitoring%20on%20ProxySQL%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EConfigure%20ProxySQL%20to%20monitor%20the%20nodes%2C%20and%20then%20create%20the%20monitoring%20user%20on%20the%20Master%20server.%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSPAN%3ECreate%20a%20new%20user%20%E2%80%98monitoruser%E2%80%99%20with%20the%20password%20%E2%80%98secretpassword%E2%80%99%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3ECREATE%20USER%20'%20monitoruser'%40'%25'%20IDENTIFIED%20BY%20'secretpassword'%3B%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CSPAN%3EGrant%20%E2%80%98monitoruser%E2%80%99%20privileges%20to%20fully%20access%20the%20MySQL%20server%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EGRANT%20SELECT%20ON%20*.*%20TO%20'%20monitoruser'%40'%25'%20WITH%20GRANT%20OPTION%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CSPAN%3EApply%20the%20changes%20to%20the%20permissions%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EFLUSH%20PRIVILEGES%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EOn%20the%20server%20running%20ProxySQL%2C%20configure%20mysql-monitor%20to%20the%20username%20of%20the%20new%20account.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Eset%20mysql-monitor_username%3D'monitoruser'%3B%0Aset%20mysql-monitor_password%3D'%20secretpassword'%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--409482238%22%20id%3D%22toc-hId--409482238%22%3E%3CSPAN%3EConfigure%20the%20routing%20rules%20for%20read%20and%20write%20split%3C%2FSPAN%3E%3C%2FH2%3E%0A%3COL%3E%0A%3CLI%3E%3CSPAN%3E%3CSPAN%3EOn%20the%20ProxySQL%20Server%2C%20configure%20the%20write%20traffic%20to%20route%20to%20the%20master%20server%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Einsert%20into%20mysql_query_rules(rule_id%2Cactive%2Cmatch_digest%2Cdestination_hostgroup%2Capply)values(1%2C1%2C'%5ESELECT.*FOR%20UPDATE%24'%2C1%2C1)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CSPAN%3EOn%20the%20ProxySQL%20Server%2C%20configure%20the%20read%20traffic%20to%20route%20to%20the%20read%20replica%20server%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Einsert%20into%20mysql_query_rules(rule_id%2Cactive%2Cmatch_digest%2Cdestination_hostgroup%2Capply)values(2%2C1%2C'%5ESELECT'%2C2%2C1)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22toc-hId--543166962%22%20id%3D%22toc-hId--543166962%22%3E%3CSPAN%3ESave%20the%20changes%20made%20to%20the%20ProxySQL%20configuration%20to%20persists%20across%20restarts%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EIn%20ProxySQL%20configuration%20system%2C%20the%20changes%20we%20made%20are%20in%20memory%20and%20to%20make%20them%20persist%20across%20the%20restarts%2C%20you%20must%20copy%20settings%20to%20runtime%20and%20save%20them%20to%20disk.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSPAN%3EOn%20the%20server%20running%20ProxySQL%2C%20execute%20the%20below%20commands%20to%20save%20the%20settings%20to%20runtime%3A%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Eload%20mysql%20users%20to%20runtime%3B%0Aload%20mysql%20servers%20to%20runtime%3B%0Aload%20mysql%20query%20rules%20to%20runtime%3B%0Aload%20mysql%20variables%20to%20runtime%3B%0Aload%20admin%20variables%20to%20runtime%3B%0A%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CSPAN%3EOn%20the%20server%20running%20ProxySQL%2C%20execute%20the%20following%20commands%20to%20save%20the%20settings%20to%20disk%3A%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Esave%20mysql%20users%20to%20disk%3B%0Asave%20mysql%20servers%20to%20disk%3B%0Asave%20mysql%20query%20rules%20to%20disk%3B%0Asave%20mysql%20variables%20to%20disk%3B%0Asave%20admin%20variables%20to%20disk%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EAfter%20successfully%20completing%20the%20above%20steps%2C%20ProxySQL%20is%20configured%20with%20native%20clustering%20and%20is%20ready%20to%20split%20the%20read%20and%20write%20workload.%20Use%20the%20following%20steps%20to%20test%20if%20the%20read%20and%20write%20splits%20are%20being%20forwarded%20properly%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSPAN%3ELog%20in%20to%20one%20of%20the%20servers%20running%20ProxySQL%20with%20the%20ProxySQL%20user%20you%20created%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Emysql%20%E2%80%93u%20mydemouser%20%E2%80%93p%20secretpassword%20-h127.0.0.1%20-P6033%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3ERun%20the%20read%20and%20write%20queries%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3ESELECT%20*%20%0AFROM%20mydemotable%3B%0AUPDATE%20mydemotable%0ASET%20mydemocolumn%3Dvalue%0AWHERE%20condition%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20verify%20that%20ProxySQL%20has%20routed%20the%20above%20read%20and%20write%20correctly%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%203.%26nbsp%3B%3CSPAN%3EConnect%20to%20the%20ProxySQL%20administration%20interface%20on%20one%20of%20the%20VM%20with%20the%20default%20password%20%E2%80%98admin%E2%80%99.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Emysql%20%E2%80%93u%20admin%20%E2%80%93p%20admin%20-h127.0.0.1%20-P6032%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%204.%20Execute%20the%20following%20query%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3ESELECT%20*%20FROM%20stats_mysql_query_digest%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIf%20you%20have%20trouble%20setting%20up%20ProxySQL%20on%20Azure%20Database%20for%20MySQL%2C%20please%20contact%20the%20Azure%20Database%20for%20MySQL%20team%20at%20%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-AskAzureDBforMySQL%40service.microsoft.com%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThank%20you!%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EAmol%20Bhatnagar%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EProgram%20Manager%20-%20Microsoft%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1490357%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESet%20up%20ProxySQL%20clustering%20to%20connect%20efficiently%20to%20Azure%20Database%20for%20MySQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Introduction

Customers who have read our previous blogs frequently raise an important question: How should we configure ProxySQL in a highly available setup to get maximum performance and scale from our Azure Database for MySQL service. In this post, I hope to provide detail that will help to address the question.

Important: This post is a part of a multi-post blog series related to configuring ProxySQL with Azure Database for MySQL. We highly recommend that you read the previous posts in this series (shown below) to have more context about use cases for ProxySQL with Azure Database for MySQL servers.

Most of the time, you configure ProxySQL on a separate server, and all the connections are routed from the application to the ProxySQL server. ProxySQL in turn directs all the connections to database server depending on the query rules configured (illustrated in figure 1). There are some concerns with using this approach, as:

  • ProxySQL becomes a single point of failure for the application, potentially impacting the application’s availability.
  • The ProxySQL server can become a resource bottleneck, limiting performance and scale.

One way to address these concerns is to configure ProxySQL on the application side (illustrated in figure 2). By collocating ProxySQL with the application VMs, you also reduce cost. One of the downsides of this solution is the need to manually synchronize the ProxySQL configuration across application VMs or pods. While this works for many customers, if ProxySQL configuration changes are less frequent (as is the case in most scenarios), it can become a challenge in a complex setup. You can mitigate this problem and also build a highly available and scalable architecture with ProxySQL by using ProxySQL native clustering (as illustrated in figure 3).

Important:

This feature is experimental in ProxySQL and subject to change. We strongly recommend to think carefully before using it in production.

 

ambhatna_0-1593120927866.png

 

This blog post shows how to configure native ProxySQL clustering as shown in Figure 3.

Note:

ProxySQL is an open source community tool. It is supported by Microsoft on a best effort basis. In order to get production support with authoritative guidance, you can evaluate and reach out to ProxySQL Product support.

 

Prerequisites

For the example in this post, we’ll be setting up a cluster with three nodes and configuring the ProxySQL server to split the read and write workloads to designated Azure Database for MySQL servers. Prerequisites for this effort are outlined in the post Load balance read replicas using ProxySQL in Azure Database for MySQL, the difference being that we’ll use three Linux VMs running Ubuntu as three nodes for ProxySQL cluster.

 

Configuring ProxySQL native clustering

Perform below steps on all three Linux VMs.

To install ProxySQL, in the post Load balance read replicas using ProxySQL in Azure Database for MySQL, refer to the detail in the section “Installing ProxySQL on Ubuntu VM”.

  1. After installing ProxySQL, update the proxysql config file located at /etc/proxysql.cnf with the cluster details, and add the information about the servers hosting ProxySQL:

admin_variables=
{
admin_credentials="admin:admin;cluster1:secret1pass"
# mysql_ifaces="127.0.0.1:6032;/tmp/proxysql_admin.sock"
mysql_ifaces="0.0.0.0:6032"
# refresh_interval=2000
# debug=true
cluster_username="cluster1"
cluster_password="secret1pass"
cluster_check_interval_ms=200
cluster_check_status_frequency=100
cluster_mysql_query_rules_save_to_disk=true
cluster_mysql_servers_save_to_disk=true
cluster_mysql_users_save_to_disk=true
cluster_proxysql_servers_save_to_disk=true
cluster_mysql_query_rules_diffs_before_sync=3
cluster_mysql_servers_diffs_before_sync=3
cluster_mysql_users_diffs_before_sync=3
cluster_proxysql_servers_diffs_before_sync=3
}

proxysql_servers =
(
{
hostname="VM_1_Public_IP"
port=6032
comment="proxysql100"
},
{
hostname=" VM_2_Public_IP"
port=6032
comment="proxysql200"
},
{
hostname=" VM_3_Public_IP"
port=6032
comment="proxysql300"
}
)

Important:

  • In the proxysql.cnf file, only add the bolded configuration information above. Also, ensure that the VMs can communicate with each other using inbound and outbound rules.
  • Make sure that Azure VM are part of availability set to protect from datacenter level failure and update.

2. Execute the below step to re-initialize ProxySQL from the config file (after first startup the DB file is used instead of the proxysql.cnf config file)

 

Service proxysql initial​

 

Note:

In the previous section, we configured ProxySQL native clustering. This ensures that changes to one ProxySQL node will be propagated to all nodes in the cluster. From now onwards, please perform the ProxySQL specific changes to only one of the nodes in the ProxySQL cluster.

 

Setting up the ProxySQL

  1. Connect to the ProxySQL administration interface with the default password ‘admin’.
    mysql –u admin –p admin -h127.0.0.1 -P6032
  2. Add the reader and writer nodes ProxySQL server pool.
    insert into mysql_servers(hostgroup_id,hostname,port,weight,comment) values(1,'mydemomasterserver.mysql.database.azure.com',3306,1,'Write Group');
     
    insert into mysql_servers(hostgroup_id,hostname,port,weight,comment) values(2,'mydemoreplicaserver.mysql.database.azure.com',3306,1,'Read Group');
  3. Enable SSL support in ProxySQL server pool
    UPDATE mysql_servers SET use_ssl=1 WHERE hostgroup_id=1;
    UPDATE mysql_servers SET use_ssl=1 WHERE hostgroup_id=2;

Creating the MySQL users

In ProxySQL, the user connects to ProxySQL and in turn ProxySQL passes the connection to the MySQL node. To allow ProxySQL to access to the MySQL database, we need to create a user on MySQL database with the same credentials as on the ProxySQL server.

  1. Create a new user ‘mydemouser’ with the password ‘secretpassword’
    CREATE USER 'mydemouser'@'%' IDENTIFIED BY ' secretpassword';
  2. Grant ‘mydemouser’ privileges to fully access the MySQL server
    GRANT ALL PRIVILEGES ON *.* TO ' mydemouser'@'%' WITH GRANT OPTION;
  3. Apply the changes to the permissions
    FLUSH PRIVILEGES;

Creating the ProxySQL user

Note: Perform the action below on only one of the nodes in the ProxySQL cluster.

Allow the ‘mydemouser’ user to connect to ProxySQL server.

 

insert into mysql_users(username,password,default_hostgroup,transaction_persistent)values('mydemouser',' secretpassword',1,1);

 

Configure Monitoring on ProxySQL

Configure ProxySQL to monitor the nodes, and then create the monitoring user on the Master server.

 

  1. Create a new user ‘monitoruser’ with the password ‘secretpassword’
    CREATE USER ' monitoruser'@'%' IDENTIFIED BY 'secretpassword';​
  2. Grant ‘monitoruser’ privileges to fully access the MySQL server
    GRANT SELECT ON *.* TO ' monitoruser'@'%' WITH GRANT OPTION;
  3. Apply the changes to the permissions
    FLUSH PRIVILEGES;

On the server running ProxySQL, configure mysql-monitor to the username of the new account.

 

set mysql-monitor_username='monitoruser';
set mysql-monitor_password=' secretpassword';

 

Configure the routing rules for read and write split

  1. On the ProxySQL Server, configure the write traffic to route to the master server
    insert into mysql_query_rules(rule_id,active,match_digest,destination_hostgroup,apply)values(1,1,'^SELECT.*FOR UPDATE$',1,1);
  2. On the ProxySQL Server, configure the read traffic to route to the read replica server
    insert into mysql_query_rules(rule_id,active,match_digest,destination_hostgroup,apply)values(2,1,'^SELECT',2,1);

Save the changes made to the ProxySQL configuration to persists across restarts

In ProxySQL configuration system, the changes we made are in memory and to make them persist across the restarts, you must copy settings to runtime and save them to disk.

  1. On the server running ProxySQL, execute the below commands to save the settings to runtime:
    load mysql users to runtime;
    load mysql servers to runtime;
    load mysql query rules to runtime;
    load mysql variables to runtime;
    load admin variables to runtime;
    ​
  2. On the server running ProxySQL, execute the following commands to save the settings to disk:
    save mysql users to disk;
    save mysql servers to disk;
    save mysql query rules to disk;
    save mysql variables to disk;
    save admin variables to disk;

After successfully completing the above steps, ProxySQL is configured with native clustering and is ready to split the read and write workload. Use the following steps to test if the read and write splits are being forwarded properly:

  1. Log in to one of the servers running ProxySQL with the ProxySQL user you created
    mysql –u mydemouser –p secretpassword -h127.0.0.1 -P6033
  2. Run the read and write queries

 

SELECT * 
FROM mydemotable;
UPDATE mydemotable
SET mydemocolumn=value
WHERE condition;

 

To verify that ProxySQL has routed the above read and write correctly:

      3. Connect to the ProxySQL administration interface on one of the VM with the default password ‘admin’.

 

mysql –u admin –p admin -h127.0.0.1 -P6032

 

      4. Execute the following query:

 

SELECT * FROM stats_mysql_query_digest;

 

If you have trouble setting up ProxySQL on Azure Database for MySQL, please contact the Azure Database for MySQL team at AskAzureDBforMySQL@service.microsoft.com

Thank you!

Amol Bhatnagar

Program Manager - Microsoft