Congratulations!

[Valid RSS] This is a valid RSS feed.

Recommendations

This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.

Source: http://www.tusacentral.net/joomla/index.php/mysql-blogs?format=feed&type=rss

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- generator="Joomla! - Open Source Content Management" -->
  3. <?xml-stylesheet href="/joomla/plugins/system/jce/css/content.css?badb4208be409b1335b815dde676300e" type="text/css"?>
  4. <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  5. <channel>
  6. <title>TusaCentral - MySQL Blogs</title>
  7. <description><![CDATA[]]></description>
  8. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs</link>
  9. <lastBuildDate>Wed, 18 Jun 2025 20:53:03 +0000</lastBuildDate>
  10. <generator>Joomla! - Open Source Content Management</generator>
  11. <atom:link rel="self" type="application/rss+xml" href="http://www.tusacentral.net/joomla/index.php/mysql-blogs?format=feed&amp;type=rss"/>
  12. <language>en-gb</language>
  13. <item>
  14. <title>How to Set Up the Development Environment for MySQL Shell Plugins for Python</title>
  15. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/259-how-to-set-up-the-development-environment-for-mysql-shell-plugins-for-python</link>
  16. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/259-how-to-set-up-the-development-environment-for-mysql-shell-plugins-for-python</guid>
  17. <description><![CDATA[<p>MySQL Shell is a powerful tool for managing MySQL databases, and one of its most exciting features is the ability to extend its functionality using plugins. If you're a Python developer, you can create custom plugins to automate tasks, add new commands, or<img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/dolphin-programming.jpeg" alt="dolphin programming" width="300" height="300" style="margin-left: 10px; margin-bottom: 10px; float: right;" /><br style="clear: none;" /> integrate MySQL Shell with other tools. However debugging the python code could be cumbersome for mysql-shell given the python code requires some specific objects available only when running inside the shell.&nbsp;</p>
  18. <p>In this blog post, we'll walk you through the steps to set up your development environment for creating MySQL Shell plugins in Python while able to modify and debug the mysql-shell itself.</p>
  19. <h2>Prerequisites</h2>
  20. <p>Before we dive into the setup, ensure you have the following installed on your system:</p>
  21. <p>&nbsp;</p>
  22. <ul>
  23. <li aria-level="1">MySQL Shell: Download and install MySQL Shell from the official MySQL website.</li>
  24. <li aria-level="1">Python 3.8 or later: MySQL Shell plugins require Python 3.8+. You can download Python from python.org.</li>
  25. <li aria-level="1">A code editor: Use your favorite code editor, such as VS Code</li>
  26. <li aria-level="1">Git: Optional, but useful for version control.</li>
  27. </ul>
  28. <p>&nbsp;</p>
  29. <p>A directory structure as follow:</p>
  30. <pre>mysql_source/
  31. ├── boost
  32. ├── mysql-8.4.4&nbsp; &lt;-- directory where we compile the mysql server&nbsp;
  33. ├── mysql-server &lt;-- directory with the source code (from git or package)
  34. ├── mysql-shell&nbsp; &lt;-- directory with the mysql-shell code from git
  35. ├── mysql-shell-build-vs &lt;-- directory where we build using Visual Studio
  36. └── mysql-shell-plugins&nbsp; &lt;-- directory with the example plugin&nbsp;
  37. </pre>
  38. <p>&nbsp;</p>
  39. <h2>Step 1: Collect and compile MySQL server code</h2>
  40. <p>If you want to clone the MySQL repository:</p>
  41. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">git clone <a href="https://github.com/mysql/mysql-server.git"></a><a href="https://github.com/mysql/mysql-server.git">https://github.com/mysql/mysql-server.git</a></span></p>
  42. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">git fetch</span></p>
  43. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">git checkout tags/mysql-8.4.4 -b mysql-8.4.4&nbsp;</span></p>
  44. <p>&nbsp;</p>
  45. <p>Or just download the source code from the website for that specific release:</p>
  46. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">curl <a href="https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-8.4.4.tar.gz"></a><a href="https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-8.4.4.tar.gz">https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-8.4.4.tar.gz</a> - o mysql-8.4.4.tar.gz</span></p>
  47. <p>&nbsp;</p>
  48. <p>In both cases once you have the code locally we need to configure and build the libraries.</p>
  49. <p>For more information about how to compile and dependencies check <a href="https://dev.mysql.com/doc/refman/8.4/en/source-installation.html">here</a></p>
  50. <p>&nbsp;</p>
  51. <p>Then we go inside the compile directory (mysql-8.4.4) and configure it:</p>
  52. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">cmake /<span style="font-family: 'courier new', courier;">&lt;path&gt;</span>/mysql_source/mysql-server -DCMAKE_INSTALL_PREFIX=/<span style="font-family: 'courier new', courier;">&lt;path&gt;</span>/mysql_templates/mysql-8.4.4 -DWITH_DEBUG=1 -Dprotobuf_BUILD_SHARED_LIBS=ON</span></p>
  53. <p>&nbsp;</p>
  54. <p>And we compile the needed libraries:</p>
  55. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;cmake --build . --target mysqlclient</span></p>
  56. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;cmake --build . --target mysqlxclient</span></p>
  57. <p>&nbsp;</p>
  58. <p>There is no need to compile the whole server, unless you really want to.&nbsp;</p>
  59. <p>&nbsp;</p>
  60. <h2>Step 2: Collect and compile MySQL Shell code</h2>
  61. <p>Once the server libs are prepared then go for mysql-shell.</p>
  62. <p>Get the code:</p>
  63. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">git clone <a href="https://github.com/mysql/mysql-server.git"></a><a href="https://github.com/mysql/mysql-server.git">https://github.com/mysql/mysql-server.git</a></span></p>
  64. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">git fetch</span></p>
  65. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">git checkout tags/8.4.4 -b 8.4.4</span></p>
  66. <p>&nbsp;</p>
  67. <p>Now my advice is to always do a compilation outside the code editor to be sure we have all the needed components, for more info check <a href="https://github.com/mysql/mysql-shell/blob/master/INSTALL">here</a></p>
  68. <p>&nbsp;</p>
  69. <p>To configure:</p>
  70. <p><span style="font-family: 'courier new', courier;">cmake /<span style="font-family: 'courier new', courier;">&lt;path&gt;</span>/mysql_source/mysql-shell -DMYSQL_SOURCE_DIR=/<span style="font-family: 'courier new', courier;">&lt;path&gt;</span>/mysql_source/mysql-server/ -DMYSQL_BUILD_DIR=/<span style="font-family: 'courier new', courier;">&lt;path&gt;</span>/mysql_source/mysql-8.4.4 -DHAVE_PYTHON=1 -DHAVE_V8=0 -DWITH_TESTS=1 -DCMAKE_BUILD_TYPE=Debug&nbsp;</span><span style="font-family: 'courier new', courier;">-DCMAKE_INSTALL_PREFIX=/<span style="font-family: 'courier new', courier;">&lt;path&gt;</span>/mysql_source/mysql_shell_bin&nbsp;</span></p>
  71. <p>&nbsp;</p>
  72. <p>If all went well you can check if the mysql-shell works properly running it from the destination path (in the example) /opt/mysql_source/mysql_shell_bin/bin/mysqlsh&nbsp;</p>
  73. <h2>Step 3: Set Up a Python Virtual Environment</h2>
  74. <p>To avoid conflicts with other Python projects, it's a good idea to create a virtual environment for your MySQL Shell plugin development.</p>
  75. <p>Open your terminal and navigate to your project directory.</p>
  76. <p>Create a virtual environment:</p>
  77. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">python -m venv mysqlsh-plugin-env</span></p>
  78. <p>Activate the virtual environment:</p>
  79. <p>&nbsp;</p>
  80. <p>On macOS/Linux:</p>
  81. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">source mysqlsh-plugin-env/bin/activate</span></p>
  82. <p>&nbsp;</p>
  83. <p>Verify that the virtual environment is active. Your terminal prompt should now show the name of the virtual environment.</p>
  84. <p>&nbsp;</p>
  85. <h2>Step 4: For lazy people (as myself) download and use existing plugin demos.</h2>
  86. <p>Our dear friend <a href="https://lefred.be/">Lefred </a>has built a very nice suite that I normally use as a starting point.</p>
  87. <p>Get the code, go to your mysql_source directory and:</p>
  88. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">git clone <a href="https://github.com/lefred/mysqlshell-plugins.git"></a><a href="https://github.com/lefred/mysqlshell-plugins.git">https://github.com/lefred/mysqlshell-plugins.git</a>&nbsp;</span></p>
  89. <p>&nbsp;</p>
  90. <p>In mysql-shell at the moment you can load the plugin at startup only if they are located in the sub-directory ~/.mysqlsh/plugins or where the lib/mysqlsh/plugins is located. See <a href="https://bugs.mysql.com/bug.php?id=117569">FR here</a> for a more convenient way to dynamically pass the path to browse.&nbsp;</p>
  91. <p>Anyhow for now and the purpose of this blog let us use a a trick and create a symlink:</p>
  92. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">mkdir ~/.mysqlsh/plugins</span></p>
  93. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">ln -s &lt;path&gt;/mysql_source/mysql-shell-plugins/demo ~/.mysqlshell/plugins/demo</span></p>
  94. <p>&nbsp;</p>
  95. <p>Ok now our code side is set.&nbsp;</p>
  96. <p>Download and configure VisualStudio.</p>
  97. <p>Add few extension, mine are the following:</p>
  98. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/1.jpg" alt="1" width="473" height="700" /></p>
  99. <p>&nbsp;</p>
  100. <p>Then open the directory where you have clone the mysql-shell code inside VS and save it as workspace:</p>
  101. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/2.jpg" alt="2" width="285" height="616" /></p>
  102. <p>&nbsp;</p>
  103. <p>Then click again on the File and <em>add Folder to workspace</em> and add mysql-shell-plugin/demo directory.&nbsp;</p>
  104. <p>&nbsp;</p>
  105. <p>Now we need to configure the cmake side of the project:</p>
  106. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/3.jpg" alt="3" width="501" height="318" /></p>
  107. <p>&nbsp;</p>
  108. <p>Click on the icon on the left first then on the settings wheel to open the specific menu.&nbsp;</p>
  109. <p>I suggest you to change things at workspace level choosing the workspace tab:</p>
  110. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/4.jpg" alt="4" width="280" height="103" /></p>
  111. <p>&nbsp;</p>
  112. <p>Look for the Cmake: Build Directory option and set it to /&lt;add full path&gt;/mysql_source/mysql-shell-build-vs as outlined before.&nbsp;</p>
  113. <p>Then look for the <strong>Cmake: Configure Settings</strong> option and click on edit settings.json and set as follow:<br /> <span style="font-family: 'courier new', courier;">"cmake.configureSettings": {</span></p>
  114. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">"MYSQL_SOURCE_DIR":"/&lt;add full path&gt;/mysql_source/mysql-server/",</span></p>
  115. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">"MYSQL_BUILD_DIR":"/&lt;add full path&gt;/mysql_source/mysql-8.4.4",</span></p>
  116. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">"HAVE_PYTHON":true,</span></p>
  117. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">"BUNDLED_POLYGLOT_DIR":0,</span></p>
  118. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">"WITH_TESTS":true,</span></p>
  119. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">"CMAKE_BUILD_TYPE":"Debug",</span></p>
  120. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">},</span></p>
  121. <p>The above will create the Cmake configuration and structure in /&lt;add full path&gt;/mysql_source/mysql-shell-build-vs.&nbsp;</p>
  122. <p>&nbsp;</p>
  123. <p>Once this is done compile the project clicking on the small icon close to build</p>
  124. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/5.jpg" alt="5" width="471" height="283" /></p>
  125. <p>This will build the whole project, sit down and relax while compilation will complete.&nbsp;</p>
  126. <p>&nbsp;</p>
  127. <p>Once this is complete click on the run-and-debug&nbsp; icon:<br /><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/6.jpg" alt="6" width="344" height="441" /></p>
  128. <p>Then click on create a launch.json</p>
  129. <p>Choose mysql-shell-vs:</p>
  130. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/7.jpg" alt="7" width="627" height="163" /></p>
  131. <p>&nbsp;</p>
  132. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/8.jpg" alt="8" width="581" height="386" /></p>
  133. <p>Then pick C/C++ gdb Attach.</p>
  134. <p>This will open a json file, we are interested in the values inside the “configurations”, it should be something like this:<br /> &nbsp;<span style="font-family: 'courier new', courier;"> &nbsp; &nbsp; {</span></p>
  135. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"name": "(gdb) Launch",</span></p>
  136. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type": "cppdbg",</span></p>
  137. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"request": "launch",</span></p>
  138. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"program": "/&lt;add full path&gt;/mysql_source/mysql-shell-build-vs/bin/mysqlsh",</span></p>
  139. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"args": [</span></p>
  140. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"--verbose=1"</span></p>
  141. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;],</span></p>
  142. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"stopAtEntry": false,</span></p>
  143. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"cwd": "/&lt;add full path&gt;/mysql_source/mysql-shell-build-vs/",</span></p>
  144. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"environment": [{"name": "PYTHONPATH", "value": "PATH to your python directory"}],</span></p>
  145. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"externalConsole": false,</span></p>
  146. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"MIMode": "gdb",</span></p>
  147. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"setupCommands": [</span></p>
  148. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span></p>
  149. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"description": "Enable pretty-printing for gdb",</span></p>
  150. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"text": "-enable-pretty-printing",</span></p>
  151. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ignoreFailures": true</span></p>
  152. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},</span></p>
  153. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span></p>
  154. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"description": "Set Disassembly Flavor to Intel",</span></p>
  155. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"text": "-gdb-set disassembly-flavor intel",</span></p>
  156. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ignoreFailures": true</span></p>
  157. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></p>
  158. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]</span></p>
  159. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></p>
  160. <p>After that you need to add the Python debugger information:</p>
  161. <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>&nbsp;{</code></p>
  162. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"name": "plugin-p",</code></p>
  163. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type": "debugpy",</code></p>
  164. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"request": "attach",</code></p>
  165. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"connect": {</code></p>
  166. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"host": "localhost",</code></p>
  167. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"port": 5678</code></p>
  168. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},</code></p>
  169. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"pathMappings": [</code></p>
  170. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</code></p>
  171. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"localRoot": "${workspaceFolder}",</code></p>
  172. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"remoteRoot": "."</code></p>
  173. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</code></p>
  174. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;],</code></p>
  175. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"justMyCode": false</code></p>
  176. <p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},</code></p>
  177. <p>As you can see what we will do is to attach the debugger to a process that will spin up inside the code.</p>
  178. <p>&nbsp;</p>
  179. <p>Save the file, and in the left panel you will now have the option to run and debug using both debuggers.&nbsp;</p>
  180. <p>Before running the debug let us do a couple of more things.</p>
  181. <p>Click on the project explorer and open the init.py file in the demo directory&nbsp;</p>
  182. <p>&nbsp;</p>
  183. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/9.jpg" alt="9" width="313" height="446" /></p>
  184. <p>&nbsp;</p>
  185. <p>Before the instruction: import mysqlsh, add this text:</p>
  186. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">import debugpy</span></p>
  187. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">debugpy.listen(("localhost", 5678))</span></p>
  188. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">print("Waiting for debugger attach...")</span></p>
  189. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">debugpy.wait_for_client()</span></p>
  190. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">print("Debugger attached.")</span></p>
  191. <p>If the module debugpy is not installed do it with:</p>
  192. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">pip install debugpy</span></p>
  193. <p>Then before the last line add:</p>
  194. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">import mysqlsh</span></p>
  195. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">shell = mysqlsh.globals.shell</span></p>
  196. <p style="padding-left: 30px;">&nbsp;</p>
  197. <p>This to create the shell object that is available only internally to the mysql-shell.</p>
  198. <p>&nbsp;</p>
  199. <p>Now let us add a couple of breakpoints one in the mysql-shell code and another inside the python code.</p>
  200. <p>In mysql_shell.cc look for:</p>
  201. <p style="padding-left: 30px;">&nbsp;<span style="font-family: 'courier new', courier;">&nbsp;for (const auto &amp;dir : plugin_directories) {</span></p>
  202. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;&nbsp;&nbsp;get_plugins(file_list, dir, true);</span></p>
  203. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;&nbsp;}</span></p>
  204. <p>In mysql-shell 8.4.4 is at line 964.</p>
  205. <p>Put a breakpoint on <span style="font-family: 'courier new', courier;">get_plugins</span></p>
  206. <p>Then open oracle8ball.py and put a breakpoint on the last line:</p>
  207. <p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&nbsp;print(answers[index])&nbsp;</span></p>
  208. <p>&nbsp;</p>
  209. <p>Run the C/C++ debugger…&nbsp;</p>
  210. <p>The execution will stop and in the debug left panel you will see the variable informations plus the debug toolbar:</p>
  211. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/10.jpg" alt="10" width="778" height="307" /></p>
  212. <p>This is standard debug for C/C++ projects … Let us click to proceed.</p>
  213. <p>Execution will continue until loading the plugins then will stop. It will hang because the line we have inserted:</p>
  214. <p><samp>debugpy.wait_for_client()</samp></p>
  215. <p><br />Now run the Python debugger it will connect to the dbugger we defined in the code allowing the process to continue.</p>
  216. <p>In the terminal window the mysql-shell prompt will appear but not only:</p>
  217. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/10-1.jpg" alt="10 1" width="556" height="313" /></p>
  218. <p>We can see that the python debugger is now also attached.&nbsp;</p>
  219. <p>&nbsp;</p>
  220. <p>Let us move to python and execute the demo.oracle8ball()</p>
  221. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/10-2.jpg" alt="10 2" width="524" height="337" /></p>
  222. <p>&nbsp;</p>
  223. <p>Execution is suspended and our debugger stop at our breakpoint:</p>
  224. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql-shell/11.jpg" alt="11" width="786" height="321" /></p>
  225. <p>&nbsp;</p>
  226. <p>Please note two things, the first is that also in this case we can see the whole set of information related to local and global variables including the shell object and the other is that the debugger menu shows that now the navigation button refers to the python debugger.&nbsp;</p>
  227. <p>&nbsp;</p>
  228. <p>This level of integration will give anyone a more friendly environment where to develop your mysql-shell extensions. This is particularly important for the ones who wish to standardize and simplify the DBA operation or to give developers easy access to independently and safely perform actions on the databases.&nbsp;</p>
  229. <h2>Tips for Developing MySQL Shell Plugins</h2>
  230. <p>Use the MySQL Shell API: MySQL Shell provides a rich API for interacting with MySQL databases. Refer to the official documentation for details.</p>
  231. <ul>
  232. <li aria-level="1">Test Incrementally: Test your plugin functions frequently to catch errors early.</li>
  233. <li aria-level="1">Leverage Python Libraries: You can use any Python library in your plugin, so take advantage of the vast Python ecosystem.</li>
  234. </ul>
  235. <h1>Conclusion</h1>
  236. <p>Setting up a development environment for MySQL Shell plugins in Python is straightforward. With the right tools and a bit of Python knowledge, you can create powerful extensions to enhance MySQL Shell's functionality. Whether you're automating database tasks or integrating with other systems, MySQL Shell plugins offer endless possibilities.</p>
  237. <p>&nbsp;</p>
  238. <p>Happy coding!</p>
  239. <p>&nbsp;</p>
  240. <p></p>]]></description>
  241. <category>MySQL</category>
  242. <pubDate>Thu, 27 Feb 2025 15:39:47 +0000</pubDate>
  243. </item>
  244. <item>
  245. <title>MySQL latest performance review</title>
  246. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/258-mysql-latest-performance-review</link>
  247. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/258-mysql-latest-performance-review</guid>
  248. <description><![CDATA[<p>This article is focused on describing the latest performance benchmarking executed on the latest release of MySQL and Percona.&nbsp;<img src="http://www.tusacentral.net/joomla/images/stories/mysql_performance_january_2025/dolphin_jumping_outside.jpeg" alt="dolphin jumping outside" width="286" height="286" style="margin-left: 10px; float: right;" /></p>
  249. <p>In this set of tests I have used the machine described <a href="https://github.com/Tusamarco/blogs/blob/master/testmachine/testmachine.md">here</a>.&nbsp;&nbsp;</p>
  250. <h3>Assumptions</h3>
  251. <p>There are many ways to run tests, and we know that results may vary depending on how you play with many factors, like the environment or the MySQL server settings. However, if we compare several versions of the same product on the same platform, it is logical to assume that all the versions will have the same “chance” to behave well or badly unless we change the MySQL server settings.&nbsp;</p>
  252. <p>Because of this, I ran the tests changing only things in a consistent way, with the intent to give the same opportunity to each solution., with the clear assumption that if you release your product based on the defaults, that implies you had tested with them and consider them the safest for generic use.&nbsp;</p>
  253. <p>I also applied some <a href="https://github.com/Tusamarco/blogs/blob/master/testmachine/mysql_configuration.md">modifications </a>and ran the tests again to see how optimization would impact performance.&nbsp;</p>
  254. <h3>What tests do we run?</h3>
  255. <p>High level, I run one set of test:</p>
  256. <ul>
  257. <li aria-level="1">TPC-C (<a href="https://www.tpc.org/tpcc/"></a><a href="https://www.tpc.org/tpcc/">https://www.tpc.org/tpcc/</a>) like&nbsp;</li>
  258. </ul>
  259. <p>The full methodology and test details can be found <a href="https://github.com/Tusamarco/benchmarktools/blob/main/docs/plan.md">here</a>, while actual commands are available:</p>
  260. <ul>
  261. <li aria-level="1"><a href="https://github.com/Tusamarco/benchmarktools/blob/main/software/fill_sysbench_map.sh">Sysbench</a></li>
  262. <li aria-level="1"><a href="https://github.com/Tusamarco/benchmarktools/blob/main/software/fill_tpcc_map.sh">TPC-C</a>&nbsp;</li>
  263. </ul>
  264. <p>&nbsp;</p>
  265. <h3>Why do I only run TPC-C tests?&nbsp;&nbsp;</h3>
  266. <p>Well I am, normally, more interested in testing scenarios that are closer to reality than a single function test as we normally do with sysbench.&nbsp;</p>
  267. <p>This is it, while it is not possible to get the perfect benchmark test fitting all real usage, we need to keep in mind the rule of 80%.&nbsp;</p>
  268. <p>If you use MYSQL/InnoDB I expect that you have an OLTP kind of traffic, more than Key/Value or else. Given that while testing the single function, as we do with sysbench, may be useful to identify regression points or so. To get the wide scenario, TPC-C is a better way to go, given it implies not only a more intense write load, TPC-C test is 50/50 r/w, but also a schema structure with relations, foreign keys and constraints. In short, it is closer to the common use of a relational database management system.&nbsp;</p>
  269. <p>&nbsp;</p>
  270. <h2>Results</h2>
  271. <p>The tests done have two different kinds of isolation levels. <a href="http://www.tusacentral.net/joomla/#Repeatable_reads">Repeatable Read</a> and <a href="http://www.tusacentral.net/joomla/#Read_committed">Read Committed</a>. The first is the default in MySQL/InnoDB, while the second is the default in many other very well known RDBMS.&nbsp;</p>
  272. <p>&nbsp;</p>
  273. <p>As usual an image is more descriptive than many words:</p>
  274. <p><a href="http://www.tusacentral.net/joomla/images/stories/mysql_performance_january_2025/TPC-C_Read_Committed__Operations_sec.png" target="_parent"><img src="http://www.tusacentral.net/joomla/images/stories/mysql_performance_january_2025/TPC-C_Read_Committed__Operations_sec.png" alt="TPC C Read Committed Operations sec" width="600" height="322" /></a></p>
  275. <p><a href="http://www.tusacentral.net/joomla/images/stories/mysql_performance_january_2025/TPC-c_Repeatable_Read__Operations_sec.png"><img src="http://www.tusacentral.net/joomla/images/stories/mysql_performance_january_2025/TPC-c_Repeatable_Read__Operations_sec.png" alt="TPC c Repeatable Read Operations sec" width="600" height="322" /></a></p>
  276. <p>You can also compare these trends (not the values) with the previous results published <a href="http://www.tusacentral.net/joomla/index.php/mysql-blogs/256-sakila-where-are-you-going">here</a>.</p>
  277. <p>Let us comment a bit on these images.&nbsp;</p>
  278. <p><strong>The first comment</strong> we should make is that nowadays our systems must be ready to scale. Period, no discussion, also doing benchmarks up to 1024 threads is not enough. In reality we have 4000 or even more connections, given that doing benchmarking exercises and stopping the load at 128 threads or lower, makes no sense. Here it is quite clear that doing something like that could be very misleading.&nbsp;</p>
  279. <p>Old MySQL versions are still faster than newer with low level of concurrency, but they do not scale. So if I stop my tests at 64 or 128 threads I will conclude that MySQL 5.7 is always better than newer versions, while if I go on loading, I can see that old version performance drop after 64 concurrent threads.&nbsp;</p>
  280. <p>&nbsp;</p>
  281. <p><strong>The second comment</strong> is that while in previous tests (see mentioned article) we saw that newer versions were not performing better or even consistently. With the latest releases MySQL had not only stabilized the server behaviour, but done significant fixes to the performance issues it had.&nbsp;</p>
  282. <p>If we remove the 5.7 version from the graphs we can see clearer what is going on:</p>
  283. <p><a href="http://www.tusacentral.net/joomla/images/stories/mysql_performance_january_2025/TPC-C_Read_Committed__Operations_sec_no57.png"><img src="http://www.tusacentral.net/joomla/images/stories/mysql_performance_january_2025/TPC-C_Read_Committed__Operations_sec_no57.png" alt="TPC C Read Committed Operations sec no57" width="600" height="322" /></a></p>
  284. <p><a href="http://www.tusacentral.net/joomla/images/stories/mysql_performance_january_2025/TPC-c_Repeatable_Read__Operations_sec_no57.png"><img src="http://www.tusacentral.net/joomla/images/stories/mysql_performance_january_2025/TPC-c_Repeatable_Read__Operations_sec_no57.png" alt="TPC c Repeatable Read Operations sec no57" width="600" height="322" /></a></p>
  285. <p>If you notice the servers lines after 32 threads and especially after 64 threads diverge and we have two groups one see Percona and MySQL 8.0.40 in the lower set while Percona and MySQL 8.4 and 9.x are in the upper group.&nbsp;</p>
  286. <p>This is quite great news and very nice to see, because if I have to read it in a way I see a positive sign indicating how Oracle/MySQL is progressively resolving some performance issues and gaining ground again.&nbsp;</p>
  287. <p>&nbsp;<a href="http://www.tusacentral.net/joomla/static/data_Tpccallno5.7_.html">see also dynamic graphs</a></p>
  288. <h1>Conclusions</h1>
  289. <p>The tests performed using TPC-C like tests confirms the initial finding of my colleague <a href="https://www.percona.com/blog/mysql-8-4-3-and-9-1-0-major-performance-gains-revealed/">here</a>, and give us a picture that is more positive of what we had. At the same time they indicate that the race to get better performance is open again, and I am intrigued to see what will come next.</p>
  290. <p>For now we can say that MySQL 9.2 is the better performing MySQL version currently available, for its stability and scalability.&nbsp;</p>
  291. <p>Great job!&nbsp;&nbsp;</p>
  292. <p>&nbsp;</p>]]></description>
  293. <category>MySQL</category>
  294. <pubDate>Tue, 28 Jan 2025 16:35:38 +0000</pubDate>
  295. </item>
  296. <item>
  297. <title>How to migrate a production database to Percona Everest (MySQL) using Clone</title>
  298. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/257-how-to-migrate-a-production-database-to-percona-everest-mysql-using-clone</link>
  299. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/257-how-to-migrate-a-production-database-to-percona-everest-mysql-using-clone</guid>
  300. <description><![CDATA[<p><span style="font-weight: 400;">The aim of this long article is to give you the instructions and tools to migrate your production database, from your current environment to a solution based on </span><a href="https://docs.percona.com/everest/index.html"><span style="font-weight: 400;">Percona Everest (MySQL)</span></a><span style="font-weight: 400;">.</span></p>
  301. <p><span style="font-weight: 400;">Nice, you decided to test Percona Everest, and you found that it is the tool you were looking for to manage your private DBaaS. For sure the easiest part will be to run new environments to get better understanding and experience on how the solution works. However, the day when you will look to migrate your existing environments will come. What should you do?</span></p>
  302. <p><span style="font-weight: 400;">Prepare a plan! In which the first step is to </span><b>understand your current environment</b><span style="font-weight: 400;">.&nbsp;</span></p>
  303. <p><span style="font-weight: 400;">&nbsp;When I say understand the current environment, I mean that you need to have a clear understanding of:</span></p>
  304. <ul>
  305. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">the current dimensions (CPU/Memory/Disk utilization)</span></li>
  306. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">the way it is accessed by the application, what kind of query you have, is Read or Write intensive, do you have pure OLTP or also some analytic, any ELT processing</span></li>
  307. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">the way it is used, constant load or by time of the day or by day of the year? Do you have any peak ie: Black Friday&nbsp;</span></li>
  308. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">what is the RPO/RTO, do you need a Disaster Recovery site?&nbsp;</span></li>
  309. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Who is accessing your database, and why.&nbsp;</span></li>
  310. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">What MySQL version are you using, is it compatible with Percona Everest MySQL versions?&nbsp;</span></li>
  311. </ul>
  312. <p><span style="font-weight: 400;">Once you have all the information, it is time to perform a quick review if the solution could fit or not, for this step, given its complexity, I suggest you contact Percona and get help from our experts to take the right decision.&nbsp;&nbsp;&nbsp;</span></p>
  313. <p><span style="font-weight: 400;">From the above process you should come with few clear indications such as:</span></p>
  314. <ul>
  315. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Needed resources</span></li>
  316. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">It is more read, write or 50/50</span></li>
  317. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">The level of recovery I need</span></li>
  318. </ul>
  319. <p><span style="font-weight: 400;">The first thing to do is to calculate the optimal configuration. For this you can help yourself with the </span><a href="https://github.com/Tusamarco/mysqloperatorcalculator"><span style="font-weight: 400;">mysqloperatorcalculator</span></a><span style="font-weight: 400;">. The tool will give you the most relevant variables to set for MySQL, configuration that you will be able to pass to Percona Everest while creating the new cluster.&nbsp;&nbsp;</span></p>
  320. <p><span style="font-weight: 400;">To install </span><a href="https://docs.percona.com/everest/install/SetupPrereqs.html"><span style="font-weight: 400;">Percona Everest see here</span></a></p>
  321. <h2><span style="font-weight: 400;">Create the new cluster</span></h2>
  322. <p><span style="font-weight: 400;">It is now time to open our Percona Everest console and start the adventure. </span></p>
  323. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/09/everest1-a.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/how_to_migrate_toPeverest/everest1-a.jpg" alt="everest1 a" width="1024" height="169" class="alignnone size-large wp-image-98244" /></a></p>
  324. <p><span style="font-weight: 400;">In the basic information step, look at the supported versions for Database Server</span></p>
  325. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/09/everest2-a.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/how_to_migrate_toPeverest/everest2-a.jpg" alt="everest2 a" width="1024" height="478" class="alignnone size-large wp-image-98246" /></a></p>
  326. <p><span style="font-weight: 400;">This version and the source version must match to safely use the CLONE plugin. Note that you cannot clone between MySQL 8.0 and MySQL 8.4 but can clone within a series such as MySQL 8.0.37 and MySQL 8.0.42. Before 8.0.37, the point release number also had to match, so cloning the likes of 8.0.36 to 8.0.42 or vice-versa is not permitted</span></p>
  327. <p><span style="font-weight: 400;">It is now time to set the resources, the value of them should come from the analysis previously performed.</span></p>
  328. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/09/everest3-a.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/how_to_migrate_toPeverest/everest3-a.jpg" alt="everest3 a" width="1024" height="446" class="alignnone size-large wp-image-98248" /></a></p>
  329. <p><span style="font-weight: 400;">Given that choose 1 (one) node, then Custom and feel the fields as appropriate.</span></p>
  330. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/09/everest4-a.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/how_to_migrate_toPeverest/everest4-a.jpg" alt="everest4 a" width="1024" height="481" class="alignnone size-large wp-image-98250" /></a></p>
  331. <p><span style="font-weight: 400;">In advance configuration add the IP(s) you want to allow to access the cluster. You must add the IP of the source, IE 18.23.4.12/32.&nbsp;&nbsp;</span></p>
  332. <p><span style="font-weight: 400;">In the set database engine parameters add the values (for MySQL only) that the mysqloperatorcalculator is giving you. Do not forget to have the </span><b>mysqld</b><span style="font-weight: 400;"> section declaration.</span></p>
  333. <p><span style="font-weight: 400;">For example, in our case I need to calculate the needed values for a MySQL server with 4 CPU 8GB ram serving OLTP load, once you have the mysqloperatorcalculator tool running:</span></p>
  334. <pre class="lang:sh decode:true">$ curl -i -X GET -H "Content-Type: application/json" -d '{"output":"human","dbtype":"pxc", "dimension":  {"id": 999, "cpu":4000,"memory":"8G"}, "loadtype":  {"id": 3}, "connections": 300,"mysqlversion":{"major":8,"minor":0,"patch":36}}' http://127.0.0.1:8080/calculator</pre>
  335. <p><span style="font-weight: 400;">You will get a set of values that after cleanup looks like:</span></p>
  336. <pre class="lang:sh decode:true">[mysqld]
  337.    binlog_cache_size = 262144
  338.    binlog_expire_logs_seconds = 604800
  339.    binlog_format = ROW
  340. … snip …
  341.    loose_wsrep_sync_wait = 3
  342.    loose_wsrep_trx_fragment_size = 1048576
  343.    loose_wsrep_trx_fragment_unit = bytes
  344. </pre>
  345. <p><span style="font-weight: 400;">Add the text in the TEXTAREA for the database parameters.</span></p>
  346. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/09/everest5-a.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/how_to_migrate_toPeverest/everest5-a.jpg" alt="everest5 a" width="1024" height="354" class="alignnone size-large wp-image-98252" /></a></p>
  347. <p><span style="font-weight: 400;">Enable monitoring if you like then click on Create database.</span></p>
  348. <p><span style="font-weight: 400;">Once ready you will have something like this:</span></p>
  349. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/09/everest6.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/how_to_migrate_toPeverest/everest6.jpg" alt="everest6" width="1024" height="158" class="alignnone size-large wp-image-98253" /></a></p>
  350. <p><span style="font-weight: 400;">Or from shell</span></p>
  351. <pre class="lang:sh decode:true">$ kubectl get pxc
  352. NAME         ENDPOINT   STATUS   PXC   PROXYSQL   HAPROXY   AGE
  353. test-prod1   xxx        ready    1                1         2m49s
  354.  
  355. $ kubectl get pods
  356. NAME                                              READY   STATUS    RESTARTS   AGE
  357. percona-xtradb-cluster-operator-fb4cf7f9d-97rfs   1/1     Running   0          13d
  358. test-prod1-haproxy-0                              3/3     Running   0          106s
  359. test-prod1-pxc-0                                  2/2     Running   0          69s
  360. </pre>
  361. <p><span style="font-weight: 400;">We are now ready to continue our journey.</span></p>
  362. <h2><span style="font-weight: 400;">Align the system users</span></h2>
  363. <p><span style="font-weight: 400;">This is a very important step. Percona Everest use the Percona Operator who will create a </span><a href="https://docs.percona.com/percona-operator-for-mysql/pxc/users.html"><span style="font-weight: 400;">set of system users</span></a><span style="font-weight: 400;"> in the database, and these users must be present also in the source with the same level of GRANTS, otherwise after the clone phase is terminated, the system will not work correctly.&nbsp;</span></p>
  364. <p><span style="font-weight: 400;">Keep in mind Percona Everest will create the users with some generated password, these passwords may or may not fit your company rules or be simply too crazy. Do not worry you will be able to change them. For now, let's see what the system has generated.&nbsp;</span></p>
  365. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/09/everest8.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/how_to_migrate_toPeverest/everest8.jpg" alt="everest8" width="1024" height="234" class="alignnone size-large wp-image-98255" /></a></p>
  366. <p><span style="font-weight: 400;">To see how to access the cluster click on the “</span><b>^</b><span style="font-weight: 400;">” top right, it will expand the section. User is “root” now unhide the password… Ok I don’t know you, but I do not like it at all. Let me change to the password I have already defined for </span><i><span style="font-weight: 400;">root</span></i><span style="font-weight: 400;"> in the source.&nbsp;</span></p>
  367. <p><span style="font-weight: 400;">Percona Everest is not (yet) allowing you to modify the system users’ passwords from the GUI, but you can do it from command line:</span></p>
  368. <pre class="lang:sh decode:true">DB_NAMESPACE=namespace';
  369. DB_NAME='cluster-name';
  370. USER='user';
  371. PASSWORD='new-password';
  372. kubectl patch secret everest-secrets-"$DB_NAME" -p="{"stringData":{"$USER": "$PASSWORD"}}" -n "$DB_NAMESPACE"
  373. </pre>
  374. <p><span style="font-weight: 400;">Before changing let us check what password we have also for the other system users.&nbsp;</span></p>
  375. <p><span style="font-weight: 400;">About system users in Operator for MySQL (PXC based) we have the following:</span></p>
  376. <ul>
  377. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">root</span></li>
  378. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">operator</span></li>
  379. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">xtrabackup</span></li>
  380. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">monitor</span></li>
  381. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">replication</span></li>
  382. </ul>
  383. <p><span style="font-weight: 400;">To get all of them use command line:</span></p>
  384. <pre class="lang:sh decode:true">DB_NAMESPACE='namespace'; DB_NAME='cluster-name'; kubectl get secret everest-secrets-"$DB_NAME" -n "$DB_NAMESPACE" -o go-template='{{range $k,$v := .data}}{{"### "}}{{$k}}{{"| pw: "}}{{$v|base64decode}}{{"nn"}}{{end}}'|grep -E 'operator|replication|monitor|root||xtrabackup'
  385. ### monitor| pw: $&amp;4fwdoYroBxFo#kQi
  386. ### operator| pw: NNfIUv+iL+J!,.Aqy94
  387. ### replication| pw: Rj89Ks)IVNQJH}Rd
  388. ### root| pw: f~A)Nws8wD&lt;~%.j[
  389. <span style="font-weight: 400;">### xtrabackup| pw: h)Tb@ij*0=(?,?30</span>
  390. </pre>
  391. <p><span style="font-weight: 400;">Now let me change my </span><i><span style="font-weight: 400;">root</span></i><span style="font-weight: 400;"> user password:</span></p>
  392. <pre class="lang:sh decode:true">$ DB_NAMESPACE='namespace'; DB_NAME='cluster-name'; USER='root'; PASSWORD='root_password'; kubectl patch secret everest-secrets-"$DB_NAME" -p="{"stringData":{"$USER": "$PASSWORD"}}" -n "$DB_NAMESPACE"</pre>
  393. <p><span style="font-weight: 400;">Now if I collapse and expand again (forcing a reload of the section):</span></p>
  394. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/09/everest9.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/how_to_migrate_toPeverest/everest9.jpg" alt="everest9" width="853" height="191" class="alignnone size-full wp-image-98256" /></a></p>
  395. <p><span style="font-weight: 400;">My </span><i><span style="font-weight: 400;">root</span></i><span style="font-weight: 400;"> user password is aligned with the one I pushed.&nbsp;</span></p>
  396. <p><span style="font-weight: 400;">As we have seen we have to decide what to do, so first thing is to check if our SOURCE has or not the users defined. If not, then it is easy we will just grab the users from the newly generated cluster and recreate them in the SOURCE.</span></p>
  397. <p><span style="font-weight: 400;">To do so we will query the source database:</span></p>
  398. <pre class="lang:sh decode:true">(root@localhost) [(none)]&gt;select user,host,plugin from mysql.user order by 1,2;
  399. +----------------------------+---------------+-----------------------+
  400. | user                       | host          | plugin                |
  401. +----------------------------+---------------+-----------------------+
  402. | app_test                   | %             | mysql_native_password |
  403. | dba                        | %             | mysql_native_password |
  404. | dba                        | 127.0.0.1     | mysql_native_password |
  405. | mysql.infoschema           | localhost     | caching_sha2_password |
  406. | mysql.pxc.internal.session | localhost     | caching_sha2_password |
  407. | mysql.pxc.sst.role         | localhost     | caching_sha2_password |
  408. | mysql.session              | localhost     | caching_sha2_password |
  409. | mysql.sys                  | localhost     | caching_sha2_password |
  410. | operator                   | %             | caching_sha2_password |
  411. | pmm                        | 127.0.0.1     | caching_sha2_password |
  412. | pmm                        | localhost     | caching_sha2_password |
  413. | replica                    | 3.120.188.222 | caching_sha2_password |
  414. | root                       | localhost     | caching_sha2_password |
  415. +----------------------------+---------------+-----------------------+
  416. </pre>
  417. <p><span style="font-weight: 400;">We are lucky and there is nothing really conflicting, so we can export and create the users inside the SOURCE. To do so you can use </span><a href="https://docs.percona.com/percona-toolkit/pt-show-grants.html"><span style="font-weight: 400;">pt-show-grants</span></a><span style="font-weight: 400;">:</span></p>
  418. <pre class="lang:sh decode:true">pt-show-grants --host cluster-end-point --port 3306 --user dba --password dba --only 'monitor'@'%','xtrabackup'@'%',operator@'%',replication@'%',root@'%</pre>
  419. <p><span style="font-weight: 400;">This will generate an SQL output that you can run on the source. Please review it before running to be sure it will be safe for you to run it.</span></p>
  420. <p><span style="font-weight: 400;">Once applied to source we will have:</span></p>
  421. <pre class="lang:sh decode:true">+----------------------------+---------------+-----------------------+
  422. | user                       | host          | plugin                |
  423. +----------------------------+---------------+-----------------------+
  424. | app_test                   | %             | mysql_native_password |
  425. | dba                        | %             | mysql_native_password |
  426. | dba                        | 127.0.0.1     | mysql_native_password |
  427. | monitor                    | %             | caching_sha2_password |
  428. | mysql.infoschema           | localhost     | caching_sha2_password |
  429. | mysql.pxc.internal.session | localhost     | caching_sha2_password |
  430. | mysql.pxc.sst.role         | localhost     | caching_sha2_password |
  431. | mysql.session              | localhost     | caching_sha2_password |
  432. | mysql.sys                  | localhost     | caching_sha2_password |
  433. | operator                   | %             | caching_sha2_password |
  434. | pmm                        | 127.0.0.1     | caching_sha2_password |
  435. | pmm                        | localhost     | caching_sha2_password |
  436. | replica                    | 3.120.188.222 | caching_sha2_password |
  437. | replication                | %             | caching_sha2_password |
  438. | root                       | %             | caching_sha2_password |
  439. | root                       | localhost     | caching_sha2_password |
  440. | xtrabackup                 | %             | caching_sha2_password |
  441. +----------------------------+---------------+-----------------------+
  442. </pre>
  443. <p><span style="font-weight: 400;">The last step to do about the users, is to create a specific user to use for the migration. We will use it to perform the clone and after that we will remove it.&nbsp;</span></p>
  444. <p><span style="font-weight: 400;">On SOURCE:</span></p>
  445. <pre class="lang:mysql decode:true">create user migration@'%' identified by 'migration_password';
  446.     grant backup_admin on *.* to migration@'%'
  447. </pre>
  448. <p><span style="font-weight: 400;">On RECEIVER (new cluster):</span></p>
  449. <pre class="lang:mysql decode:true">  create user migration@'%' identified by 'migration_password';
  450.     GRANT SYSTEM_USER, REPLICATION SLAVE, CONNECTION_ADMIN, BACKUP_ADMIN, GROUP_REPLICATION_STREAM, CLONE_ADMIN,SHUTDOWN ON *.* to migration@'%';
  451. </pre>
  452. <h2><span style="font-weight: 400;">Let us go CLONING&nbsp;</span></h2>
  453. <p><span style="font-weight: 400;">First, is the CLONE plugin already there?</span></p>
  454. <p><span style="font-weight: 400;">Discover this querying the two systems:</span></p>
  455. <pre class="lang:mysql decode:true">SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS  WHERE PLUGIN_NAME = 'clone';
  456. SOURCE:
  457. +-------------+---------------+
  458. | PLUGIN_NAME | PLUGIN_STATUS |
  459. +-------------+---------------+
  460. | clone       | ACTIVE        |
  461. +-------------+---------------+
  462. </pre>
  463. <pre class="lang:mysql decode:true">RECEIVER:
  464. mysql&gt; SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS  WHERE PLUGIN_NAME = 'clone';
  465. Empty set (0.42 sec)
  466. </pre>
  467. <p><span style="font-weight: 400;">RECEIVER doesn’t have the plugin active. Let us activate it:</span></p>
  468. <pre class="lang:mysql decode:true">INSTALL PLUGIN clone SONAME 'mysql_clone.so';</pre>
  469. <p><span style="font-weight: 400;">Warning! </span><span style="font-weight: 400;"><br /></span><span style="font-weight: 400;">If your source is behind a firewall, you need to allow the RECEIVER to connect, to get the IP of the RECEIVER just do:</span></p>
  470. <pre class="lang:sh decode:true">kubectl -n namespace exec mysqlpodname -c pxc -- curl -4s ifconfig.me</pre>
  471. <p><span style="font-weight: 400;">This will return an IP, you need to add that IP to the firewall and allow the access. Keep this value aside, you will also need later to setup the asynchronous replication.&nbsp;</span></p>
  472. <p>&nbsp;</p>
  473. <p><span style="font-weight: 400;">Are we ready? Not really, there is a caveat here. If we clone with the Galera library active, the cloning will fail.&nbsp;</span></p>
  474. <p><span style="font-weight: 400;">To have it working we must:</span></p>
  475. <ol>
  476. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">disable the wsrep provider</span></li>
  477. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">stop operator probes to monitor the pod</span></li>
  478. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">connect directly to the pod to run the operation and to monitor it.&nbsp;</span></li>
  479. </ol>
  480. <p><span style="font-weight: 400;">To do the above, on the receiver, we can:</span></p>
  481. <ol>
  482. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">add </span><i><span style="font-weight: 400;">wsrep_provider=none</span></i><span style="font-weight: 400;"> to the configuration</span></li>
  483. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">as soon as the pod is up (monitor the log) issue from command line the command:</span><span style="font-weight: 400;"><br /></span>
  484. <pre class="lang:sh decode:true">kubectl -n namespace exec pod-name -c pxc -- touch /var/lib/mysql/sleep-forever</pre>
  485. </li>
  486. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Connect to the pod using:</span><span style="font-weight: 400;"><br /></span>
  487. <pre class="lang:sh decode:true">kubectl exec --stdin --tty &lt;pod name&gt; -n &lt;namespace&gt; -c pxc -- /bin/bash</pre>
  488. </li>
  489. </ol>
  490. <p><span style="font-weight: 400;">During the time of the operations, the cluster will not be accessible from its end point and HAProxy pod will result down as well, all this is OK, don’t worry.</span></p>
  491. <h3><span style="font-weight: 400;">Let us go…</span></h3>
  492. <p><span style="font-weight: 400;">While monitoring the log and pod:</span></p>
  493. <pre class="lang:sh decode:true">kubectl logs pod-name --follow -c pxc
  494. kubectl get pods
  495. </pre>
  496. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/09/everest10-a.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/how_to_migrate_toPeverest/everest10-a.jpg" alt="everest10" width="1024" height="125" class="alignnone size-large wp-image-98258" /></a></p>
  497. <p><span style="font-weight: 400;">Once you click continue and then edit database, the pod will be restarted.</span></p>
  498. <p><span style="font-weight: 400;">Wait for the message in the log:</span></p>
  499. <pre class="lang:sh decode:true">[MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.36-28.1'&nbsp; socket: '/tmp/mysql.sock'&nbsp; port: 3306&nbsp; Percona XtraDB Cluster (GPL), Release rel28, Revision bfb687f, WSREP version 26.1.4.3.
  500. 2024-07-29T17:22:11.933714Z 0 [System] [MY-013292] [Server] Admin interface ready for connections, address: '10.1.68.172'&nbsp; port: 33062</pre>
  501. <p>As soon as you see it, run the command to prevent Operator to restart the pod:</p>
  502. <pre class="lang:sh decode:true">kubectl -n namespace exec pod-name -c pxc -- touch /var/lib/mysql/sleep-forever</pre>
  503. <p><span style="font-weight: 400;">Confirm file is there:</span><span style="font-weight: 400;"><br /></span></p>
  504. <pre class="lang:sh decode:true">kubectl -n namespace exec pod-name -c pxc -- ls -l /var/lib/mysql|grep sleep</pre>
  505. <p><span style="font-weight: 400;">Checking the status you will have:</span></p>
  506. <pre class="lang:sh decode:true">NAME                                              READY   STATUS    RESTARTS   AGE
  507. percona-xtradb-cluster-operator-fb4cf7f9d-97rfs   1/1     Running   0          13d
  508. test-prod1-haproxy-0                              2/3     Running   0          21h
  509. test-prod1-pxc-0                                  1/2     Running   0          46s
  510. </pre>
  511. <p><span style="font-weight: 400;">Now you can connect to your pod only locally:</span></p>
  512. <pre class="lang:sh decode:true">kubectl exec --stdin --tty &lt;pod name&gt; -n &lt;namespace&gt; -c pxc -- /bin/bash</pre>
  513. <p><span style="font-weight: 400;">Once there:</span></p>
  514. <pre class="lang:sh decode:true">mysql -uroot -p&lt;root_password&gt;</pre>
  515. <p><span style="font-weight: 400;">And you are in.</span></p>
  516. <p><span style="font-weight: 400;">I suggest you to open two different bash terminals and in one run the monitor query:</span></p>
  517. <pre class="lang:sh decode:true">while [ 1 == 1 ]; do mysql -uroot -p&lt;root_password&gt; -e "select id,stage,state,BEGIN_TIME,END_TIME,THREADS,((ESTIMATE/1024)/1024) ESTIMATE_MB,format(((data/estimate)*100),2) 'completed%', ((DATA/1024)/1024) DATA_MB,NETWORK,DATA_SPEED,NETWORK_SPEED from performance_schema.clone_progress;";sleep 1;done;</pre>
  518. <p><span style="font-weight: 400;">This command will give you a clear idea of the status of the cloning process.</span></p>
  519. <p><span style="font-weight: 400;">To clone from a SOURCE you need to tell the RECEIVER which source to trust.</span></p>
  520. <p><span style="font-weight: 400;">On the other bash, inside the mysql client:</span></p>
  521. <pre class="lang:mysql decode:true">SET GLOBAL clone_valid_donor_list = 'source_public_ip:port';
  522. CLONE INSTANCE FROM 'migration'@'ip':port IDENTIFIED BY 'XXX';</pre>
  523. <p>While cloning your monitor query will give you the status of the operation:</p>
  524. <pre class="lang:mysql decode:true">+------+-----------+-------------+----------------------------+----------------------------+---------+-----------------+------------+---------------+------------+------------+---------------+
  525. | id   | stage     | state       | BEGIN_TIME                 | END_TIME                   | THREADS | ESTIMATE_MB     | completed% | DATA_MB       | NETWORK    | DATA_SPEED | NETWORK_SPEED |
  526. +------+-----------+-------------+----------------------------+----------------------------+---------+-----------------+------------+---------------+------------+------------+---------------+
  527. |    1 | DROP DATA | Completed   | 2024-07-30 15:07:17.690966 | 2024-07-30 15:07:17.806309 |       1 |      0.00000000 | NULL       |    0.00000000 |          0 |          0 |             0 |
  528. |    1 | FILE COPY | In Progress | 2024-07-30 15:07:17.806384 | NULL                       |       4 | 130692.40951157 | 3.55       | 4642.11263657 | 4867879397 |  491961485 |     491987808 |
  529. |    1 | PAGE COPY | Not Started | NULL                       | NULL                       |       0 |      0.00000000 | NULL       |    0.00000000 |          0 |          0 |             0 |
  530. |    1 | REDO COPY | Not Started | NULL                       | NULL                       |       0 |      0.00000000 | NULL       |    0.00000000 |          0 |          0 |             0 |
  531. |    1 | FILE SYNC | Not Started | NULL                       | NULL                       |       0 |      0.00000000 | NULL       |    0.00000000 |          0 |          0 |             0 |
  532. |    1 | RESTART   | Not Started | NULL                       | NULL                       |       0 |      0.00000000 | NULL       |    0.00000000 |          0 |          0 |             0 |
  533. |    1 | RECOVERY  | Not Started | NULL                       | NULL                       |       0 |      0.00000000 | NULL       |    0.00000000 |          0 |          0 |             0 |
  534. +------+-----------+-------------+----------------------------+----------------------------+---------+-----------------+------------+---------------+------------+------------+---------------+
  535. </pre>
  536. <p><span style="font-weight: 400;">When the process is completed, the mysqld will shut down.</span></p>
  537. <p><span style="font-weight: 400;">Checking in the log you will see something like this:</span></p>
  538. <pre class="lang:sh decode:true">The /var/lib/mysql/sleep-forever file is detected, node is going to infinity loop
  539. <span style="font-weight: 400;">If you want to exit from infinity loop you need to remove /var/lib/mysql/sleep-forever file</span></pre>
  540. <p><span style="font-weight: 400;">Do not worry all is good!</span></p>
  541. <p><span style="font-weight: 400;">At this point we want to have MySQL start again and validate the current files:</span></p>
  542. <pre class="lang:sh decode:true">kubectl -n namespace exec podname -c pxc – mysqld &amp;</pre>
  543. <p><span style="font-weight: 400;">Check the log and if all is ok, connect to mysql using local client:</span></p>
  544. <pre class="lang:sh decode:true">kubectl exec --stdin --tty &lt;pod name&gt; -n &lt;namespace&gt; -c pxc -- /bin/bash
  545. mysql -uroot -p&lt;password&gt;</pre>
  546. <p>Issue <i>shutdown</i> command from inside.</p>
  547. <p><span style="font-weight: 400;">It is time to remove the </span><i><span style="font-weight: 400;">wsrep_provider=none</span></i><span style="font-weight: 400;"> and after the </span><i><span style="font-weight: 400;">sleep-forever</span></i><span style="font-weight: 400;"> file.</span></p>
  548. <p><span style="font-weight: 400;">Go to the Percona Everest GUI and remove from the Database Parameters </span><i><span style="font-weight: 400;">wsrep_provider=none</span></i><span style="font-weight: 400;"> click continue and then edit database.</span></p>
  549. <p><span style="font-weight: 400;">Final step, remove the file:</span></p>
  550. <pre class="lang:sh decode:true">kubectl -n namespace exec podname -c pxc -- rm -f /var/lib/mysql/sleep-forever</pre>
  551. <p><span style="font-weight: 400;">Cluster will come back (after few restarts) with the new dataset and pointed to the SOURCE GTID:</span></p>
  552. <pre class="lang:mysql decode:true">mysql&gt; select @@gtid_executed;
  553. +-----------------------------------------------+
  554. | @@gtid_executed                               |
  555. +-----------------------------------------------+
  556. | aeb22c03-7f13-11ee-9ff6-0224c88bdc4c:1-698687 |
  557. +-----------------------------------------------+
  558. </pre>
  559. <h2><span style="font-weight: 400;">Enable Replication</span></h2>
  560. <p><span style="font-weight: 400;">Now if you are used to Percona Operator for MySQL (PXC based) you probably know that it does support </span><a href="https://www.percona.com/blog/migration-of-a-mysql-database-to-a-kubernetes-cluster-using-asynchronous-replication/"><span style="font-weight: 400;">remote asynchronous replication</span></a><span style="font-weight: 400;">. This feature is available in the operator used by Everest but it is not exposed yet. </span><span style="font-weight: 400;"><br /></span><span style="font-weight: 400;">The benefit of using the “native” replication is that the replication will be managed by the operator in case of pod crash. This will allow the cluster to continue to replicate cross pods.&nbsp;</span></p>
  561. <p><span style="font-weight: 400;">On the other hand, the method described below, which for the moment (Percona Everest v1.0.1) is the only applicable, require manual intervention to start the replication in case of pod failure.&nbsp;</span></p>
  562. <p><span style="font-weight: 400;">Clarified that, here are the steps you need to follow to enable replication between the new environment and your current production.&nbsp;</span></p>
  563. <p><span style="font-weight: 400;">On source:</span></p>
  564. <pre class="lang:mysql decode:true">CREATE USER &lt;replicauser&gt;@'3.120.188.222' IDENTIFIED BY '&lt;replicapw&gt;';
  565. GRANT REPLICATION SLAVE ON *.* TO replica@'&lt;replica_external_ip&gt;';</pre>
  566. <p>The IP of <i>replica_external_ip</i> is the one I told you to keep aside, for convenience here the command to get it again:</p>
  567. <pre class="lang:sh decode:true">kubectl -n namespace exec podname -c pxc -- curl -4s ifconfig.me</pre>
  568. <p><span style="font-weight: 400;">On Receiver, connect to the pod using mysql client and type:</span></p>
  569. <pre class="lang:mysql decode:true">CHANGE REPLICATION SOURCE TO SOURCE_HOST='&lt;source&gt;', SOURCE_USER=&lt;replicauser&gt;, SOURCE_PORT=3306, SOURCE_PASSWORD='&lt;replicapw&gt;', SOURCE_AUTO_POSITION = 1</pre>
  570. <p><span style="font-weight: 400;">Then start replication as usual.</span></p>
  571. <p><span style="font-weight: 400;">If all was done right, you will have the Replication working and your new database is replicating from current production, keeping the two in sync.</span></p>
  572. <pre class="lang:mysql decode:true">mysql&gt; show replica statusG
  573. *************************** 1. row ***************************
  574.             Replica_IO_State: Waiting for source to send event
  575.                  Source_Host: 18.198.187.64
  576.                  Source_User: replica
  577.                  Source_Port: 3307
  578.                Connect_Retry: 60
  579.              Source_Log_File: binlog.000001
  580.          Read_Source_Log_Pos: 337467656
  581.               Relay_Log_File: test-prod1-pxc-0-relay-bin.000002
  582.                Relay_Log_Pos: 411
  583.        Relay_Source_Log_File: binlog.000001
  584.           Replica_IO_Running: Yes
  585.          Replica_SQL_Running: Yes
  586. … snip …
  587.            Executed_Gtid_Set: aeb22c03-7f13-11ee-9ff6-0224c88bdc4c:1-698687
  588.                Auto_Position: 1
  589.         Replicate_Rewrite_DB:
  590.                 Channel_Name:
  591.           Source_TLS_Version:
  592.       Source_public_key_path:
  593.        Get_Source_public_key: 0
  594.            Network_Namespace:
  595. </pre>
  596. <h2><span style="font-weight: 400;">Final touch</span></h2>
  597. <p><span style="font-weight: 400;">The final touch is to move the cluster from 1 node to 3 nodes.</span></p>
  598. <pre class="lang:sh decode:true">$ kubectl get pods
  599. NAME                                              READY   STATUS    RESTARTS      AGE
  600. percona-xtradb-cluster-operator-fb4cf7f9d-97rfs   1/1     Running   0             14d
  601. test-prod1-haproxy-0                              2/2     Running   6 (48m ago)   77m
  602. test-prod1-pxc-0                                  1/1     Running   0             45m
  603. </pre>
  604. <p><span style="font-weight: 400;">To do so, open the Percona Everest GUI, edit your database and in the </span><b>Resources</b><span style="font-weight: 400;"> tab, choose 3 nodes, then continue till the end and </span><b>edit database.</b><span style="font-weight: 400;"></span></p>
  605. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/09/everest11-a.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/how_to_migrate_toPeverest/everest11-a.jpg" alt="everest11 a" width="1024" height="416" class="alignnone size-large wp-image-98260" /></a></p>
  606. <p><span style="font-weight: 400;">At the end of the update process, you will have:</span></p>
  607. <pre class="lang:sh decode:true">$ kubectl get pods
  608. NAME                                              READY   STATUS    RESTARTS       AGE
  609. percona-xtradb-cluster-operator-fb4cf7f9d-97rfs   1/1     Running   0              14d
  610. test-prod1-haproxy-0                              2/2     Running   6 (151m ago)   3h1m
  611. test-prod1-haproxy-1                              2/2     Running   0              103m
  612. test-prod1-haproxy-2                              2/2     Running   0              102m
  613. test-prod1-pxc-0                                  1/1     Running   0              149m
  614. test-prod1-pxc-1                                  1/1     Running   0              103m
  615. test-prod1-pxc-2                                  1/1     Running   0              93m
  616. </pre>
  617. <p><span style="font-weight: 400;">At this point you have your new environment ready to go. </span></p>
  618. <h2><span style="font-weight: 400;">Post migration actions</span></h2>
  619. <p><span style="font-weight: 400;">Remember that there are always many other things to do once you have migrated the data:</span></p>
  620. <ul>
  621. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Validate Data Integrity</span>
  622. <ul>
  623. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Consistency Check: Use tools like mysqlcheck or Percona’s pt-table-checksum to ensure data integrity and consistency between MySQL 8.0 and Percona Everest.</span></li>
  624. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Query Testing: Run critical queries and perform load testing to ensure that performance metrics are met and that queries execute correctly.</span></li>
  625. </ul>
  626. </li>
  627. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Test and Optimize</span>
  628. <ul>
  629. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Benchmarking: Conduct performance benchmarking to compare MySQL 8.0 and Percona Everest. Use tools like sysbench or MySQL’s EXPLAIN statement to analyze query performance.</span></li>
  630. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Optimization: Tweak Percona Everest settings based on the benchmark results. Consider features like Percona’s Query Analytics and Performance Schema for deeper insights.</span></li>
  631. </ul>
  632. </li>
  633. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Enable Backup schedule and Point In time Recovery</span><span style="font-weight: 400;"><br /></span><a href="https://www.percona.com/blog/wp-content/uploads/2024/09/everest12-a.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/how_to_migrate_toPeverest/everest12-a.jpg" alt="everest12 a" width="1024" height="376" class="alignnone size-large wp-image-98262" /></a></li>
  634. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Switch to Production</span>
  635. <ul>
  636. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Cutover Plan: Develop a cutover plan that includes a maintenance window, final data synchronization, and the switchover to the new database.</span></li>
  637. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">ALWAYS perform a backup of the platform.</span></li>
  638. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Monitoring and Support: Set up monitoring with tools like Percona Monitoring and Management (PMM) to keep an eye on performance, queries, and server health.</span></li>
  639. </ul>
  640. </li>
  641. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Verification and Documentation:</span>
  642. <ul>
  643. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Data Validation: Conduct thorough testing to confirm that all application functionality works as expected with Percona Everest.</span></li>
  644. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Documentation: Update your database documentation to reflect the new setup, configurations, and any changes made during the migration.</span></li>
  645. </ul>
  646. </li>
  647. </ul>
  648. <h2><span style="font-weight: 400;">Summary of commands&nbsp;</span></h2>
  649. <table>
  650. <tbody>
  651. <tr>
  652. <td><span style="font-weight: 400;">Use</span></td>
  653. <td><span style="font-weight: 400;">Command</span></td>
  654. </tr>
  655. <tr>
  656. <td><span style="font-weight: 400;">Get cluster state</span></td>
  657. <td><span style="font-weight: 400;">kubectl get pxc</span></td>
  658. </tr>
  659. <tr>
  660. <td><span style="font-weight: 400;">Get list of the pods</span></td>
  661. <td><span style="font-weight: 400;">kubectl get pods</span></td>
  662. </tr>
  663. <tr>
  664. <td><span style="font-weight: 400;">Return password for system users</span></td>
  665. <td><span style="font-weight: 400;">DB_NAMESPACE='namespace'; DB_NAME='cluster-name'; kubectl get secret everest-secrets-"$DB_NAME" -n "$DB_NAMESPACE" -o go-template='{{range $k,$v := .data}}{{"### "}}{{$k}}{{"| pw: "}}{{$v|base64decode}}{{"nn"}}{{end}}'|grep -E 'operator|replication|monitor|root||xtrabackup'</span></td>
  666. </tr>
  667. <tr>
  668. <td><span style="font-weight: 400;">Change password for a given user</span></td>
  669. <td><span style="font-weight: 400;">DB_NAMESPACE='namespace'; DB_NAME='cluster-name'; USER='root'; PASSWORD='root_password'; kubectl patch secret everest-secrets-"$DB_NAME" -p="{"stringData":{"$USER": "$PASSWORD"}}" -n "$DB_NAMESPACE</span></td>
  670. </tr>
  671. <tr>
  672. <td><span style="font-weight: 400;">Show the pod log for a specific container Tail style</span></td>
  673. <td><span style="font-weight: 400;">kubectl logs pod-name --follow -c pxc</span></td>
  674. </tr>
  675. <tr>
  676. <td><span style="font-weight: 400;">Return public IP for that pod</span></td>
  677. <td><span style="font-weight: 400;">kubectl -n namespace exec podname -c pxc -- curl -4s ifconfig.me</span></td>
  678. </tr>
  679. <tr>
  680. <td><span style="font-weight: 400;">Prevent operator to restart the pod</span></td>
  681. <td><span style="font-weight: 400;">kubectl -n namespace exec pod-name -c pxc -- touch /var/lib/mysql/sleep-forever</span></td>
  682. </tr>
  683. <tr>
  684. <td><span style="font-weight: 400;">Remove the sleep-forever file</span></td>
  685. <td><span style="font-weight: 400;">kubectl -n namespace exec pod-name -c pxc – rm -f /var/lib/mysql/sleep-forever</span></td>
  686. </tr>
  687. <tr>
  688. <td><span style="font-weight: 400;">Connect to pod bash</span></td>
  689. <td><span style="font-weight: 400;">kubectl exec --stdin --tty &lt;pod name&gt; -n &lt;namespace&gt; -c pxc -- /bin/bash</span></td>
  690. </tr>
  691. <tr>
  692. <td>&nbsp;</td>
  693. <td>&nbsp;</td>
  694. </tr>
  695. </tbody>
  696. </table>
  697. <h1><span style="font-weight: 400;">References</span></h1>
  698. <p><a href="https://www.percona.com/blog/understanding-what-kubernetes-is-used-for-the-key-to-cloud-native-efficiency/"><span style="font-weight: 400;">https://www.percona.com/blog/understanding-what-kubernetes-is-used-for-the-key-to-cloud-native-efficiency/</span></a></p>
  699. <p><a href="https://www.percona.com/blog/should-you-deploy-your-databases-on-kubernetes-and-what-makes-statefulset-worthwhile/"><span style="font-weight: 400;">https://www.percona.com/blog/should-you-deploy-your-databases-on-kubernetes-and-what-makes-statefulset-worthwhile/</span></a></p>
  700. <p><a href="https://www.tusacentral.com/joomla/index.php/mysql-blogs/242-compare-percona-distribution-for-mysql-operator-vs-aws-aurora-and-standard-rds"><span style="font-weight: 400;">https://www.tusacentral.com/joomla/index.php/mysql-blogs/242-compare-percona-distribution-for-mysql-operator-vs-aws-aurora-and-standard-rds</span></a></p>
  701. <p><a href="https://www.tusacentral.com/joomla/index.php/mysql-blogs/243-mysql-on-kubernetes-demystified"><span style="font-weight: 400;">https://www.tusacentral.com/joomla/index.php/mysql-blogs/243-mysql-on-kubernetes-demystified</span></a></p>
  702. <p><a href="https://github.com/Tusamarco/mysqloperatorcalculator"><span style="font-weight: 400;">https://github.com/Tusamarco/mysqloperatorcalculator</span></a></p>
  703. <p><a href="https://www.percona.com/blog/migration-of-a-mysql-database-to-a-kubernetes-cluster-using-asynchronous-replication/"><span style="font-weight: 400;">https://www.percona.com/blog/migration-of-a-mysql-database-to-a-kubernetes-cluster-using-asynchronous-replication/</span></a></p>
  704. <p>&nbsp;</p>]]></description>
  705. <category>MySQL</category>
  706. <pubDate>Mon, 02 Sep 2024 13:47:01 +0000</pubDate>
  707. </item>
  708. <item>
  709. <title>Sakila, Where Are You Going?</title>
  710. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/256-sakila-where-are-you-going</link>
  711. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/256-sakila-where-are-you-going</guid>
  712. <description><![CDATA[<p>This article is in large part the same of what I have published in the <a href="https://www.percona.com/blog/sakila-where-are-you-going/">Percona blog</a>. However I am reproposing it here given it is the first some other benchmarking exercise that I am probably going to present here in an extended format, while it may be more concise in other platforms.&nbsp;</p>
  713. <p>In any case why this tests.&nbsp;</p>
  714. <p>I am curious, and I do not like (at all) what is happening around MySQL and MariaDB, never like it, but now is really think is time to end this negative trend, that is killing not only the community, but the products as well.&nbsp;</p>
  715. <h2>The tests</h2>
  716. <h3>Assumptions</h3>
  717. <p><span style="font-weight: 400;">There are many ways to run tests, and we know that results may vary depending on how you play with many factors, like the environment or the MySQL server settings. However, if we compare several versions of the same product on the same platform, it is logical to assume that all the versions will have the same “chance” to behave well or badly unless we change the MySQL server settings.&nbsp;</span></p>
  718. <p><span style="font-weight: 400;">Because of this, I ran the tests ON DEFAULTS, with the clear assumption that if you release your product based on the defaults, that implies you had tested with them and consider them the safest for generic use.&nbsp;</span></p>
  719. <p><span style="font-weight: 400;">I also applied some </span><a href="https://github.com/Tusamarco/blogs/blob/master/sakila_where_are_you_going/config_changes.txt"><span style="font-weight: 400;">modifications </span></a><span style="font-weight: 400;">and ran the tests again to see how optimization would impact performance.&nbsp;</span></p>
  720. <h3><span style="font-weight: 400;">What tests do we run?</span></h3>
  721. <p><span style="font-weight: 400;">High level, we run two sets of tests:</span></p>
  722. <ul>
  723. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Sysbench</span></li>
  724. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">TPC-C (<a href="https://www.tpc.org/tpcc/" rel="nofollow">https://www.tpc.org/tpcc/</a>) like&nbsp;</span></li>
  725. </ul>
  726. <p><span style="font-weight: 400;">The full methodology and test details can be found <a href="https://github.com/Tusamarco/benchmarktools/blob/main/docs/plan.md" rel="nofollow">here</a></span><span style="font-weight: 400;">, while actual commands are available:</span></p>
  727. <ul>
  728. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;"><a href="https://github.com/Tusamarco/benchmarktools/blob/main/software/fill_sysbench_map.sh" rel="nofollow">Sysbench</a></span></li>
  729. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;"><a href="https://github.com/Tusamarco/benchmarktools/blob/main/software/fill_tpcc_map.sh" rel="nofollow">TPC-C</a>&nbsp;</span></li>
  730. </ul>
  731. <h2><span style="font-weight: 400;">Results</span></h2>
  732. <p><span style="font-weight: 400;">While I have executed the whole set of tests as indicated on the page, </span><span style="font-weight: 400;">and all the results are visible </span><a href="https://github.com/Tusamarco/blogs/tree/master/sakila_where_are_you_going"><span style="font-weight: 400;">here</span></a><span style="font-weight: 400;">, for brevity and because I want to keep this article at a high level, I will report and cover only the Read-Write tests and the TPC-C.&nbsp;</span></p>
  733. <p><span style="font-weight: 400;">This is because, in my opinion, they offer an immediate and global view of how the server behaves. They also represent the most used scenario, while the other tests are more interesting to dig into problems.&nbsp;&nbsp;&nbsp;</span></p>
  734. <p><span style="font-weight: 400;">The sysbench read/write tests reported below have a lower percentage of writes ~36% and ~64% reads, where reads are point selects and range selects. TPC-C instead has an even distribution of 50/50 % between read and write operations.&nbsp;</span></p>
  735. <h3><span style="font-weight: 400;">Sysbench read and write tests&nbsp;</span></h3>
  736. <p><span style="font-weight: 400;">Test using default configurations only MySQL in different versions.&nbsp;</span></p>
  737. <p><span style="font-weight: 400;">Small dataset:</span></p>
  738. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/mysql_trend_default_rw_small.png"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/mysql_trend_default_rw_small.jpg" alt="mysql trend default rw small" width="800" height="333" class="aligncenter wp-image-96835 size-large" /></a></p>
  739. <p><span style="font-weight: 400;">Optimized configuration only MySQL:</span></p>
  740. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/mysql_trend_optimized_rw_small_100_range.png"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/mysql_trend_optimized_rw_small_100_range.jpg" alt="mysql trend optimized rw small 100 range" width="800" height="333" class="aligncenter wp-image-96839 size-large" /></a></p>
  741. <p><span style="font-weight: 400;">Large dataset using defaults:</span></p>
  742. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/mysql_trend_default_rw_large_100_range.png"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/mysql_trend_default_rw_large_100_range.jpg" alt="mysql trend default rw large 100 range" width="800" height="333" class="aligncenter wp-image-96833 size-large" /></a></p>
  743. <p><span style="font-weight: 400;">Using optimization:</span></p>
  744. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/mysql_trend_optimized_rw_large_100_range.png"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/mysql_trend_optimized_rw_large_100_range.jpg" alt="mysql trend optimized rw large 100 range" width="800" height="333" class="aligncenter wp-image-96837 size-large" /></a></p>
  745. <p><span style="font-weight: 400;">The first two graphs are interesting for several reasons, but one that jumps out is that we cannot count on DEFAULTS as a starting point. Or, to be correct, we can use them as the base from which we must identify better defaults; this is also corroborated by Oracle's recent decision to modify many defaults in 8.4 (<a href="https://lefred.be/content/mysql-8-4-lts-new-production-ready-defaults-for-innodb/" rel="nofollow">see article</a>).&nbsp;</span></p>
  746. <p><span style="font-weight: 400;">Given that I will focus on the results obtained with the optimized configs.</span></p>
  747. <p><span style="font-weight: 400;">Now looking at the graphs above, we can see that:</span></p>
  748. <ol>
  749. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">MySQL 5.7 is performing better in both cases just using defaults.</span></li>
  750. <li style="font-weight: 400;" aria-level="1">Given bad defaults, MySQL 8.036 was not performing well in the first case; just making some adjustments allowed it to over-perform 8.4 and be closer to what 5.7 can do.</li>
  751. </ol>
  752. <h3><span style="font-weight: 400;">TPC-C tests</span></h3>
  753. <p>As indicated, TPC-C tests are supposed to be write-intensive, using transactions and more complex queries with join, grouping, and sorting.</p>
  754. <p>I was testing the TPC-C using the most common isolation modes, Repeatable Reads, and Read Committed.</p>
  755. <p><span style="font-weight: 400;">While we experienced several issues during the multiple runs, those were not consistent, mainly due to locking timeouts. Given that, while I am representing the issue presence with a blank in the graph, they are not to be considered to impact the execution trend but only represent a saturation limit.&nbsp;</span></p>
  756. <p><span style="font-weight: 400;">Test using optimized configurations:</span></p>
  757. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/tpcc-RepeatableRead-with-optimized_only_mysql.png"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/tpcc_RepeatableRead_with_defaults_only_mysql.jpg" alt="tpcc RepeatableRead with defaults only mysql" width="800" height="333" class="aligncenter wp-image-96870 size-large" /></a></p>
  758. <p><span style="font-weight: 400;">Test using optimized configurations:</span></p>
  759. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/tpcc-ReadCommitted-with-optimized_only_mysql.png"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/tpcc_ReadCommitted_with_optimized_only_mysql.jpg" alt="tpcc ReadCommitted with optimized only mysql" width="800" height="333" class="aligncenter wp-image-96866 size-large" /></a></p>
  760. <p><span style="font-weight: 400;">In this test we can observe that MySQL 5.7 is better performing in comparison with the other MySQL versions.&nbsp;&nbsp;</span></p>
  761. <h3>What if we compare it with Percona Server for MySQL and MariaDB?</h3>
  762. <p><span style="font-weight: 400;">I will present only the optimized tests here for brevity because, as I saw before, we know defaults are not serving us well.&nbsp;</span></p>
  763. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/mysql_versions_compare_optimized_rw_small_100_range.png"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/mysql_versions_compare_optimized_rw_small_100_range.jpg" alt="mysql versions compare optimized rw small 100 range" width="800" height="333" class="aligncenter wp-image-96848 size-large" /></a></p>
  764. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/mysql_versions_compare_optimized_rw_large_100_range.png"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/mysql_versions_compare_optimized_rw_large_100_range.jpg" alt="mysql versions compare optimized rw large 100 range" width="800" height="333" class="aligncenter wp-image-96846 size-large" /></a></p>
  765. <p><span style="font-weight: 400;">When comparing the MYSQL versions against Percona Server for MySQL 8.0.36 and MariaDB 11.3, we see how MySQL 8.4 is doing better only in relation to MariaDB; after that, it remains behind also compared to MySQL 8.0.36.&nbsp;</span></p>
  766. <h4><i><span style="font-weight: 400;">TPC-C</span></i></h4>
  767. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/tpcc-RepeatableRead-optimized_all.png"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/tpcc_RepeatableRead_optimized_all.jpg" alt="tpcc RepeatableRead optimized all" width="800" height="333" class="aligncenter wp-image-96867 size-large" /></a></p>
  768. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/tpcc-ReadCommitted-optimized_all.png"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/tpcc_ReadCommitted_optimized_all.jpg" alt="tpcc ReadCommitted optimized all" width="800" height="333" class="aligncenter wp-image-96854 size-large" /></a></p>
  769. <p><span style="font-weight: 400;">As expected, MySQL 8.4 is not acting well here either, and only MariaDB is performing worse. </span><span style="font-weight: 400;">Note how Percona Server for MySQL 8.0.36 is the only one able to handle the increased contention.&nbsp;</span></p>
  770. <h2><span style="font-weight: 400;">What are these tests saying to us?</span></h2>
  771. <p><span style="font-weight: 400;">Frankly speaking, what we get here is what most of our users get as well, but on their own skin. MySQL performances are degrading with the increase of versions.&nbsp;</span></p>
  772. <p><span style="font-weight: 400;">For sure, MySQL 8.x comes with interesting additions; however, if you consider performance as the first and most important topic, then MySQL 8.x is not any better.&nbsp;</span></p>
  773. <p><span style="font-weight: 400;">Having said this, we must say that probably most of the ones still using MySQL 5.7 (and we have thousands of them) are right. Why embark on a very risky migration and then discover that you have lost a considerable percentage in performance?&nbsp;&nbsp;</span></p>
  774. <p><span style="font-weight: 400;">Regarding this, if we analyze the data and convert the trends into transactions/sec, we can identify the following scenarios if we compare the tests done using TPC:</span></p>
  775. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/tpcc_trx_lost_rr.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/tpcc_trx_pct_lost_rr.jpg" alt="tpcc trx lost rr" width="800" height="581" class="aligncenter wp-image-96871 size-large" /></a></p>
  776. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/tpcc_trx_lost_rc.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/tpcc_trx_lost_pct_rc.jpg" alt="tpcc trx lost pct rc" width="800" height="549" class="aligncenter wp-image-96872 size-large" /></a></p>
  777. <p><span style="font-weight: 400;">As we can see, the performance degradation can be significant in both tests, while the benefits (when present) are irrelevant.&nbsp;</span></p>
  778. <p><span style="font-weight: 400;">In absolute numbers:</span></p>
  779. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/tpcc_trx_lost_rr-1.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/tpcc_trx_lost_rr.jpg" alt="tpcc trx lost rr" width="800" height="581" class="aligncenter wp-image-96874 size-large" /></a></p>
  780. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/tpcc_trx_lost_rc-1.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/tpcc_trx_lost_rc.jpg" alt="tpcc trx lost rc" width="800" height="549" class="aligncenter wp-image-96873 size-large" /></a></p>
  781. <p><span style="font-weight: 400;"><br /></span>In this scenario, we need to ask ourselves, can my business deal with such a performance drop?</p>
  782. <h3>Considerations</h3>
  783. <p><span style="font-weight: 400;">When MySQL was sold to SUN Microsystems, I was in MySQL AB. I was not happy about that move at all, and when Oracle took over SUN, I was really concerned about Oracle's possible decision to kill MySQL. I also decided to move on and join another company.&nbsp;</span></p>
  784. <p><span style="font-weight: 400;">In the years after, I changed my mind, and I was supporting and promoting the Oracle/MySQL work. In many ways, I still am.&nbsp;</span></p>
  785. <p><span style="font-weight: 400;">They did a great job rationalizing the development, and the code clean-up was significant. However, something did not progress with the rest of the code. The performance decrease we are seeing is the cost of this lack of progress; see also Peter's article <a href="https://www.percona.com/blog/is-oracle-finally-killing-mysql/">Is Oracle Finally Killing MySQL?.</a></span><span style="font-weight: 400;"></span></p>
  786. <p><span style="font-weight: 400;">On the other hand, we need to recognize that Oracle is investing a lot in performance and functionalities when we talk of the OCI/MySQL/Heatwave offer. Only those improvements are not reflected in the MySQL code, no matter if it is Community or Enterprise.&nbsp;</span></p>
  787. <p><span style="font-weight: 400;">Once more, while I consider this extremely sad, I can also understand why.&nbsp;</span></p>
  788. <p><span style="font-weight: 400;">Why should Oracle continue to optimize the MySQL code for free when cloud providers such as Google or AWS use that code, optimize it for their use, make billions, and not even share the code back?&nbsp;</span></p>
  789. <p><span style="font-weight: 400;">We know this has been happening for many years now, and we know this is causing a significant and negative impact on the open source ecosystem.&nbsp;</span></p>
  790. <p><span style="font-weight: 400;">MySQL is just another Lego block in a larger scenario in which cloud companies are cannibalizing the work of others for their own economic return.&nbsp;</span></p>
  791. <p><span style="font-weight: 400;">What can be done? I can only hope we will see a different behavior soon. Opening the code and investing in projects that will help communities such as MySQL to quickly recover the lost ground.&nbsp;</span></p>
  792. <p>Let me add that while is perfectly normal in our economy to look for profit, at the end this is what capitalism is for, it is not normal, or for better say it is negative, to look for profit without keeping in mind you are burning out the resources. that gives you that profit.&nbsp;</p>
  793. <p>This last is consumerism, using and abusing, without keeping in mind you MUST give the resources you use the time/energy/opportunity to renew and florish is stupid, short sight and suicidal.</p>
  794. <p>Perfectly in line with our times isen't it?&nbsp; &nbsp;</p>
  795. <p>So let say that many big names in the cloud, should seriously rethink what they are doing, not because they need to be nice. But because they will get better outcome and income helping the many opensource community instead as they are doing today, abusing them.&nbsp;</p>
  796. <p><span style="font-weight: 400;">In the meantime, we must acknowledge that many customers/users are on 5.7 for a good reason and that until we are able to fix that, they may decide not to migrate forever or, if they must, to migrate to something else, such as Postgres.&nbsp;</span></p>
  797. <p>Then Sakila will slowly and painfully die as usual for the greed of the human being, nothing new in a way, yes, but not good.</p>
  798. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/06/dolphin_heatwave3.jpeg"><img src="http://www.tusacentral.net/joomla/images/stories/sakila_where_are_you_going/dolphin_heatwave3.jpeg" alt="dolphin heatwave3" width="600" height="600" class="aligncenter wp-image-96858 size-medium" style="display: block; margin-left: auto; margin-right: auto;" /></a></p>
  799. <p><span style="font-weight: 400;">Happy MySQL to all.&nbsp;&nbsp;</span></p>
  800. <p>&nbsp;</p>]]></description>
  801. <category>MySQL</category>
  802. <pubDate>Tue, 18 Jun 2024 13:22:55 +0000</pubDate>
  803. </item>
  804. <item>
  805. <title>Is MySQL Router 8.2 Any Better?</title>
  806. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/255-is-mysql-router-8-2-any-better</link>
  807. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/255-is-mysql-router-8-2-any-better</guid>
  808. <description><![CDATA[<p>In my previous article, <a href="https://www.percona.com/blog/comparisons-of-proxies-for-mysql/">Comparisons of Proxies for MySQL</a>, I showed how MySQL Router was the lesser performing Proxy in the comparison. From that time to now, we had several MySQL releases and, of course, also some new MySQL Router ones.</p>
  809. <p>Most importantly, we also had MySQL Router going back to being a level 7 proxy capable of redirecting traffic in case of R/W operations (<a href="https://dev.mysql.com/doc/mysql-router/8.2/en/router-read-write-splitting.html" rel="nofollow">see this</a>).</p>
  810. <p>All these bring me hope that we will also have some good improvements in what is a basic functionality in a router: routing.</p>
  811. <p>So with these great expectations, I had to repeat the exact same tests I did in my previous tests, plus I tested for MySQL Router only the cost of encapsulating the select inside a transaction.</p>
  812. <p>Just keep in mind that for all the tests, MySQL Router was configured to use the read/write split option.</p>
  813. <h2>The results</h2>
  814. <p><span style="font-weight: 400;">Given this is the continuation of the previous blog, all the explanations about the tests and commands used are in the <a href="https://www.percona.com/blog/comparisons-of-proxies-for-mysql/">first article</a>. If you did not read that, do it now, or it will be difficult for you to follow what is explained later.</span></p>
  815. <p><span style="font-weight: 400;">As indicated, I was looking to identify when the first proxy would reach a dimension that would not be manageable. The load is all in creating and serving the connections, while the number of operations is capped at 100.</span></p>
  816. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/01/events_rate_82.png"><img src="https://www.percona.com/blog/wp-content/uploads/2024/01/events_rate_82-1024x608.png" alt="" width="600" height="356" class="aligncenter wp-image-93339 size-large" /></a></p>
  817. <p><span style="font-weight: 400;">As you can see, MySQL Router was reaching the saturation level and was unable to serve traffic at exactly the same time as the previous test.</span></p>
  818. <h2>Test two</h2>
  819. <p><i><span style="font-weight: 400;">When the going gets tough, the tough get going </span></i><span style="font-weight: 400;">reprise ;)&nbsp;</span></p>
  820. <p><span style="font-weight: 400;">Let’s remove the –rate limitation and see what will happen. </span><span style="font-weight: 400;">First, let us compare MySQL router versions only:</span></p>
  821. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/01/router_82_80_comparison_events.png"><img src="http://www.tusacentral.net/joomla/images/stories/ismysqlrouter82better/router_82_80_comparison_events.png" alt="router 82 80 comparison events" width="600" height="376" class="size-large wp-image-93348 aligncenter" /></a></p>
  822. <p><span style="font-weight: 400;">As we can see the MySQL Router version 8.2 is doing better up to 64 concurrent threads.</span></p>
  823. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/01/router_82_80_comparison_latency.png"><img src="https://www.percona.com/blog/wp-content/uploads/2024/01/router_82_80_comparison_latency-1024x680.png" alt="" width="600" height="398" class="size-large wp-image-93349 aligncenter" /></a></p>
  824. <p><span style="font-weight: 400;">Latency follows the same trend in old and new cases, and we can see that the new version is acting better, up to 1024 threads.</span></p>
  825. <p><span style="font-weight: 400;">Is this enough to cover the gap with the other proxies? Which, in the end, is what we would like to see.&nbsp;</span></p>
  826. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/01/events_norate_82.png"><img src="http://www.tusacentral.net/joomla/images/stories/ismysqlrouter82better/events_norate_82.png" alt="events norate 82" width="600" height="326" class="size-large wp-image-93337 aligncenter" /></a></p>
  827. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/01/latency_norate_82.png"><img src="http://www.tusacentral.net/joomla/images/stories/ismysqlrouter82better/latency_norate_82.png" alt="latency norate 82" width="600" height="364" class="size-large wp-image-93342 aligncenter" /></a></p>
  828. <p><span style="font-weight: 400;">Well, I would say not really; we see a bit of better performance with low concurrent threads, but still not scaling and definitely lower than the other two.</span></p>
  829. <p><span style="font-weight: 400;">Now let us take a look at the CPU saturation:</span></p>
  830. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/01/cpu_saturation.png"><img src="http://www.tusacentral.net/joomla/images/stories/ismysqlrouter82better/cpu_saturation.png" alt="cpu saturation" width="600" height="300" class="size-full wp-image-93334 aligncenter" /></a></p>
  831. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/01/cpu.png"><img src="http://www.tusacentral.net/joomla/images/stories/ismysqlrouter82better/cpu.png" alt="cpu" width="600" height="300" class="size-full wp-image-93335 aligncenter" /></a></p>
  832. <p>Here, we can see how MySQL Router hits the top as soon as the rate option is lifted and gets worse with the increase of the running threads.</p>
  833. <h2>Test three</h2>
  834. <p><span style="font-weight: 400;">This simple test was meant to identify the cost of a transaction, or better, what it will cost to include selects inside a transaction.</span></p>
  835. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/01/read_events_trx.png"><img src="http://www.tusacentral.net/joomla/images/stories/ismysqlrouter82better/read_events_trx.png" alt="read events trx" width="600" height="356" class="size-large wp-image-93344 aligncenter" /></a></p>
  836. <p><a href="https://www.percona.com/blog/wp-content/uploads/2024/01/latency_events_trx.png"><img src="http://www.tusacentral.net/joomla/images/stories/ismysqlrouter82better/latency_events_trx.png" alt="latency events trx" width="600" height="371" class="size-large wp-image-93340 aligncenter" /></a></p>
  837. <p><span style="font-weight: 400;">As we can clearly see, MySQL Router, when handling selects inside a transaction, will drop its performance drastically going back to version 8.0 performance.</span></p>
  838. <h3>Conclusions</h3>
  839. <p>To the initial question — Is MySQL Router 8.2 any better? — we can answer a small (very small) yes.</p>
  840. <p>However, it is still far, far away from being competitive with ProxySQL (same proxy level) or with HAProxy. The fact it is not able to serve efficiently the requests also inside the lower set of concurrent threads, is disappointing.</p>
  841. <p>Even more disappointing because MySQL Router is presented as a critical component in the MySQL InnoDB Cluster solution. How can we use it in the architectures if the product has such limitations?</p>
  842. <p>I know that Oracle suggests to scale out, and I agree with them. When in need to scale with MySQL Router, the only option is to build a forest. However, we must keep in mind that each MySQL Router connects and queries the data nodes constantly and intensively. Given that it requires adding a forest of router nodes to scale, it is not without performance impact, given the increasing noise generated on the data nodes.</p>
  843. <p>Anyhow also, if there is a theoretical option to scale, that is not a good reason to use a poor performing component.</p>
  844. <p>I would prefer to use ProxySQL with Group Replication and add whatever script is needed in mysqlshell to manage it as Oracle is doing for the MySQL InnoDB cluster solution.</p>
  845. <p>What also left me very unhappy is that MySQL InnoDB Cluster is one of the important components of the OCI offer for MySQL. Is Oracle using MySQL Router there as well? I assume so. Can we trust it? I am not feeling like I can.</p>
  846. <p>Finally, what has been done for MySQL Router so far leads me to think that there is no real interest in making it the more robust and performing product that MySQL InnoDB Cluster deserves.</p>
  847. <p>I hope I am wrong and that we will soon see a fully refactored version of MySQL Router. I really hope Oracle will prove me wrong.</p>
  848. <p>Great MySQL to everyone.</p>]]></description>
  849. <category>MySQL</category>
  850. <pubDate>Wed, 10 Jan 2024 18:05:47 +0000</pubDate>
  851. </item>
  852. <item>
  853. <title>Export and import of MySQL passwords using caching_sha2 </title>
  854. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/254-export-and-import-of-mysql-passwords-using-caching-sha2</link>
  855. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/254-export-and-import-of-mysql-passwords-using-caching-sha2</guid>
  856. <description><![CDATA[<p><em><span style="font-weight: 400;">Some fun is coming <a href="https://www.percona.com/blog/wp-content/uploads/2023/09/user-migration.jpg"><img src="https://www.percona.com/blog/wp-content/uploads/2023/09/user-migration-300x136.jpg" alt="" width="380" height="172" class="wp-image-91109 alignright" style="float: right;" /></a></span></em></p>
  857. <p><span style="font-weight: 400;">While I was writing the internal guidelines on how to migrate from MariaDB to Percona Server, I had to export the users accounts in a portable way. This given MariaDB uses&nbsp; some non standard syntax brings me to first test some external tools such as Fred </span><a href="https://github.com/lefred/mysqlshell-plugins/wiki/user#getusersgrants"><span style="font-weight: 400;">https://github.com/lefred/mysqlshell-plugins/wiki/user#getusersgrants</span></a><span style="font-weight: 400;"> and our <a href="https://github.com/percona/percona-toolkit/blob/3.x/bin/pt-show-grants" rel="nofollow">PT-SHOW-GRANTS</a> tool.&nbsp;</span></p>
  858. <p><span style="font-weight: 400;">Useless to say this had open a can worms, given first I had to fix/convert the specifics for MariaDB (not in the scope of this blog), then while testing I discover another nasty issue, that currently prevent us to easily export the new Passwords in MySQL 8 (and PS 8) when caching_sha2 is used.&nbsp;</span></p>
  859. <p>&nbsp;</p>
  860. <p><span style="font-weight: 400;">So what is the problem I am referring to?</span></p>
  861. <p><span style="font-weight: 400;">Well the point is that when you generate passwords with caching_sha2 (default in mysql 8) the password generated can (will) contain characters that are not portable, not even between mysql 8.&nbsp;</span></p>
  862. <p><span style="font-weight: 400;">Let's see a practical example to understand.</span></p>
  863. <p><span style="font-weight: 400;">If I use old </span><i><span style="font-weight: 400;">mysql_native_password</span></i><span style="font-weight: 400;"> and I create a user such as:</span><span style="font-weight: 400;"><br /></span></p>
  864. <pre class="lang:mysql decode:true">create user dba@'192.168.1.%' identified with mysql_native_password by 'dba';
  865. </pre>
  866. <p><span style="font-weight: 400;">My authentication_string will be:&nbsp;</span></p>
  867. <pre class="lang:mysql decode:true">root@localhost) [(none)]&gt;select user,host,authentication_string,plugin from mysql.user where user ='dba' order by 1,2;
  868. +------+-------------+-------------------------------------------+-----------------------+
  869. | user | host        | authentication_string                     | plugin                |
  870. +------+-------------+-------------------------------------------+-----------------------+
  871. | dba  | 192.168.1.% | *381AD08BBFA647B14C82AC1094A29AD4D7E4F51D | mysql_native_password |
  872. +------+-------------+-------------------------------------------+-----------------------+
  873. </pre>
  874. <p><span style="font-weight: 400;">At this point if you want to export the user:</span></p>
  875. <pre class="lang:mysql decode:true">(root@localhost) [(none)]&gt;show create user dba@'192.168.1.%'G
  876. *************************** 1. row ***************************
  877. CREATE USER for dba@192.168.1.%: CREATE USER `dba`@`192.168.1.%` IDENTIFIED WITH 'mysql_native_password' AS '*381AD08BBFA647B14C82AC1094A29AD4D7E4F51D' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT PASSWORD REQUIRE CURRENT DEFAULT
  878. 1 row in set (0.01 sec)
  879. </pre>
  880. <p><span style="font-weight: 400;">You just need to use the text after the semicolon and all will work fine. Remember that when you want to preserve the already converted password you need to use the </span><i><span style="font-weight: 400;">IDENTIFIED … AS &lt;PW&gt;</span></i><span style="font-weight: 400;"> not the </span><b>BY</b><span style="font-weight: 400;"> or you will re-convert the password ;).</span></p>
  881. <p><span style="font-weight: 400;">&nbsp;Anyhow .. this is simple and what we are all used to.&nbsp;</span></p>
  882. <p><span style="font-weight: 400;">Now if you instead try to use caching_sha2 things will go differently:</span></p>
  883. <pre class="lang:mysql decode:true">root@localhost) [(none)]&gt;create user dba@'192.168.4.%' identified with caching_sha2_password by 'dba';
  884. Query OK, 0 rows affected (0.02 sec)
  885.  
  886. (root@localhost) [(none)]&gt;select user,host,authentication_string,plugin from mysql.user where user ='dba' order by 1,2;
  887. +------+-------------+------------------------------------------------------------------------+-----------------------+
  888. | user | host        | authentication_string                                                  | plugin                |
  889. +------+-------------+------------------------------------------------------------------------+-----------------------+
  890. | dba  | 192.168.1.% | *381AD08BBFA647B14C82AC1094A29AD4D7E4F51D                              | mysql_native_password |
  891. | dba  | 192.168.4.% | $A$005$@&amp;%1H5iNQx|.l{N7T/GosA.Lp4EiO0bxLVQp8Zi0WY2nXLr8TkleQPYjaqVxI7 | caching_sha2_password |
  892. +------+-------------+------------------------------------------------------------------------+-----------------------+
  893. 2 rows in set (0.00 sec)
  894. </pre>
  895. <p><span style="font-weight: 400;">Probably you will not see it here given that while converted on your screen the special characters will be replaced, but the password contains invalid characters.&nbsp;</span></p>
  896. <p><span style="font-weight: 400;">If I try to extract the </span><i><span style="font-weight: 400;">Create USER</span></i><span style="font-weight: 400;"> text I will get:</span></p>
  897. <pre class="lang:mysql decode:true"> (root@localhost) [(none)]&gt;show create user dba@'192.168.4.%'G
  898. *************************** 1. row ***************************
  899. CREATE USER for dba@192.168.4.%: CREATE USER `dba`@`192.168.4.%` IDENTIFIED WITH 'caching_sha2_password' AS '$A$005$@&amp;%1H5iNQx|.l{N7T/GosA.Lp4EiO0bxLVQp8Zi0WY2nXLr8TkleQPYjaqVxI7' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT PASSWORD REQUIRE CURRENT DEFAULT
  900. 1 row in set (0.00 sec)</pre>
  901. <p><span style="font-weight: 400;">However if I try to use this text to generate the user after I drop it:</span><span style="font-weight: 400;"><br /></span></p>
  902. <pre class="lang:mysql decode:true">(root@localhost) [(none)]&gt;drop user dba@'192.168.4.%';
  903. Query OK, 0 rows affected (0.02 sec)
  904. (root@localhost) [(none)]&gt;create user dba@'192.168.4.%' IDENTIFIED AS 'NQx|.l{N7T/GosA.Lp4EiO0bxLVQp8Zi0WY2nXLr8TkleQPYjaqVxI7';
  905. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS 'NQx|.l{N7T/GosA.Lp4EiO0bxLVQp8Zi0WY2nXLr8TkleQPYjaqVxI7'' at line 1
  906. </pre>
  907. <p><span style="font-weight: 400;">Don’t waste time, there is nothing wrong in the query, except the simple fact that you CANNOT use the text coming from the authentication_string when you have </span><i><span style="font-weight: 400;">caching_sha2</span></i><span style="font-weight: 400;">.&nbsp;</span></p>
  908. <p><span style="font-weight: 400;">So? What should we do?&nbsp;</span></p>
  909. <p><span style="font-weight: 400;">The answer is easy, we need to convert the password into binary and use/store that.&nbsp;</span></p>
  910. <p><span style="font-weight: 400;">Let us try.</span></p>
  911. <p><span style="font-weight: 400;">First create the user again:</span></p>
  912. <pre class="lang:mysql decode:true">(root@localhost) [(none)]&gt;select user,host,authentication_string,plugin from mysql.user where user ='dba' order by 1,2;
  913. +------+-------------+------------------------------------------------------------------------+-----------------------+
  914. | user | host        | authentication_string                                                  | plugin                |
  915. +------+-------------+------------------------------------------------------------------------+-----------------------+
  916. | dba  | 192.168.1.% | *381AD08BBFA647B14C82AC1094A29AD4D7E4F51D                              | mysql_native_password |
  917. | dba  | 192.168.4.% | $A$005$X&gt;ztS}WfR"k~aH3Hs0hBbF3WmM2FXubKumr/CId182pl2Lj/gEtxLvV0 | caching_sha2_password |
  918. +------+-------------+------------------------------------------------------------------------+-----------------------+
  919. 2 rows in set (0.00 sec)
  920.  
  921. (root@localhost) [(none)]&gt;exit
  922. Bye
  923. [root@master3 ps80]# ./mysql-3307 -udba -pdba -h192.168.4.57 -P3307
  924. ...
  925. (dba@192.168.4.57) [(none)]&gt;
  926. </pre>
  927. <p><span style="font-weight: 400;">OK as you can see I create the user and can connect, but as we know the PW is not portable.</span></p>
  928. <p><span style="font-weight: 400;">Let us convert it and create the user:</span></p>
  929. <pre class="lang:mysql decode:true">(root@localhost) [(none)]&gt;select user,host,convert(authentication_string using binary),plugin from mysql.user where user ='dba' and host='192.168.4.%' order by 1,2;
  930. +------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
  931. | user | host        | convert(authentication_string using binary)                                                                                                    | plugin                |
  932. +------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
  933. | dba  | 192.168.4.% | 0x2441243030352458193E107A74537D0157055C66527F226B7E5C6148334873306842624633576D4D32465875624B756D722F434964313832706C324C6A2F674574784C765630 | caching_sha2_password |
  934. +------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
  935. </pre>
  936. <p><span style="font-weight: 400;">So the password is: </span></p>
  937. <pre class="lang:mysql decode:true">0x2441243030352458193E107A74537D0157055C66527F226B7E5C6148334873306842624633576D4D32465875624B756D722F434964313832706C324C6A2F674574784C7656
  938. </pre>
  939. <p>Let us use it:</p>
  940. <pre class="lang:mysql decode:true">(root@localhost) [(none)]&gt;drop user dba@'192.168.4.%';
  941. Query OK, 0 rows affected (0.02 sec)
  942.  
  943. (root@localhost) [(none)]&gt;create user dba@'192.168.4.%' IDENTIFIED with 'caching_sha2_password' AS 0x2441243030352458193E107A74537D0157055C66527F226B7E5C6148334873306842624633576D4D32465875624B756D722F434964313832706C324C6A2F674574784C765630;
  944. Query OK, 0 rows affected (0.03 sec)
  945. </pre>
  946. <p><span style="font-weight: 400;">Let us check the user now:</span></p>
  947. <pre class="lang:mysql decode:true">(root@localhost) [(none)]&gt;select user,host, authentication_string,plugin from mysql.user where user ='dba' and host= '192.168.4.%' order by 1,2;
  948. +------+-------------+------------------------------------------------------------------------+-----------------------+
  949. | user | host        | authentication_string                                                  | plugin                |
  950. +------+-------------+------------------------------------------------------------------------+-----------------------+
  951. | dba  | 192.168.4.% | $A$005$X&gt;ztS}WfR"k~aH3Hs0hBbF3WmM2FXubKumr/CId182pl2Lj/gEtxLvV0 | caching_sha2_password |
  952. +------+-------------+------------------------------------------------------------------------+-----------------------+
  953. 1 row in set (0.00 sec)
  954.  
  955. [root@master3 ps80]# ./mysql-3307 -udba -pdba -h192.168.4.57 -P3307
  956.  
  957. (dba@192.168.4.57) [(none)]&gt;select current_user();
  958. +-----------------+
  959. | current_user()  |
  960. +-----------------+
  961. | dba@192.168.4.% |
  962. +-----------------+
  963. 1 row in set (0.00 sec)
  964.  
  965. </pre>
  966. <p><span style="font-weight: 400;">As you can see the user has been created correctly and password is again in encrypted format.&nbsp;</span></p>
  967. <p><span style="font-weight: 400;">In short what you need to do when in need to export users from MySQL/PS 8 is:</span></p>
  968. <ol>
  969. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Read the user information</span></li>
  970. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Convert Password to hex format when plugin is caching_sha2</span></li>
  971. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Push the AS &lt;password&gt; converted to a file or any other way you were used to</span></li>
  972. </ol>
  973. <p>&nbsp;</p>
  974. <p>Another possible solution is to use at session level the parameter <em>print_identified_with_as_hex.</em> If set causes SHOW CREATE USER to display such hash values as hexadecimal strings rather than as regular string literals. Hash values that do not contain unprintable characters still display as regular string literals, even with this variable enabled.</p>
  975. <p><span style="font-weight: 400;">This at the end is exactly what Fred and I have done for our tools:</span></p>
  976. <p><span style="font-weight: 400;">See:</span></p>
  977. <ul>
  978. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Fred: </span><a href="https://github.com/lefred/mysqlshell-plugins/commit/aa5c6bbe9b9aa689bf7266f5a19a35d0091f6568"><span style="font-weight: 400;">https://github.com/lefred/mysqlshell-plugins/commit/aa5c6bbe9b9aa689bf7266f5a19a35d0091f6568</span></a></li>
  979. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Pt-show-grants: <a href="https://github.com/percona/percona-toolkit/blob/4a812d4a79c0973bf176105b0d138ad0a2a46b2f/bin/pt-show-grants#L2058" rel="nofollow">https://github.com/percona/percona-toolkit/blob/4a812d4a79c0973bf176105b0d138ad0a2a46b2f/bin/pt-show-grants#L2058</a></span></li>
  980. </ul>
  981. <h1><span style="font-weight: 400;">Conclusions</span></h1>
  982. <p><span style="font-weight: 400;">MySQL 8 and Percona server comes with a more secure hashing mechanism <i>caching_sha2_password</i> which is also the default. However if you have the need to migrate users and you use your own tools to export and import the passwords, you must update them as indicated. Or use the Percona Toolkit tools that we keep up to date for you.</span></p>
  983. <p>&nbsp;</p>
  984. <p><span style="font-weight: 400;">Have fun with MySQL!!</span></p>]]></description>
  985. <category>MySQL</category>
  986. <pubDate>Sun, 24 Sep 2023 15:39:08 +0000</pubDate>
  987. </item>
  988. <item>
  989. <title>Proof of Concept: Horizontal Write Scaling for MySQL with Kubernetes Operator</title>
  990. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/253-horizontal-write-scaling-for-mysql-with-operator-poc</link>
  991. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/253-horizontal-write-scaling-for-mysql-with-operator-poc</guid>
  992. <description><![CDATA[<p><span style="font-weight: 400;">Historically MySQL is great in horizontal READ scale. The scaling in that case is offered by the different number of Replica nodes, no matter if using standard asynchronous replication or synchronous replication.&nbsp;</span></p>
  993. <p><span style="font-weight: 400;">However those solutions do not offer the same level of scaling for writes operation.&nbsp;</span></p>
  994. <p><span style="font-weight: 400;">Why? Because the solutions still rely on writing in one single node that works as Primary. Also in case of multi-Primary the writes will be distributed by transaction. In both cases, when using virtually-synchronous replication, the process will require certification from each node and local (by node) write, as such the number of writes are NOT distributed across multiple nodes but duplicated.&nbsp;</span></p>
  995. <p><span style="font-weight: 400;">The main reason behind this is that MySQL is a relational database system (RDBMS), and any data that is going to be written in it, must respect the RDBMS rules (</span><a href="https://en.wikipedia.org/wiki/Relational_database"><span style="font-weight: 400;">https://en.wikipedia.org/wiki/Relational_database</span></a><span style="font-weight: 400;">). In short any data that is written must be consistent with the data present. To achieve that the data needs to be checked with the existing through defined relations and constraints. This action is something that can affect very large datasets and be very expensive. Think about updating a table with millions of rows that refer to another table with another million rows.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p>
  996. <p><span style="font-weight: 400;">An image may help:</span></p>
  997. <p><a href="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/schema-db.gif"><img src="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/schema-db.gif" alt="schema db" width="478" height="600" class="alignnone size-full wp-image-87678" style="display: block; margin-left: auto; margin-right: auto;" /></a></p>
  998. <p><span style="font-weight: 400;">Every time I will insert an order, I must be sure that all the related elements are in place and consistent.&nbsp;</span></p>
  999. <p><span style="font-weight: 400;">This operation is quite expensive but our database is able to run it in a few milliseconds or less, thanks to several optimizations that allow the node to execute most of them in memory, with none or little access to mass storage.&nbsp;</span></p>
  1000. <p><span style="font-weight: 400;">The key factor is that the whole data structure resides in the same location (node) facilitating the operations.</span></p>
  1001. <p><span style="font-weight: 400;">Once we have understood that, it will also become clear why we cannot have relational data split in multiple nodes and have to distribute writes by table. If I have a node that manages only the items, another the orders, another the payments, I will need to have my solution able to deal with distributed transactions, each of which needs to certify and verify other nodes data.&nbsp;</span></p>
  1002. <p><span style="font-weight: 400;">This level of distribution will seriously affect the efficiency of the operation which will increase the response time significantly. This is it, nothing is impossible however the performances will be so impacted that each operation may take seconds instead milliseconds or fraction of it, unless lifting some of the rules breaking the relational model.</span></p>
  1003. <p><span style="font-weight: 400;">MySQL as well as other RDBMS are designed to work respecting the model and cannot scale in any way by fragmenting and distributing a schema, so what can be done to scale?</span></p>
  1004. <p>&nbsp;</p>
  1005. <p><span style="font-weight: 400;">The alternative is to split a consistent set of data into fragments. What is a consistent set of data? It all depends on the kind of information we are dealing with. Keeping in mind the example above where we have a shop online serving multiple customers, we need to identify which is the most effective way to split the data.</span></p>
  1006. <p><span style="font-weight: 400;">For instance if we try to split the data by Product Type (Books, CD/DVD, etc) we will have a huge duplication of data related to customers/orders/shipments and so on, all this data is also quite dynamic given I will have customers constantly ordering things.&nbsp;</span></p>
  1007. <p>&nbsp;</p>
  1008. <p><span style="font-weight: 400;">Why duplicate the data? Because if I do not duplicate that data I will not know if a customer had already bought or not that specific item, or I will have to ask again about the shipment address and so on. Which means also that any time a customer buys something or puts something in the wish list I have to reconcile the data in all my nodes/clusters.</span></p>
  1009. <p>&nbsp;</p>
  1010. <p><span style="font-weight: 400;">On the other hand if I choose to split my data by country of customer’s residence the only data I will have to duplicate and keep in sync is the one related to the products, of which the most dynamic one will be the number of items in stock. This of course unless I can organize my products by country as well, which is a bit unusual nowadays, but not impossible.&nbsp;</span></p>
  1011. <p>&nbsp;</p>
  1012. <p><span style="font-weight: 400;">Another possible case is if I am a health organization and I manage several hospitals. As for the example above, it will be easier to split my data by hospital given most of the data related to patients is bound to the hospital itself as well as treatments and any other element related to hospital management. While it will make no sense to split by patient's country of residence.</span></p>
  1013. <p>&nbsp;</p>
  1014. <p><span style="font-weight: 400;">This technique of splitting the data into smaller pieces is called </span><b>sharding </b><span style="font-weight: 400;">and at the moment is the only way we have to scale RDBM horizontally.&nbsp;</span></p>
  1015. <p>&nbsp;</p>
  1016. <p><span style="font-weight: 400;">In the MySQL open source ecosystem we have only two consolidated ways to perform sharding, Vitess and ProxySQL. The first one is a complete solution that takes ownership of your database and manages almost any aspect of its operations in a sharded environment, this includes a lot of specific features for DBA to deal with daily operations like table modifications, backup and more.&nbsp;</span></p>
  1017. <p>&nbsp;</p>
  1018. <p><span style="font-weight: 400;">While this may look great it also comes with some string attached, including the complexity and proprietary environment. That makes Vitess a good fit for “complex” sharding scenarios where other solutions may not be enough.</span></p>
  1019. <p>&nbsp;</p>
  1020. <p><span style="font-weight: 400;">ProxySQL does not have a sharding mechanism “per se” but given the way it works and the features it has, allow us to build simple sharding solutions.&nbsp;</span></p>
  1021. <p><span style="font-weight: 400;">It is important to note that most of the DBA operations will still be on DBA to be executed with incremented complexity given the sharding environment.&nbsp;</span></p>
  1022. <p>&nbsp;</p>
  1023. <p><span style="font-weight: 400;">There is a third option which is application aware sharding.&nbsp;</span></p>
  1024. <p><span style="font-weight: 400;">This solution sees the application be aware of the need to split the data in smaller fragments and internally point the data to different “connectors” who are connected to multiple data sources.&nbsp;</span></p>
  1025. <p><span style="font-weight: 400;">In this case the application is aware of a customer country and will redirect all the operations related to him to the datasource responsible for the specific fragment.</span></p>
  1026. <p><span style="font-weight: 400;">Normally this solution requires a full code re-design and could be quite difficult to achieve when it is injected after the initial code architecture definition.&nbsp;&nbsp;</span></p>
  1027. <p><span style="font-weight: 400;">On the other hand, if done at design it is probably the best solution, because it will allow the application to define the sharding rules and can also optimize the different data sources using different technologies for different uses.</span></p>
  1028. <p><span style="font-weight: 400;">One example could be the use of a RDBMS for most of the </span><b>Online transaction processing (</b><span style="font-weight: 400;">OLTP) data shared by country, and having the products as distributed memory cache with a different technology. At the same time all the data related to orders, payments and customer history can be consolidated in a data warehouse used to generate reporting.&nbsp;&nbsp;&nbsp;&nbsp;</span></p>
  1029. <p>&nbsp;</p>
  1030. <p><span style="font-weight: 400;">As said the last one is probably the most powerful, scalable and difficult to design and unfortunately it represents probably less than the 5% of the solution currently deployed.&nbsp;</span></p>
  1031. <p><span style="font-weight: 400;">As well as very few cases are in the need to have a full system/solution to provide scalability with sharding.&nbsp;</span></p>
  1032. <p>&nbsp;</p>
  1033. <p><span style="font-weight: 400;">By experience, most of the needs for horizontal scaling fell in the simple scenario, where there is the need to achieve sharding and data separation, very often with sharding-nothing architecture. In shared-nothing, each shard can live in a totally separate logical schema instance / physical database server / data center / continent. There is no ongoing need to retain shared access (from between shards) to the other unpartitioned tables in other shards.</span></p>
  1034. <p>&nbsp;</p>
  1035. <h2><span style="font-weight: 400;">The POC</span></h2>
  1036. <h4><span style="font-weight: 400;">Why this POC?</span></h4>
  1037. <p><span style="font-weight: 400;">In the years I have faced a lot of customers that were talking about scaling their database solution and looking at very complex sharding as Vitess as the first and only way to go.&nbsp;</span></p>
  1038. <p><span style="font-weight: 400;">This without even considering if their needs were driving them there for real.&nbsp;</span></p>
  1039. <p><img src="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/kiss.png" alt="kiss" width="216" height="188" class="wp-image-87680 alignleft" style="margin-right: 10px; float: left;" /></p>
  1040. <p><span style="font-weight: 400;">In my experience, and talking with several colleagues, I am not alone, when analyzing the real needs and after discussing with all the parties impacted, only a very small percentage of customers were in the real need of complex solutions. Most of the others were just trying to avoid a project that will implement simple shared-nothing solutions. Why? Because apparently it is simpler to migrate data to a platform that </span><i><span style="font-weight: 400;">does all for you</span></i><span style="font-weight: 400;">, than accept a bit of additional work and challenge at the beginning but keep a simple approach. Also going for the last shining things always has its magic.</span></p>
  1041. <p><span style="font-weight: 400;">On top of that, with the rise of Kubernetes and Mysql Operators, a lot of confusion starts to circulate, most of which generate by the total lack of understanding that a Database and a relational database are two separate things. That lack of understanding the difference and the real problems attached to a RDBMS had brought some to talk about horizontal scaling for databases, with a concerning superficiality and without clarifying if they were talking about RDBMS or not. As such some clarification is long due as well as putting back the KISS principle as the main focus.&nbsp;</span></p>
  1042. <p>&nbsp;</p>
  1043. <p><span style="font-weight: 400;">Given that, I thought that refreshing how ProxySQL could help in building a simple sharding solution may help to clarify the issues, reset the expectations and show how we can do things in a simpler way.&nbsp; (See my old post </span><a href="https://www.percona.com/blog/mysql-sharding-with-proxysql/"><span style="font-weight: 400;">https://www.percona.com/blog/mysql-sharding-with-proxysql/</span></a><span style="font-weight: 400;">).&nbsp;</span></p>
  1044. <p>&nbsp;</p>
  1045. <p><span style="font-weight: 400;">To do so I had built a simple POC that illustrates how you can use Percona Operator for MySQL (POM) and ProxySQL to build a sharded environment with a good level of automation for some standard operations like backup/restore software upgrade and resource scaling.&nbsp;</span></p>
  1046. <p>&nbsp;</p>
  1047. <h4><span style="font-weight: 400;">Why Proxysql?</span></h4>
  1048. <p><span style="font-weight: 400;">In the following example we mimic a case where we need </span><i><span style="font-weight: 400;">a simple sharding solution</span></i><span style="font-weight: 400;">, which means we just need to redirect the data to different data containers, keeping the database maintenance operations on us. In this common case we do not need to implement a full sharding system such as Vitess.&nbsp;</span></p>
  1049. <p><span style="font-weight: 400;"></span></p>
  1050. <p><span style="font-weight: 400;">As illustrated above ProxySQL allows us to set up a common entry point for the application and then redirect the traffic on the base of identified sharding keys. It will also allow us to redirect read/write traffic to the primary and read only traffic to all secondaries.&nbsp;</span></p>
  1051. <p>&nbsp;</p>
  1052. <p><span style="font-weight: 400;">The other interesting thing is that we can have ProxySQL as part of the application pod, or as an independent service. Best practices indicate that having ProxySQL closer to the application will be more efficient especially if we decide to activate the caching feature.&nbsp;&nbsp;</span></p>
  1053. <p>&nbsp;</p>
  1054. <h4><span style="font-weight: 400;">Why POM</span></h4>
  1055. <p><span style="font-weight: 400;">Percona Operator for MySQL comes with three main solutions, Percona Operator for PXC, Percona Operator for MySQL Group Replication and Percona Operator for Percona server. The first two are based on virtually-synchronous replication, and allow the cluster to keep the data state consistent across all pods, which guarantees that the service will always offer consistent data.&nbsp; In K8s context we can see POM as a single service with native horizontal scalability for reads, while for writes we will adopt the mentioned sharding approach.&nbsp;</span></p>
  1056. <p>&nbsp;</p>
  1057. <p><span style="font-weight: 400;">The other important aspects of using a POM based solution is the automation it comes with. Deploying POM you will be able to set automation for backups, software updates, monitoring (using PMM) and last but not least the possibility to scale UP or DOWN just changing the needed resources.&nbsp;</span></p>
  1058. <h3><span style="font-weight: 400;">The elements used</span></h3>
  1059. <p><a href="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/horizontal_scaling.jpg"><img src="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/horizontal_scaling.jpg" alt="horizontal scaling" width="450" height="422" class="alignnone wp-image-87688" /></a></p>
  1060. <p><span style="font-weight: 400;">In our POC I will use a modified version of sysbench (https://github.com/Tusamarco/sysbench), that has an additional field </span><i><span style="font-weight: 400;">continent</span></i><span style="font-weight: 400;"> and I will use that as a sharding key. At the moment and for the purpose of this simple POC I will only have 2 Shards.</span></p>
  1061. <p>&nbsp;</p>
  1062. <p><span style="font-weight: 400;">As the diagram above illustrates here we have a simple deployment but good enough to illustrate the sharding approach.</span></p>
  1063. <p><span style="font-weight: 400;">We have:</span></p>
  1064. <ul>
  1065. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">The application(s) node(s), it is really up to you if you want to test with one application node or more, nothing will change, as well as for the ProxySQL nodes, just keep in mind that if you use more proxysql nodes is better to activate the internal cluster support or use consul to synchronize them.&nbsp;</span></li>
  1066. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Shard 1 is based on POM with PXC, it has:</span></li>
  1067. </ul>
  1068. <ul>
  1069. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Load balancer for service entry point</span>
  1070. <ul>
  1071. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">Entry point for r/w</span></li>
  1072. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">Entry point for read only</span></li>
  1073. </ul>
  1074. </li>
  1075. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">3 Pods for Haproxy</span>
  1076. <ul>
  1077. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">Haproxy container</span></li>
  1078. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">Pmm agent container</span></li>
  1079. </ul>
  1080. </li>
  1081. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">3 Pods with data nodes (PXC)</span>
  1082. <ul>
  1083. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">PXC cluster node container</span></li>
  1084. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">Log streaming</span></li>
  1085. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">Pmm container&nbsp;</span></li>
  1086. </ul>
  1087. </li>
  1088. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Backup/restore service&nbsp;</span></li>
  1089. </ul>
  1090. <ul>
  1091. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Shard 2 is based on POM for Percona server and Group Replication (technical preview)&nbsp;&nbsp;</span>
  1092. <ul>
  1093. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Load balancer for service entry point</span>
  1094. <ul>
  1095. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">Entry point for r/w</span></li>
  1096. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">Entry point for read only</span></li>
  1097. </ul>
  1098. </li>
  1099. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">3 Pods for MySQL Router (testing)</span>
  1100. <ul>
  1101. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">MySQL router container</span></li>
  1102. </ul>
  1103. </li>
  1104. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">3 Pods with data nodes (PS with GR)</span>
  1105. <ul>
  1106. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">PS -GR cluster node container</span></li>
  1107. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">Log streaming</span></li>
  1108. <li style="font-weight: 400;" aria-level="3"><span style="font-weight: 400;">Pmm container&nbsp;</span></li>
  1109. </ul>
  1110. </li>
  1111. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Backup/restore on scheduler</span></li>
  1112. </ul>
  1113. </li>
  1114. </ul>
  1115. <p>&nbsp;</p>
  1116. <p><span style="font-weight: 400;">Now you may have noticed that the representation of the nodes are different in size, this is not a mistake while drawing. It indicates that I have allocated more resources (CPU and Memory) to shard1 than shard2. Why? Because I can and I am simulating a situation where a shard2 gets less traffic, at least temporarily, as such I do not want to give it the same resources as shard1. I will eventually increase them if I see the needs.&nbsp;</span></p>
  1117. <h2><span style="font-weight: 400;">The settings</span></h2>
  1118. <h3><span style="font-weight: 400;">Data layer</span></h3>
  1119. <p><span style="font-weight: 400;">Let us start with the easy one, the Data layer configuration. Configuring correctly the environment is the key, and to do so I am using a tool that I wrote specifically to calculate the needed configuration in K8s POM environment, you can find it here (</span><a href="https://github.com/Tusamarco/mysqloperatorcalculator"><span style="font-weight: 400;">https://github.com/Tusamarco/mysqloperatorcalculator</span></a><span style="font-weight: 400;">).&nbsp;</span></p>
  1120. <p><span style="font-weight: 400;">Once you have compiled it and run you can simply ask what “dimensions” are supported, or you can define a custom level of resources, but you will still need to indicate the level of expected load. In any case please refer to the README in the repository which has all the instructions.</span></p>
  1121. <p><span style="font-weight: 400;">The full cr.yaml for PXC shard1 is </span><a href="https://github.com/Tusamarco/blogs/blob/master/mysql_horizontal_scaling/cr_pxc.yml"><span style="font-weight: 400;">here</span></a><span style="font-weight: 400;">, while the one for PS-GR </span><a href="https://github.com/Tusamarco/blogs/blob/master/mysql_horizontal_scaling/cr_ps_gr.yml"><span style="font-weight: 400;">here</span></a><span style="font-weight: 400;">.&nbsp;</span></p>
  1122. <p><span style="font-weight: 400;">For Shard 1: I asked for resources to cover traffic of type 2 (Light OLTP), configuration type 5 (2XLarge) 1000 connections.</span></p>
  1123. <p><span style="font-weight: 400;">For Shard2: I ask for resources to cover traffic of type 2 (Light OLTP), configuration type 2 (Small), 100 connections.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p>
  1124. <p><span style="font-weight: 400;">Once you have the CRs defined you can follow the official guidelines to set the environment up ( PXC (</span><a href="https://docs.percona.com/percona-operator-for-mysql/pxc/index.html"><span style="font-weight: 400;">https://docs.percona.com/percona-operator-for-mysql/pxc/index.html</span></a><span style="font-weight: 400;">), PS (</span><a href="https://docs.percona.com/percona-operator-for-mysql/ps/index.html"><span style="font-weight: 400;">https://docs.percona.com/percona-operator-for-mysql/ps/index.html</span></a><span style="font-weight: 400;">)</span></p>
  1125. <p>&nbsp;</p>
  1126. <p><span style="font-weight: 400;">It is time now to see the Proxysql settings.</span></p>
  1127. <h3><span style="font-weight: 400;">ProxySQL and Sharding rules</span></h3>
  1128. <p><span style="font-weight: 400;">As mentioned before we are going to test the load sharding by continent, and as also mentioned before we know that ProxySQL will not provide additional help to automatically manage the sharded environment.&nbsp;</span></p>
  1129. <p><span style="font-weight: 400;">Given that one way to do it is to create a DBA account per shard, or to inject shard information in the commands while executing. </span><span style="font-weight: 400;"><br /></span><span style="font-weight: 400;">I will use the less comfortable one just to prove if it works, the different DBA accounts.&nbsp;</span></p>
  1130. <p>&nbsp;</p>
  1131. <p><span style="font-weight: 400;">We will have 2 shards, the sharding key is the continent field, and the continents will be grouped as follows:</span></p>
  1132. <ul>
  1133. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Shard 1:</span>
  1134. <ul>
  1135. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Asia</span></li>
  1136. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Africa</span></li>
  1137. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Antarctica</span></li>
  1138. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Europe</span></li>
  1139. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">North America</span></li>
  1140. </ul>
  1141. </li>
  1142. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Shard 2:</span>
  1143. <ul>
  1144. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Oceania</span></li>
  1145. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">South America</span></li>
  1146. </ul>
  1147. </li>
  1148. </ul>
  1149. <p>&nbsp;</p>
  1150. <p><span style="font-weight: 400;">The DBAs users:</span></p>
  1151. <ul>
  1152. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">dba_g1</span></li>
  1153. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">dba_g2</span></li>
  1154. </ul>
  1155. <p>&nbsp;</p>
  1156. <p><span style="font-weight: 400;">The application user:</span></p>
  1157. <ul>
  1158. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">app_test</span></li>
  1159. </ul>
  1160. <p>&nbsp;</p>
  1161. <p><span style="font-weight: 400;">The host groups will be:</span></p>
  1162. <ul>
  1163. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Shard 1</span>
  1164. <ul>
  1165. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">100 Read and Write</span></li>
  1166. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">101 Read only</span></li>
  1167. </ul>
  1168. </li>
  1169. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Shard 2</span>
  1170. <ul>
  1171. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">200 Read and Write</span></li>
  1172. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">201 Read only</span></li>
  1173. </ul>
  1174. </li>
  1175. </ul>
  1176. <p>&nbsp;</p>
  1177. <p><span style="font-weight: 400;">Once that is defined, we need to identify which query rules will serve us and how.</span></p>
  1178. <p><span style="font-weight: 400;">What we want is to redirect all the incoming queries for:</span></p>
  1179. <ul>
  1180. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Asia, Africa, Antarctica, Europe and North America to shard 1.</span></li>
  1181. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Oceania and South America to shard 2</span></li>
  1182. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Split the queries in R/W and Read only</span></li>
  1183. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Prevent the execution of any query that do not have a shard key</span></li>
  1184. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Backup data at regular interval and store it in a safe place</span></li>
  1185. </ul>
  1186. <p><a href="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/query_rukes_sharding.png"><img src="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/query_rukes_sharding.png" alt="query rukes sharding" width="800" height="280" class="alignnone size-large wp-image-87681" /></a></p>
  1187. <p><span style="font-weight: 400;">Given the above we first define the rules for the DBAs accounts:</span></p>
  1188. <p><span style="font-weight: 400;">We set the Hostgroup for each DBA and then if the query matches the sharding rule we redirect it to the proper sharding, otherwise the HG will remain as set.</span></p>
  1189. <p><span style="font-weight: 400;">This allows us to execute queries like CREATE/DROP table on our shard without problem, but will allow us to send data where needed.&nbsp;</span></p>
  1190. <p><span style="font-weight: 400;">For instance the one below is the output of the queries that sysbench will run.</span></p>
  1191. <p><b>Prepare:</b></p>
  1192. <pre class="lang:mysql decode:true">INSERT INTO windmills_test1 /*  continent=Asia */ (uuid,millid,kwatts_s,date,location,continent,active,strrecordtype) VALUES(UUID(), 79, 3949999,NOW(),'mr18n2L9K88eMlGn7CcctT9RwKSB1FebW397','Asia',0,'quq')
  1193. </pre>
  1194. <p><span style="font-weight: 400;">In this case I have the application simply injecting a comment in the INSERT SQL declaring the shard key, given I am using the account dba_g1 to create/prepare the schemas, rules&nbsp; 32/32 will be used and give I have sett apply=1, ProxySQL will exit the query rules parsing and send the command to relevant hostgroup.</span></p>
  1195. <p><span style="font-weight: 400;">Run:</span></p>
  1196. <pre class="lang:mysql decode:true">SELECT id, millid, date,continent,active,kwatts_s FROM windmills_test1 WHERE id BETWEEN ? AND ? AND continent='South America'
  1197.  
  1198. SELECT SUM(kwatts_s) FROM windmills_test1 WHERE id BETWEEN ? AND ?  and active=1  AND continent='Asia'
  1199. SELECT id, millid, date,continent,active,kwatts_s  FROM windmills_test1 WHERE id BETWEEN ? AND ?  AND continent='Oceania' ORDER BY millid
  1200.  
  1201. SELECT DISTINCT millid,continent,active,kwatts_s   FROM windmills_test1 WHERE id BETWEEN ? AND ? AND active =1  AND continent='Oceania' ORDER BY millid
  1202.  
  1203. UPDATE windmills_test1 SET active=? WHERE id=?  AND continent='Asia'
  1204. UPDATE windmills_test1 SET strrecordtype=? WHERE id=?  AND continent='North America'
  1205.  
  1206. DELETE FROM windmills_test1 WHERE id=?  AND continent='Antarctica'
  1207.  
  1208. INSERT INTO windmills_test1 /* continent=Antarctica */ (id,uuid,millid,kwatts_s,date,location,continent,active,strrecordtype) VALUES (?, UUID(), ?, ?, NOW(), ?, ?, ?,?) ON DUPLICATE KEY UPDATE kwatts_s=kwatts_s+1
  1209. </pre>
  1210. <p><span style="font-weight: 400;">The above are executed during the tests.&nbsp;</span></p>
  1211. <p><span style="font-weight: 400;">In all of them the sharding key is present, either in the WHERE clause OR as comment.&nbsp;</span></p>
  1212. <p><span style="font-weight: 400;">Of course if I execute one of them without the sharding key,&nbsp; the firewall rule will stop the query execution, ie:</span><span style="font-weight: 400;"><br /></span></p>
  1213. <pre class="lang:mysql decode:true">mysql&gt; SELECT id, millid, date,continent,active,kwatts_s FROM windmills_test1 WHERE id BETWEEN ? AND ?;
  1214. ERROR 1148 (42000): It is impossible to redirect this command to a defined shard. Please be sure you Have the Continent definition in your query, or that you use a defined DBA account (dba_g{1/2})
  1215. </pre>
  1216. <p><span style="font-weight: 400;">Check </span><a href="https://github.com/Tusamarco/blogs/blob/master/mysql_horizontal_scaling/operator_sharding_with_proxysql_public.txt"><span style="font-weight: 400;">here </span></a><span style="font-weight: 400;">for full command list</span></p>
  1217. <h3><span style="font-weight: 400;">Setting up the dataset</span></h3>
  1218. <p><span style="font-weight: 400;">Once we have the rules set it is time to setup the schemas and the data using sysbench (</span><a href="https://github.com/Tusamarco/sysbench"><span style="font-weight: 400;">https://github.com/Tusamarco/sysbench</span></a><span style="font-weight: 400;">), remember to use windmills_sharding tests.&nbsp;&nbsp;</span></p>
  1219. <p><span style="font-weight: 400;">The first operation is to build the schema on SHARD2 without filling it with data. This is a DBA action as such we will execute it using the dba_g2 account:</span></p>
  1220. <pre class="lang:sh decode:true">sysbench ./src/lua/windmills_sharding/oltp_read.lua  --mysql-host=10.0.1.96  --mysql-port=6033 --mysql-user=dba_g2 --mysql-password=xxx --mysql-db=windmills_large --mysql_storage_engine=innodb --db-driver=mysql --tables=4 --table_size=0 --table_name=windmills --mysql-ignore-errors=all --threads=1  prepare
  1221. </pre>
  1222. <p><span style="font-weight: 400;">Setting table_size and pointing to the ProxySQL IP/port will do, and I will have:</span><span style="font-weight: 400;"><br /></span></p>
  1223. <pre class="lang:mysql decode:true">mysql&gt; select current_user(), @@hostname;
  1224. +----------------+-------------------+
  1225. | current_user() | @@hostname        |
  1226. +----------------+-------------------+
  1227. | dba_g2@%       | ps-mysql1-mysql-0 |
  1228. +----------------+-------------------+
  1229. 1 row in set (0.01 sec)
  1230.  
  1231. mysql&gt; use windmills_large;
  1232. Database changed
  1233. mysql&gt; show tables;
  1234. +---------------------------+
  1235. | Tables_in_windmills_large |
  1236. +---------------------------+
  1237. | windmills1                |
  1238. | windmills2                |
  1239. | windmills3                |
  1240. | windmills4                |
  1241. +---------------------------+
  1242. 4 rows in set (0.01 sec)
  1243.  
  1244. mysql&gt; select count(*) from windmills1;
  1245. +----------+
  1246. | count(*) |
  1247. +----------+
  1248. |        0 |
  1249. +----------+
  1250. 1 row in set (0.09 sec)
  1251. </pre>
  1252. <p><span style="font-weight: 400;">All set but empty.</span></p>
  1253. <p><span style="font-weight: 400;">Now let us do the same but with the other DBA user:</span></p>
  1254. <pre class="lang:sh decode:true">sysbench ./src/lua/windmills_sharding/oltp_read.lua  --mysql-host=10.0.1.96  --mysql-port=6033 --mysql-user=dba_g1 --mysql-password=xxx --mysql-db=windmills_large --mysql_storage_engine=innodb --db-driver=mysql --tables=4 --table_size=400 --table_name=windmills --mysql-ignore-errors=all --threads=1  prepare
  1255. </pre>
  1256. <p><span style="font-weight: 400;">If I do now the select above with user dba_g2:</span></p>
  1257. <pre class="lang:mysql decode:true">mysql&gt; select current_user(), @@hostname;select count(*) from windmills1;
  1258. +----------------+-------------------+
  1259. | current_user() | @@hostname        |
  1260. +----------------+-------------------+
  1261. | dba_g2@%       | ps-mysql1-mysql-0 |
  1262. +----------------+-------------------+
  1263. 1 row in set (0.00 sec)
  1264.  
  1265. +----------+
  1266. | count(*) |
  1267. +----------+
  1268. |      113 |
  1269. +----------+
  1270. 1 row in set (0.00 sec)
  1271. </pre>
  1272. <p><span style="font-weight: 400;">While If I reconnect and use dba_g1:</span></p>
  1273. <pre class="lang:mysql decode:true">mysql&gt; select current_user(), @@hostname;select count(*) from windmills1;
  1274. +----------------+--------------------+
  1275. | current_user() | @@hostname         |
  1276. +----------------+--------------------+
  1277. | dba_g1@%       | mt-cluster-1-pxc-0 |
  1278. +----------------+--------------------+
  1279. 1 row in set (0.00 sec)
  1280.  
  1281. +----------+
  1282. | count(*) |
  1283. +----------+
  1284. |      287 |
  1285. +----------+
  1286. 1 row in set (0.01 sec)
  1287. </pre>
  1288. <p><span style="font-weight: 400;">I can also check on ProxySQL to see which rules were utilized:</span></p>
  1289. <pre class="lang:mysql decode:true">select active,hits,destination_hostgroup, mysql_query_rules.rule_id, match_digest, match_pattern, replace_pattern, cache_ttl, apply,flagIn,flagOUT FROM mysql_query_rules NATURAL JOIN stats.stats_mysql_query_rules ORDER BY mysql_query_rules.rule_id;
  1290.  
  1291. +------+-----------------------+---------+---------------------+----------------------------------------------------------------------------+-------+--------+---------+
  1292. | hits | destination_hostgroup | rule_id | match_digest        | match_pattern                                                              | apply | flagIN | flagOUT |
  1293. +------+-----------------------+---------+---------------------+----------------------------------------------------------------------------+-------+--------+---------+
  1294. | 3261 | 100                   | 20      | NULL                | NULL                                                                       | 0     | 0      | 500     |
  1295. | 51   | 200                   | 21      | NULL                | NULL                                                                       | 0     | 0      | 600     |
  1296. | 2320 | 100                   | 31      | NULL                | scontinents*(=|like)s*'*(Asia|Africa|Antarctica|Europe|North America)'* | 1     | 500    | 0       |
  1297. | 880  | 200                   | 32      | NULL                | scontinents*(=|like)s*'*(Oceania|South America)'*                       | 1     | 500    | 0       |
  1298. | 0    | 100                   | 34      | NULL                | scontinents*(=|like)s*'*(Asia|Africa|Antarctica|Europe|North America)'* | 1     | 600    | 0       |
  1299. | 0    | 200                   | 35      | NULL                | scontinents*(=|like)s*'*(Oceania|South America)'*                       | 1     | 600    | 0       |
  1300. | 2    | 100                   | 51      | NULL                | scontinents*(=|like)s*'*(Asia|Africa|Antarctica|Europe|North America)'* | 0     | 0      | 1001    |
  1301. | 0    | 200                   | 54      | NULL                | scontinents*(=|like)s*'*(Oceania|South America)'*                       | 0     | 0      | 1002    |
  1302. | 0    | 100                   | 60      | NULL                | NULL                                                                       | 0     | 50     | 1001    |
  1303. | 0    | 200                   | 62      | NULL                | NULL                                                                       | 0     | 60     | 1002    |
  1304. | 7    | NULL                  | 2000    | .                   | NULL                                                                       | 1     | 0      | NULL    |
  1305. | 0    | 100                   | 2040    | ^SELECT.*FOR UPDATE | NULL                                                                       | 1     | 1001   | NULL    |
  1306. | 2    | 101                   | 2041    | ^SELECT.*$          | NULL                                                                       | 1     | 1001   | NULL    |
  1307. | 0    | 200                   | 2050    | ^SELECT.*FOR UPDATE | NULL                                                                       | 1     | 1002   | NULL    |
  1308. | 0    | 201                   | 2051    | ^SELECT.*$          | NULL                                                                       | 1     | 1002   | NULL    |
  1309. +------+-----------------------+---------+---------------------+----------------------------------------------------------------------------+-------+--------+---------+
  1310. </pre>
  1311. <h3><span style="font-weight: 400;">Running the application</span></h3>
  1312. <p><span style="font-weight: 400;">Now that the data load test was successful, let us do the real load following the indication as above but use 80 Tables and just a bit more records like 20000, nothing huge.&nbsp;</span></p>
  1313. <p>&nbsp;</p>
  1314. <p><span style="font-weight: 400;">Once the data is loaded we will have the 2 shards with different numbers of records, if all went well the shard2 should have ¼ of the total and shard1 ¾ .</span></p>
  1315. <p>&nbsp;</p>
  1316. <p><span style="font-weight: 400;">When load is over I have as expected:</span></p>
  1317. <pre class="lang:mysql decode:true">mysql&gt; select current_user(), @@hostname;select count(*) as shard1 from windmills_large.windmills80;select /* continent=shard2 */ count(*) as shard2 from windmills_large.windmills80;
  1318. +----------------+--------------------+
  1319. | current_user() | @@hostname         |
  1320. +----------------+--------------------+
  1321. | dba_g1@%       | mt-cluster-1-pxc-0 |
  1322. +----------------+--------------------+
  1323. 1 row in set (0.00 sec)
  1324.  
  1325. +--------+
  1326. | shard1 |
  1327. +--------+
  1328. |  14272 | ← Table windmills80 in SHARD1
  1329. +--------+
  1330. +--------+
  1331. | shard2 |
  1332. +--------+
  1333. |   5728 | ← Table windmills80 in SHARD2
  1334. +--------+
  1335. </pre>
  1336. <p><span style="font-weight: 400;">As you may have already noticed, I used a trick to query the other shard using the dba_g1 user, I just passed in the query&nbsp; the shard2 definition as a comment. That is all we need.</span></p>
  1337. <p><span style="font-weight: 400;">Let us execute the </span><i><span style="font-weight: 400;">run</span></i><span style="font-weight: 400;"> command for writes in sysbench and see what happens.</span></p>
  1338. <p><span style="font-weight: 400;">The first thing we can notice while doing writes is the query distribution:</span><span style="font-weight: 400;"><br /></span></p>
  1339. <pre class="lang:mysql decode:true">+--------+-----------+----------------------------------------------------------------------------+----------+--------+----------+----------+--------+---------+-------------+---------+
  1340. | weight | hostgroup | srv_host                                                                   | srv_port | status | ConnUsed | ConnFree | ConnOK | ConnERR | MaxConnUsed | Queries |
  1341. +--------+-----------+----------------------------------------------------------------------------+----------+--------+----------+----------+--------+---------+-------------+---------+
  1342. | 10000  | 100       | ac966f7d46c04400fb92a3603f0e2634-193113472.eu-central-1.elb.amazonaws.com  | 3306     | ONLINE | 24     | 0        | 138    | 66      | 25          | 1309353 |
  1343. | 100    | 101       | a5c8836b7c05b41928ca84f2beb48aee-1936458168.eu-central-1.elb.amazonaws.com | 3306     | ONLINE | 0     | 0        | 0      | 0       | 0           |       0 |
  1344. | 10000  | 200       | a039ab70e9f564f5e879d5e1374d9ffa-1769267689.eu-central-1.elb.amazonaws.com | 3306     | ONLINE | 24     | 1        | 129    | 66      | 25          |  516407 |
  1345. | 10000  | 201       | a039ab70e9f564f5e879d5e1374d9ffa-1769267689.eu-central-1.elb.amazonaws.com | 6447     | ONLINE | 0     | 0        | 0      | 0       | 0           |       0 |
  1346. +--------+-----------+----------------------------------------------------------------------------+----------+--------+----------+----------+--------+---------+-------------+---------+
  1347. </pre>
  1348. <p><span style="font-weight: 400;">Where we can notice that the load in connection is evenly distributed, while the load is mainly going to shard1 as we expected given we have an unbalanced sharding by design.</span></p>
  1349. <p>&nbsp;</p>
  1350. <p><span style="font-weight: 400;">At MySQL level we had:</span></p>
  1351. <p>&nbsp;</p>
  1352. <p><span style="font-weight: 400;">Questions</span></p>
  1353. <p><a href="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/pxc_ps_write_questions.png"><img src="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/pxc_ps_write_questions.png" alt="pxc ps write questions" width="1024" height="187" class="alignnone size-large wp-image-87684" /></a></p>
  1354. <p><span style="font-weight: 400;">Com Type</span></p>
  1355. <p><a href="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/pxc_ps_write_com.png"><img src="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/pxc_ps_write_com.png" alt="pxc ps write com" width="1024" height="179" class="alignnone size-large wp-image-87683" /></a></p>
  1356. <p><a href="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/number_operation_writes.png"><img src="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/number_operation_writes.png" alt="number operation writes" width="473" height="133" class="alignnone size-full wp-image-87687" /></a></p>
  1357. <p><span style="font-weight: 400;">The final point is, what is the gain using this sharding approach?</span></p>
  1358. <p><span style="font-weight: 400;">Well we still need to consider the fact we are testing on a very small set of data, however if we can already identify some benefit here, that will be an interesting result.&nbsp;</span></p>
  1359. <p>&nbsp;</p>
  1360. <p><span style="font-weight: 400;">Let see the write operations with 24 and 64 threads:</span></p>
  1361. <p><a href="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/writes_write.png"><img src="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/writes_write.png" alt="writes write" width="450" height="395" class="alignnone wp-image-87693" /></a> <a href="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/latency_write.png"><img src="http://www.tusacentral.net/joomla/images/stories/mysql_horizontal_scaling/latency_write.png" alt="latency write" width="450" height="395" class="alignnone wp-image-87686" /></a></p>
  1362. <p><span style="font-weight: 400;">We get a gain of ~33% just using sharding, while for latency we do not have a cost on the contrary also with small load increase we can see how the sharded solution performs better. Of course we are still talking about low number of rows and running threads but gain is there.&nbsp;</span></p>
  1363. <p>&nbsp;</p>
  1364. <h3><span style="font-weight: 400;">Backup&nbsp;</span></h3>
  1365. <p><span style="font-weight: 400;">The backup and restore operation when using POM is completely managed by the operator (see instructions in the POM documentation </span><a href="https://docs.percona.com/percona-operator-for-mysql/pxc/backups.html"><span style="font-weight: 400;">https://docs.percona.com/percona-operator-for-mysql/pxc/backups.html</span></a><span style="font-weight: 400;"> and </span><a href="https://docs.percona.com/percona-operator-for-mysql/ps/backups.html"><span style="font-weight: 400;">https://docs.percona.com/percona-operator-for-mysql/ps/backups.html</span></a><span style="font-weight: 400;"> ).&nbsp;</span></p>
  1366. <p><span style="font-weight: 400;">The interesting part is that we can have multiple kind of backup solution, like:</span></p>
  1367. <ul>
  1368. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">On demand</span></li>
  1369. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Scheduled&nbsp;</span></li>
  1370. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Full Point in time recovery with log streaming</span></li>
  1371. </ul>
  1372. <p><span style="font-weight: 400;">Automation will allow us to set schedule as simple as this:</span><span style="font-weight: 400;"><br /></span></p>
  1373. <pre class="lang:yaml decode:true">    schedule:
  1374.     - name: "sat-night-backup"
  1375.        schedule: "0 0 * * 6"
  1376.        keep: 3
  1377.        storageName: s3-eu-west
  1378.      - name: "daily-backup"
  1379.        schedule: "0 3 * * *"
  1380.        keep: 7
  1381.        storageName: s3-eu-west
  1382. </pre>
  1383. <p><span style="font-weight: 400;">Or if you want to run the on demand:</span></p>
  1384. <pre class="lang:sh decode:true">kubectl apply -f backup.yaml</pre>
  1385. <p><span style="font-weight: 400;">Where the backup.yaml file has very simple informations:</span></p>
  1386. <pre class="lang:yaml decode:true">apiVersion: ps.percona.com/v1alpha1
  1387. kind: PerconaServerMySQLBackup
  1388. metadata:
  1389.  name: ps-gr-sharding-test-2nd-of-may
  1390. #  finalizers:
  1391. #    - delete-backup
  1392. spec:
  1393.  clusterName: ps-mysql1
  1394.  storageName: s3-ondemand
  1395. </pre>
  1396. <p><span style="font-weight: 400;">Using both methods we will be able to soon have a good set of backups like:</span></p>
  1397. <p><span style="font-weight: 400;">POM (PXC)</span></p>
  1398. <pre class="lang:sh decode:true">cron-mt-cluster-1-s3-eu-west-20234293010-3vsve   mt-cluster-1   s3-eu-west    s3://mt-bucket-backup-tl/scheduled/mt-cluster-1-2023-04-29-03:00:10-full   Succeeded   3d9h        3d9h
  1399. cron-mt-cluster-1-s3-eu-west-20234303010-3vsve   mt-cluster-1   s3-eu-west    s3://mt-bucket-backup-tl/scheduled/mt-cluster-1-2023-04-30-03:00:10-full   Succeeded   2d9h        2d9h
  1400. cron-mt-cluster-1-s3-eu-west-2023513010-3vsve    mt-cluster-1   s3-eu-west    s3://mt-bucket-backup-tl/scheduled/mt-cluster-1-2023-05-01-03:00:10-full   Succeeded   33h         33h
  1401. cron-mt-cluster-1-s3-eu-west-2023523010-3vsve    mt-cluster-1   s3-eu-west    s3://mt-bucket-backup-tl/scheduled/mt-cluster-1-2023-05-02-03:00:10-full   Succeeded   9h          9h
  1402. </pre>
  1403. <p><span style="font-weight: 400;">POM (PS) *</span></p>
  1404. <pre class="lang:sh decode:true">NAME                             STORAGE       DESTINATION                                                                     STATE       COMPLETED   AGE
  1405. ps-gr-sharding-test              s3-ondemand   s3://mt-bucket-backup-tl/ondemand/ondemand/ps-mysql1-2023-05-01-15:10:04-full   Succeeded   21h         21h
  1406. ps-gr-sharding-test-2nd-of-may   s3-ondemand   s3://mt-bucket-backup-tl/ondemand/ondemand/ps-mysql1-2023-05-02-12:22:24-full   Succeeded   27m         27m
  1407. </pre>
  1408. <p><span style="font-weight: 400;">To note that as DBA, we still need to validate the backups with a restore procedure, that part is not automated (yet).&nbsp;</span></p>
  1409. <p><i><span style="font-weight: 400;">*Note that Backup for POM PS is available only on demand given the solution is still in technical preview</span></i></p>
  1410. <h3><span style="font-weight: 400;">When will this solution fit in?</span></h3>
  1411. <p><span style="font-weight: 400;">As mentioned multiple times, this solution can cover simple cases of sharding, better if you have shared-nothing.&nbsp;</span></p>
  1412. <p><span style="font-weight: 400;">It also requires work from the DBA side in case of DDL operations or resharding.&nbsp;</span></p>
  1413. <p><span style="font-weight: 400;">You also need to be able to change some SQL code in order to be sure to have present the sharding key/information, in any SQL executed.</span></p>
  1414. <p>&nbsp;</p>
  1415. <h3><span style="font-weight: 400;">When will this solution not fit in?</span></h3>
  1416. <p><span style="font-weight: 400;">There are several things that could prevent you to use this solution, the most common ones are:</span></p>
  1417. <ul>
  1418. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">You need to query multiple shards at the same time. This is not possible with ProxySQL</span></li>
  1419. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">You do not have a DBA to perform administrative work and need to rely on automated system</span></li>
  1420. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Distributed transaction cross shard</span></li>
  1421. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">No access to SQL code.</span></li>
  1422. </ul>
  1423. <h2><span style="font-weight: 400;">Conclusions</span></h2>
  1424. <p><span style="font-weight: 400;">We do not have the Amletic dilemma about sharding or not sharding.&nbsp;</span></p>
  1425. <p><span style="font-weight: 400;">When using a RDBMS like MySQL, if you need horizontal scalability, you need to shard.&nbsp;</span></p>
  1426. <p><span style="font-weight: 400;">The point is there is no magic wand or solution, moving to sharding is an expensive and impacting operation. If you choose it at the beginning, before doing any application development, the effort can be significantly less.&nbsp;</span></p>
  1427. <p><span style="font-weight: 400;">Doing sooner will also allow you to test proper solutions, where </span><i><span style="font-weight: 400;">proper</span></i><span style="font-weight: 400;"> is a KISS solution, always go for the less complex things, in 2 years you will be super happy about your decision.&nbsp;&nbsp;</span></p>
  1428. <p><span style="font-weight: 400;">If instead you must convert a current solution, then prepare for a bloodshed, or at least for a long journey.&nbsp;</span></p>
  1429. <p><span style="font-weight: 400;">In any case we need to keep in mind few key points:</span></p>
  1430. <ul>
  1431. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Do not believe most of the articles on the internet that promise you infinite scalability for your database. If there is no distinction in the article about a simple database and a RDBMS, run away.&nbsp;</span></li>
  1432. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Do not go for the last shiny things just because they shine. Test them and evaluate IF it makes sense for you. Better to spend a quarter testing now a few solutions, than fight for years with something that you do not fully comprehend.&nbsp;&nbsp;</span></li>
  1433. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Using containers/operators/kubernetes do not scale </span><i><span style="font-weight: 400;">per se</span></i><span style="font-weight: 400;">, you must find a mechanism to have the solution scaling, there is absolutely NO difference with premises. What you may get is a good level of automation, however that will come with a good level of complexity, it is up to you to evaluate if it makes sense or not.&nbsp;&nbsp;</span></li>
  1434. </ul>
  1435. <p>&nbsp;</p>
  1436. <p><span style="font-weight: 400;">As said at the beginning for MYSQL the choice is limited. Vitess is the full complete solution, with a lot of coding to provide you a complete platform to deal with your scaling needs.</span></p>
  1437. <p><span style="font-weight: 400;">However do not be so fast to exclude ProxySQL as possible solutions. There are out there already many using it also for sharding.&nbsp;</span></p>
  1438. <p><span style="font-weight: 400;">This small POC used a synthetic case, but it also shows that with just 4 rules you can achieve a decent solution. A real scenario could be a bit more complex … or not.&nbsp;</span></p>
  1439. <p>&nbsp;</p>
  1440. <h2><span style="font-weight: 400;">References</span></h2>
  1441. <p><span style="font-weight: 400;">Vitess (</span><a href="https://vitess.io/docs/"><span style="font-weight: 400;">https://vitess.io/docs/</span></a><span style="font-weight: 400;">)</span></p>
  1442. <p><span style="font-weight: 400;">ProxySQL (</span><a href="https://proxysql.com/documentation/"><span style="font-weight: 400;">https://proxysql.com/documentation/</span></a><span style="font-weight: 400;">)</span></p>
  1443. <p><span style="font-weight: 400;">Firewalling with ProxySQL (</span><a href="https://www.tusacentral.com/joomla/index.php/mysql-blogs/197-proxysql-firewalling"><span style="font-weight: 400;">https://www.tusacentral.com/joomla/index.php/mysql-blogs/197-proxysql-firewalling</span></a><span style="font-weight: 400;">)</span></p>
  1444. <p><span style="font-weight: 400;">Sharding:</span></p>
  1445. <ul>
  1446. <li style="font-weight: 400;" aria-level="1"><a href="https://www.percona.com/blog/mysql-sharding-with-proxysql/"><span style="font-weight: 400;">https://www.percona.com/blog/mysql-sharding-with-proxysql/</span></a></li>
  1447. <li style="font-weight: 400;" aria-level="1"><a href="https://www.percona.com/blog/horizontal-scaling-in-mysql-sharding-followup/"><span style="font-weight: 400;">https://https://medium.com/pinterest-engineering/sharding-pinterest-how-we-scaled-our-mysql-fleet-3f341e96ca6fwww.percona.com/blog/horizontal-scaling-in-mysql-sharding-followup/</span></a></li>
  1448. <li style="font-weight: 400;" aria-level="1"><a href="https://quoraengineering.quora.com/MySQL-sharding-at-Quora"><span style="font-weight: 400;">https://quoraengineering.quora.com/MySQL-sharding-at-Quora</span></a></li>
  1449. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">https://skywalking.apache.org/blog/skywalkings-new-storage-feature-based-on-shardingsphere-proxy-mysql-sharding/</span></li>
  1450. </ul>
  1451. <p>&nbsp;</p>]]></description>
  1452. <category>MySQL</category>
  1453. <pubDate>Thu, 11 May 2023 12:20:20 +0000</pubDate>
  1454. </item>
  1455. <item>
  1456. <title>Which is the best Proxy for Percona MySQL Operator?</title>
  1457. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/252-comparisons-of-proxies-for-mysql</link>
  1458. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/252-comparisons-of-proxies-for-mysql</guid>
  1459. <description><![CDATA[<h2>Overview</h2>
  1460. <p>HAProxy, ProxySQL, MySQL Router (AKA MySQL Proxy), in the last few years I had to answer multiple times on what proxy to use and in what scenario. When designing an architecture there are many components that need to be considered before deciding what is the best solution.</p>
  1461. <p>When deciding what to pick, there are many things to consider like where the proxy needs to be, if it “just” needs to redirect the connections or if more features need to be in, like caching, filtering, or if it needs to be integrated with some MySQL embedded automation.</p>
  1462. <p>Given that, there never was a single straight answer, instead an analysis needs to be done. Only after a better understanding of the environment, the needs and the evolution that the platform needs to achieve is it possible to decide what will be the better choice.</p>
  1463. <p>However recently we have seen an increase in usage of MySQL on Kubernetes, especially with the adoption of Percona Operator for MySQL.<br />In this case we have a quite well define scenario that can resemble the image below:</p>
  1464. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/proxys_gr_comparison-default.png"><img src="http://www.tusacentral.net/joomla/images/stories/proxies_comparisons_march_2023/proxys_gr_comparison-default.png" alt="proxys gr comparison default" width="536" height="614" class="aligncenter wp-image-86219 size-full" style="display: block; margin-left: auto; margin-right: auto;" /></a></p>
  1465. <p><span style="font-weight: 400;">In this scenario the proxies need to sit inside Pods balancing the incoming traffic from the Service LoadBalancer connecting with the active data nodes.</span></p>
  1466. <p><span style="font-weight: 400;">Their role is merely to be sure that any incoming connection is redirected to nodes that are able to serve them, which include having a separation between Read/Write and Read Only traffic, separation that can be achieved, at service level, with automatic recognition or with two separate entry points.&nbsp;</span></p>
  1467. <p><span style="font-weight: 400;">In this scenario it is also crucial to be efficient in resource utilization and scaling with frugality. In this context features like filtering, firewalling or caching are redundant and may consume resources that could be allocated to scaling. Those are also features that will work better outside the K8s/Operator cluster, given the closer to the application they are located, the better they will serve.&nbsp;</span></p>
  1468. <p><span style="font-weight: 400;">About that we must always remember the concept that each K8s/Operator cluster needs to be seen as a single service, not as a real cluster. In short each cluster is in reality a single database with High Availability and other functionalities built in.&nbsp;</span></p>
  1469. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/proxys_gr_comparison-default.png"></a></p>
  1470. <p><span style="font-weight: 400;">Anyhow, we are here to talk about Proxies. Once we have defined that we have one clear mandate in mind, we need to identify which product allow our K8s/Operator solution to:</span></p>
  1471. <ul>
  1472. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Scale at the maximum the number of incoming connections</span></li>
  1473. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Serve the request with the higher efficiency</span></li>
  1474. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Consume less resources as possible</span></li>
  1475. </ul>
  1476. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/proxys_gr_comparison-default.png"></a></p>
  1477. <h2><span style="font-weight: 400;">The Environment</span></h2>
  1478. <p><span style="font-weight: 400;">To identify the above points I have simulated a possible K8s/Operator environment, creating:</span></p>
  1479. <ul>
  1480. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">One powerful application node, where I run sysbench read only tests, scaling from 2 to 4096 threads. (Type c5.4xlarge)</span></li>
  1481. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">3 Mid data nodes with several gigabytes of data in with MySQL and Group Replication (Type m5.xlarge)</span></li>
  1482. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">1 Proxy node running on a resource limited box (Type t2.micro)</span></li>
  1483. </ul>
  1484. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/proxys_gr_comparison-default.png"></a></p>
  1485. <h2><span style="font-weight: 400;">The Tests&nbsp;</span></h2>
  1486. <p><span style="font-weight: 400;">We will have very simple test cases. The first one has the scope to define the baseline, identifying the moment when we will have the first level of saturation due to the number of connections. In this case we will increase the number of connections and keep a low number of operations.&nbsp;</span></p>
  1487. <p><span style="font-weight: 400;">The second test will define how well the increasing load is served inside the range we had previously identified.&nbsp;</span></p>
  1488. <p><span style="font-weight: 400;">For documentation the sysbench commands are:</span></p>
  1489. <p><span style="font-weight: 400;">Test1</span></p>
  1490. <pre class="lang:sh decode:true">sysbench ./src/lua/windmills/oltp_read.lua  --db-driver=mysql --tables=200 --table_size=1000000
  1491. --rand-type=zipfian --rand-zipfian-exp=0 --skip_trx=true  --report-interval=1 --mysql-ignore-errors=all
  1492. --mysql_storage_engine=innodb --auto_inc=off --histogram  --stats_format=csv --db-ps-mode=disable --point-selects=50
  1493. --reconnect=10 --range-selects=true –rate=100 --threads=&lt;#Threads from 2 to 4096&gt; --time=1200 run
  1494. </pre>
  1495. <p><span style="font-weight: 400;">Test2</span></p>
  1496. <pre class="lang:sh decode:true">sysbench ./src/lua/windmills/oltp_read.lua  --mysql-host=&lt;host&gt; --mysql-port=&lt;port&gt; --mysql-user=&lt;user&gt;
  1497. --mysql-password=&lt;pw&gt; --mysql-db=&lt;schema&gt; --db-driver=mysql --tables=200 --table_size=1000000  --rand-type=zipfian
  1498. --rand-zipfian-exp=0 --skip_trx=true  --report-interval=1 --mysql-ignore-errors=all --mysql_storage_engine=innodb
  1499. --auto_inc=off --histogram --table_name=&lt;tablename&gt;  --stats_format=csv --db-ps-mode=disable --point-selects=50
  1500. --reconnect=10 --range-selects=true --threads=&lt;#Threads from 2 to 4096&gt; --time=1200 run
  1501. </pre>
  1502. <h2><span style="font-weight: 400;">Results</span></h2>
  1503. <h3><span style="font-weight: 400;">Test 1</span></h3>
  1504. <p><span style="font-weight: 400;">As indicated here I was looking to identify when the first Proxy will reach a dimension that would not be manageable. The load is all in creating and serving the connections, while the number of operations is capped to 100.&nbsp;</span></p>
  1505. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/events_rate2.png"><img src="http://www.tusacentral.net/joomla/images/stories/proxies_comparisons_march_2023/events_rate2.png" alt="events rate2" width="600" height="401" class="alignnone size-large wp-image-86207" style="display: block; margin-left: auto; margin-right: auto;" /></a></p>
  1506. <p><span style="font-weight: 400;">As you can see and as I was expecting, the three Proxies were behaving more or less the same, serving the same number of operations (they were capped so why not), until not.</span></p>
  1507. <p><span style="font-weight: 400;">MySQL router after 2048 connection was not able to serve anything more.</span></p>
  1508. <p><b>NOTE: MySQL Router was actually stopped working at 1024 threads, but using version 8.0.32 I enabled the feature: </b><b><i>connection_sharing</i></b><b>. That allows it to go a bit further</b><span style="font-weight: 400;">.&nbsp;&nbsp;</span></p>
  1509. <p><span style="font-weight: 400;">Let us take a look also the the latency:</span></p>
  1510. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/latency95_rate.png"><img src="http://www.tusacentral.net/joomla/images/stories/proxies_comparisons_march_2023/latency95_rate.png" alt="latency95 rate" width="600" height="424" class="alignnone size-large wp-image-86209" style="display: block; margin-left: auto; margin-right: auto;" /></a></p>
  1511. <p><span style="font-weight: 400;">Here the situation starts to be a little bit more complicated. MySQL Router is the one that has the higher latency no matter what. However HAProxy and ProxySQL have an interesting behavior. HAProxy is performing better with a low number of connections, while ProxySQL is doing better when a high number of connections is in place.&nbsp;&nbsp;</span></p>
  1512. <p><span style="font-weight: 400;">This is due to the multiplexing and the very efficient way ProxySQL uses to deal with high load.</span></p>
  1513. <p><span style="font-weight: 400;">Everything has a cost:</span></p>
  1514. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/node-summary-cpu.png"><img src="http://www.tusacentral.net/joomla/images/stories/proxies_comparisons_march_2023/node-summary-cpu.png" alt="node summary cpu" width="600" height="241" class="alignnone size-large wp-image-86215" style="display: block; margin-left: auto; margin-right: auto;" /></a></p>
  1515. <p><span style="font-weight: 400;">HAProxy is definitely using less user’s CPU resources than ProxySQL or MySQL Router …</span></p>
  1516. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/node-summary-cpu-saturation.png"><img src="http://www.tusacentral.net/joomla/images/stories/proxies_comparisons_march_2023/node-summary-cpu-saturation.png" alt="node summary cpu saturation" width="600" height="238" class="alignnone size-large wp-image-86214" style="display: block; margin-left: auto; margin-right: auto;" /></a></p>
  1517. <p><span style="font-weight: 400;">.. we can also notice that HAProxy barely reaches on average the 1.5 CPU load while ProxySQL is at 2.50 and MySQL Router around 2.&nbsp;</span></p>
  1518. <p><span style="font-weight: 400;">To be honest I was expecting something like this, given ProxySQL's need to handle the connections and the other basic routing. What was instead a surprise was MySQL Router, why does it have a higher load?</span></p>
  1519. <h4><span style="font-weight: 400;">Brief summary</span></h4>
  1520. <p><span style="font-weight: 400;">This test highlights that HAProxy and ProxySQL are able to reach a level of connection higher than the slowest runner in the game (MySQL Router). It is also clear that traffic is better served under a high number of connections by ProxySQL but it requires more resources.&nbsp;</span></p>
  1521. <h2><span style="font-weight: 400;">Test 2</span></h2>
  1522. <p><i><span style="font-weight: 400;">When the going gets tough, the tough gets going</span></i></p>
  1523. <p><span style="font-weight: 400;">Well let us remove the </span><i><span style="font-weight: 400;">–rate</span></i><span style="font-weight: 400;"> limitation and see what will happen.&nbsp;</span></p>
  1524. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/events_perf.png"><img src="http://www.tusacentral.net/joomla/images/stories/proxies_comparisons_march_2023/events_perf.png" alt="events perf" width="800" height="475" class="alignnone size-large wp-image-86205" style="display: block; margin-left: auto; margin-right: auto;" /></a></p>
  1525. <p><span style="font-weight: 400;">The scenario with load changes drastically. We can see how HAProxy is able to serve the connection and allow the execution of a higher number of operations for the whole test. ProxySQL is immediately after it and is behaving quite well up to 128 threads, then it just collapses.&nbsp;</span></p>
  1526. <p><span style="font-weight: 400;">MySQL Router never takes off; it always stays below the 1k reads/second while HAProxy was able to serve 8.2k and&nbsp; ProxySQL 6.6k.</span></p>
  1527. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/latency95_perf.png"><img src="http://www.tusacentral.net/joomla/images/stories/proxies_comparisons_march_2023/latency95_perf.png" alt="latency95 perf" width="800" height="531" class="alignnone size-large wp-image-86208" style="display: block; margin-left: auto; margin-right: auto;" /></a></p>
  1528. <p><span style="font-weight: 400;">Taking a look at the Latency, we can see that HAProxy had a gradual increase as expected, while ProxySQL and MySQL Router just went up from the 256 threads on.&nbsp;</span></p>
  1529. <p><span style="font-weight: 400;">To observe that both ProxySQL and MySQL Router were not able to complete the tests with 4096 threads.</span></p>
  1530. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/node-summary-cpu-perf.png"><img src="http://www.tusacentral.net/joomla/images/stories/proxies_comparisons_march_2023/node-summary-cpu-perf.png" alt="node summary cpu perf" width="800" height="318" class="alignnone size-large wp-image-86212" style="display: block; margin-left: auto; margin-right: auto;" /></a></p>
  1531. <p><span style="font-weight: 400;">Why? HAProxy stays always below 50% cpu, no matter the increasing number of threads/connections, scaling the load very efficiently. MySQL router was almost immediately reaching the saturation point, being affected not only by the number of threads/connections but also by the number of operations, and that was not expected given we do not have a level 7 capability in MySQL Router.</span></p>
  1532. <p><span style="font-weight: 400;">Finally ProxySQL, which was working fine up to a certain limit, then it reached saturation point and was not able to serve the load. I am saying load because ProxySQL is a level 7 proxy and is aware of the content of the load. Given that on top of multiplexing, additional resource consumption was expected.&nbsp;&nbsp;&nbsp;</span></p>
  1533. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/node-summary-cpu-saturation-perf.png"><img src="http://www.tusacentral.net/joomla/images/stories/proxies_comparisons_march_2023/node-summary-cpu-saturation-perf.png" alt="node summary cpu saturation perf" width="800" height="319" class="alignnone size-large wp-image-86213" style="display: block; margin-left: auto; margin-right: auto;" /></a></p>
  1534. <p><span style="font-weight: 400;">Here we just have a clear confirmation of what already said above, with 100% cpu utilization reached by MySQL Router with just 16 threads, and ProxySQL way after at 256 threads.</span></p>
  1535. <h2><span style="font-weight: 400;">Brief Summary</span></h2>
  1536. <p><span style="font-weight: 400;">HAProxy comes up as the champion in this test, there is no doubt that it was able to scale the increasing load in connection without being affected significantly by the load generated by the requests. The lower consumption in resources also indicates the possible space for even more scaling.</span></p>
  1537. <p><span style="font-weight: 400;">ProxySQL was penalized by the limited resources, but this was the game, we have to get the most out of the few available. This test indicates that it is not optimal to use ProxySQL inside the Operator, actually it is a wrong choice if low resource and scalability is a must.&nbsp;&nbsp;&nbsp;&nbsp;</span></p>
  1538. <p><span style="font-weight: 400;">MySQL Router was never in the game. Unless a serious refactoring, MySQL Router is designed for very limited scalability, as such the only way to adopt it is to have many of them at application node level. Utilizing it close to the data nodes in a centralized position is a mistake.&nbsp;&nbsp;</span></p>
  1539. <h2><span style="font-weight: 400;">Conclusions</span></h2>
  1540. <p><span style="font-weight: 400;">I started showing an image on how the MySQL service is organized and want to close showing the variation that for me is the one to be considered the default approach:</span></p>
  1541. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/proxys_gr_comparison-haproxy.jpg"><img src="https://www.percona.com/blog/wp-content/uploads/2023/03/proxys_gr_comparison-haproxy.jpg" alt="" width="536" height="651" class="size-full wp-image-86220 aligncenter" style="display: block; margin-left: auto; margin-right: auto;" /></a></p>
  1542. <p><span style="font-weight: 400;">This to highlight that we always need to choose the right tool for the job.&nbsp;</span></p>
  1543. <p><span style="font-weight: 400;">The Proxy in architectures involving MySQL/PS/PXC is a crucial element for the scalability of the cluster, no matter if using K8s or not. It is important to choose the one that serves us better, which in some cases can be ProxySQL over HAProxy.&nbsp;</span><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/proxys_gr_comparison-haproxy.jpg"><br /></a></p>
  1544. <p><span style="font-weight: 400;">However when talking of K8s and Operators we must recognize the need to optimize the resources usage for the specific service. In that context there is no discussion about it, HAProxy is the best solution and the one we should go to.&nbsp;</span><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/proxys_gr_comparison-haproxy.jpg"><br /></a></p>
  1545. <p><span style="font-weight: 400;">My final observation is about MySQL Router (aka MySQL Proxy).&nbsp;</span></p>
  1546. <p><span style="font-weight: 400;">Unless a significant refactoring of the product at the moment it is not even close to what the other two can do. From the tests done so far, it requires a complete reshaping starting to identify why it is so subject to the load coming from the query, more than the load coming from the connections.&nbsp;&nbsp;&nbsp;</span></p>
  1547. <p><a href="https://www.percona.com/blog/wp-content/uploads/2023/03/proxys_gr_comparison-haproxy.jpg"></a></p>
  1548. <p><span style="font-weight: 400;">Great MySQL to everyone.&nbsp;</span></p>
  1549. <h2>References</h2>
  1550. <p>https://www.percona.com/blog/boosting-percona-distribution-for-mysql-operator-efficiency/</p>
  1551. <p>https://www.slideshare.net/marcotusa/my-sql-on-kubernetes-demystified</p>
  1552. <p>https://docs.haproxy.org/2.7/configuration.html</p>
  1553. <p>https://proxysql.com/documentation/</p>
  1554. <p>https://dev.mysql.com/doc/mysql-router/8.0/en/</p>
  1555. <p>&nbsp;</p>
  1556. <p>&nbsp;</p>]]></description>
  1557. <category>MySQL</category>
  1558. <pubDate>Sun, 19 Mar 2023 17:57:59 +0000</pubDate>
  1559. </item>
  1560. <item>
  1561. <title>Help! I am out of disk space!</title>
  1562. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/251-help-i-am-out-of-disk-space</link>
  1563. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/251-help-i-am-out-of-disk-space</guid>
  1564. <description><![CDATA[<p><em><span style="font-weight: 400;">How we could&nbsp; fix a nasty out of space issue leveraging the flexibility of Percona MySQL operator (PMO)&nbsp;&nbsp;<img src="http://www.tusacentral.net/joomla/images/stories/DiskSpaceFull.png" alt="DiskSpaceFull" width="350" height="208" style="float: right;" /></span></em></p>
  1565. <p><span style="font-weight: 400;">When planning a database deployment, one of the most challenging factors to consider is the amount of space we need to dedicate for Data on disk.</span></p>
  1566. <p><span style="font-weight: 400;">This is even more cumbersome when working on bare metal. Given it is definitely more difficult to add space when using this kind of solution in respect to the cloud.&nbsp;</span></p>
  1567. <p><span style="font-weight: 400;">This is it, when using cloud storage like EBS or similar it is normally easy(er) to extend volumes, which gives us the luxury to plan the space to allocate for data with a good grade of relaxation.&nbsp;</span></p>
  1568. <p><span style="font-weight: 400;">Is this also true when using a solution based on Kubernetes like Percona Operator for MySQL? Well it depends on where you run it, however if the platform you choose supports the option to extend volumes K8s per se is giving you the possibility to do so as well.</span></p>
  1569. <p><span style="font-weight: 400;">However, if it can go wrong it will, and ending up with a fully filled device with MySQL is not a fun experience.&nbsp;</span></p>
  1570. <p><span style="font-weight: 400;">As you know, on normal deployments, when mysql has no space left on the device, it simply stops working, ergo it will cause a production down event, which of course is an unfortunate event that we want to avoid at any cost.&nbsp;&nbsp;</span></p>
  1571. <p><span style="font-weight: 400;">This blog is the story of what happened, what was supposed to happen and why.&nbsp;</span></p>
  1572. <h2><span style="font-weight: 400;">The story&nbsp;</span></h2>
  1573. <p><span style="font-weight: 400;">Case was on AWS using EKS.</span></p>
  1574. <p><span style="font-weight: 400;">Given all the above, I was quite surprised when we had a case in which a deployed solution based on PMO went out of space. However we start to dig and review what was going on and why.</span></p>
  1575. <p><span style="font-weight: 400;">The first thing we did was to quickly investigate what was really taking space, that could have been an easy win if most of the space was taken by some log, but unfortunately this was not the case, data was really taking all the available space.&nbsp;</span></p>
  1576. <p><span style="font-weight: 400;">The next step was to check what storage class was used for the PVC</span></p>
  1577. <pre class="lang:sh decode:true">k get pvc
  1578. NAME                         VOLUME    CAPACITY   ACCESS MODES   STORAGECLASS
  1579. datadir-mt-cluster-1-pxc-0   pvc-&lt;snip&gt;   233Gi      RWO            io1
  1580. datadir-mt-cluster-1-pxc-1   pvc-&lt;snip&gt;   233Gi      RWO            io1
  1581. datadir-mt-cluster-1-pxc-2   pvc-&lt;snip&gt;   233Gi      RWO            io1
  1582. </pre>
  1583. <p><span style="font-weight: 400;">Ok we use the io1 SC, it is now time to check if the SC is supporting volume expansion:</span></p>
  1584. <pre class="lang:sh decode:true">kubectl describe sc io1
  1585. Name:            io1
  1586. IsDefaultClass:  No
  1587. Annotations:     kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"false"},"name":"io1"},"parameters":{"fsType":"ext4","iopsPerGB":"12","type":"io1"},"provisioner":"kubernetes.io/aws-ebs"}
  1588. ,storageclass.kubernetes.io/is-default-class=false
  1589. Provisioner:           kubernetes.io/aws-ebs
  1590. Parameters:            fsType=ext4,iopsPerGB=12,type=io1
  1591. AllowVolumeExpansion:  &lt;unset&gt; &lt;------------
  1592. MountOptions:          &lt;none&gt;
  1593. ReclaimPolicy:         Delete
  1594. VolumeBindingMode:     Immediate
  1595. Events:                &lt;none&gt;
  1596. </pre>
  1597. <p><span style="font-weight: 400;">And no is not enabled, in this case we cannot just go and expand the volume, must change the storage class settings first. </span><span style="font-weight: 400;"><br /></span><span style="font-weight: 400;">To enable volume expansion, you need to delete the storage class and enable it again.&nbsp;</span></p>
  1598. <p><span style="font-weight: 400;">Unfortunately we were unsuccessful in doing that operation, because the storage class kept staying as unset for&nbsp; ALLOWVOLUMEEXPANSION.&nbsp;</span></p>
  1599. <p><span style="font-weight: 400;">As said this is a production down event, so we cannot invest too much time in digging why it was not correctly changing the mode, we had to act quickly.&nbsp;</span></p>
  1600. <p><span style="font-weight: 400;">The only option we had to fix it was:</span></p>
  1601. <ul>
  1602. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Expand the io1 volumes from AWS console (or aws client)</span></li>
  1603. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Resize the file system&nbsp;</span></li>
  1604. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Patch any K8 file to allow K8 to correctly see the new volumes dimension&nbsp;&nbsp;</span></li>
  1605. </ul>
  1606. <p><span style="font-weight: 400;">Expanding EBS volumes from the console is trivial, just go to Volumes, select the volume you want to modify, choose modify and change the size of it with the one desired, done.&nbsp;</span></p>
  1607. <p><span style="font-weight: 400;">Once that is done connect to the Node hosting the pod which has the volume mounted like:</span></p>
  1608. <pre class="lang:sh decode:true"> k get pods -o wide|grep mysql-0
  1609. NAME                                        READY     STATUS    RESTARTS   AGE    IP            NODE            
  1610. cluster-1-pxc-0                               2/2     Running   1          11d    10.1.76.189     &lt;mynode&gt;.eu-central-1.compute.internal</pre>
  1611. <p><span style="font-weight: 400;">Then we need to get the id of the pvc to identify it on the node</span></p>
  1612. <pre class="lang:sh decode:true">k get pvc
  1613. NAME                         STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS
  1614. datadir-cluster-1-pxc-0   Bound    pvc-1678c7ee-3e50-4329-a5d8-25cd188dc0df   233Gi      RWO            io1
  1615. </pre>
  1616. <p><span style="font-weight: 400;">One note, when doing this kind of recovery with a PXC based solution, always recover node-0 first, then the others.&nbsp;&nbsp;</span></p>
  1617. <p><span style="font-weight: 400;">So we connect to &lt;mynode&gt; and identify the volume:&nbsp;</span></p>
  1618. <pre class="lang:sh decode:true">lslbk |grep pvc-1678c7ee-3e50-4329-a5d8-25cd188dc0df
  1619. nvme1n1      259:4    0  350G  0 disk /var/lib/kubelet/pods/9724a0f6-fb79-4e6b-be8d-b797062bf716/volumes/kubernetes.io~aws-ebs/pvc-1678c7ee-3e50-4329-a5d8-25cd188dc0df &lt;-----
  1620. </pre>
  1621. <p><span style="font-weight: 400;">At this point we can resize it:</span></p>
  1622. <pre class="lang:sh decode:true">root@ip-&lt;snip&gt;:/# resize2fs  /dev/nvme1n1
  1623. resize2fs 1.45.5 (07-Jan-2020)
  1624. Filesystem at /dev/nvme1n1 is mounted on /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/eu-central-1a/vol-0ab0db8ecf0293b2f; on-line resizing required
  1625. old_desc_blocks = 30, new_desc_blocks = 44
  1626. The filesystem on /dev/nvme1n1 is now 91750400 (4k) blocks long.
  1627. </pre>
  1628. <p><span style="font-weight: 400;">The good thing is that as soon as you do that the MySQL daemon see the space and will restart, however it will happen only on the current pod and K8 will still see the old dimension:</span></p>
  1629. <pre class="lang:sh decode:true">k get pv
  1630. NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                            STORAGECLASS   REASON
  1631. pvc-1678c7ee-3e50-4329-a5d8-25cd188dc0df   333Gi      RWO            Delete           Bound    pxc/datadir-cluster-1-pxc-0   io1
  1632. </pre>
  1633. <p><span style="font-weight: 400;">To allow k8 to be align with the real dimension we must patch the information stored, the command is the following:</span></p>
  1634. <pre class="lang:sh decode:true">kubectl patch pvc &lt;pvc-name&gt;  -n &lt;pvc-namespace&gt; -p '{ "spec": { "resources": { "requests": { "storage": "NEW STORAGE VALUE" }}}}'
  1635. Ie:
  1636. kubectl patch pvc datadir-cluster-1-pxc-0 -n pxc -p '{ "spec": { "resources": { "requests": { "storage": "350" }}}}'
  1637. </pre>
  1638. <p><span style="font-weight: 400;">Remember to use as pvc-name the NAME coming from </span></p>
  1639. <pre><span style="font-weight: 400;">kubectl get pvc</span><span style="font-weight: 400;">.</span></pre>
  1640. <p><span style="font-weight: 400;">Once this is done k8 will see the new volume dimension correctly.</span></p>
  1641. <p><span style="font-weight: 400;">Just repeat the process for Node-1 and Node-2 and …done the cluster is up again.</span></p>
  1642. <p><span style="font-weight: 400;">Finally do not forget to modify your custom resources file (cr.yaml) to match the new volume size. IE:</span></p>
  1643. <pre class="lang:sh decode:true">    volumeSpec:
  1644.      persistentVolumeClaim:
  1645.        storageClassName: "io1"
  1646.        resources:
  1647.          requests:
  1648.            storage: 350G
  1649. </pre>
  1650. <p><span style="font-weight: 400;">The whole process took just a few minutes, it was time now to investigate why the incident happened and why the storage class was not allowing extension in the first place.&nbsp;&nbsp;</span></p>
  1651. <p>&nbsp;</p>
  1652. <h2><span style="font-weight: 400;">Why it happened</span></h2>
  1653. <p><span style="font-weight: 400;">Well first and foremost the platform was not correctly monitored. As such there was lack of visibility about the space utilization, and no alert about disk space.&nbsp;</span></p>
  1654. <p><span style="font-weight: 400;">This was easy to solve just enabling the PMM feature in the cluster cr and set the alert in PMM once the nodes join it (see </span><a href="https://docs.percona.com/percona-monitoring-and-management/get-started/alerting.html"><span style="font-weight: 400;">https://docs.percona.com/percona-monitoring-and-management/get-started/alerting.html</span></a><span style="font-weight: 400;"> for details on how to).</span></p>
  1655. <p><span style="font-weight: 400;">The second issue was the problem with the storage class. Once we had the time to carefully review the configuration files, we identified that there was an additional tab in the SC class, which was causing k8 to ignore the directive.&nbsp;</span></p>
  1656. <p><span style="font-weight: 400;">Was suppose to be:</span></p>
  1657. <pre class="lang:sh decode:true">kind: StorageClass
  1658. apiVersion: storage.k8s.io/v1
  1659. metadata:
  1660.  name: io1
  1661.  annotations:
  1662.    storageclass.kubernetes.io/is-default-class: "false"
  1663. provisioner: kubernetes.io/aws-ebs
  1664. parameters:
  1665.  type: io1
  1666.  iopsPerGB: "12"
  1667.  fsType: ext4
  1668. allowVolumeExpansion: true &lt;----------
  1669.  
  1670. It was:
  1671. kind: StorageClass
  1672. apiVersion: storage.k8s.io/v1
  1673. metadata:
  1674.  name: io1
  1675.  annotations:
  1676.    storageclass.kubernetes.io/is-default-class: "false"
  1677. provisioner: kubernetes.io/aws-ebs
  1678. parameters:
  1679.  type: io1
  1680.  iopsPerGB: "12"
  1681.  fsType: ext4
  1682.  allowVolumeExpansion: true. &lt;---------</pre>
  1683. <p><span style="font-weight: 400;">What was concerning was the lack of error returned by the Kubernetes API, so in theory the configuration was accepted but not really validated.&nbsp;</span></p>
  1684. <p><span style="font-weight: 400;">In any case once we had fix the typo and recreated the SC, the setting for volume expansion was correctly accepted:</span></p>
  1685. <pre class="lang:sh decode:true">kubectl describe sc io1
  1686. Name:            io1
  1687. IsDefaultClass:  No
  1688. Annotations:     kubectl.kubernetes.io/last-applied-configuration={"allowVolumeExpansion":true,"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"false"},"name":"io1"},"parameters":{"fsType":"ext4","iopsPerGB":"12","type":"io1"},"provisioner":"kubernetes.io/aws-ebs"}
  1689. ,storageclass.kubernetes.io/is-default-class=false
  1690. Provisioner:           kubernetes.io/aws-ebs
  1691. Parameters:            fsType=ext4,iopsPerGB=12,type=io1
  1692. AllowVolumeExpansion:  True    
  1693. MountOptions:          &lt;none&gt;
  1694. ReclaimPolicy:         Delete
  1695. VolumeBindingMode:     Immediate
  1696. Events:                &lt;none&gt;
  1697. </pre>
  1698. <h2><span style="font-weight: 400;">What should have happened instead?</span></h2>
  1699. <p><span style="font-weight: 400;">If a proper monitoring and alerting was in place, the administrators would have the time to act and extend the volumes without downtime.&nbsp;</span></p>
  1700. <p><span style="font-weight: 400;">However, the procedure for extending volumes on K8 is not complex but also not as straightforward as you may think. My colleague Natalia Marukovich wrote this blog post (</span><a href="https://www.percona.com/blog/percona-operator-volume-expansion-without-downtime/"><span style="font-weight: 400;">https://www.percona.com/blog/percona-operator-volume-expansion-without-downtime/</span></a><span style="font-weight: 400;">)&nbsp; that gives you the step by step instructions on how to extend the volumes without downtime.&nbsp;</span></p>
  1701. <h2><span style="font-weight: 400;">Conclusions</span></h2>
  1702. <p><span style="font-weight: 400;">Using the cloud, containers, automation or more complex orchestrators like Kubernetes, do not solve all, do not prevent mistakes from happening, and more importantly do not make the right decisions for you.&nbsp;</span></p>
  1703. <p><span style="font-weight: 400;">You must set up a proper architecture that includes backup, monitoring and alerting. You must set the right alerts and act on them in time.&nbsp;</span></p>
  1704. <p><span style="font-weight: 400;">Finally automation is cool, however the devil is in the details and typos are his day to day joy. Be careful and check what you put online, do not rush it. Validate, validate validate…&nbsp;</span></p>
  1705. <p><span style="font-weight: 400;">Great stateful MySQL to all.&nbsp;</span></p>]]></description>
  1706. <category>MySQL</category>
  1707. <pubDate>Thu, 19 Jan 2023 14:11:24 +0000</pubDate>
  1708. </item>
  1709. <item>
  1710. <title>MySQL Dual password how to manage them programmatically</title>
  1711. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/250-mysql-dual-password-how-to-manage-them-programmatically</link>
  1712. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/250-mysql-dual-password-how-to-manage-them-programmatically</guid>
  1713. <description><![CDATA[<p><span style="font-weight: 400;">What is dual password in MYSQL and how it works was already covered by my colleague Brian Sumpter here (</span><a href="https://www.percona.com/blog/using-mysql-8-dual-passwords/"><span style="font-weight: 400;">https://www.percona.com/blog/using-mysql-8-dual-passwords/</span></a><span style="font-weight: 400;">).&nbsp;<img src="http://www.tusacentral.net/joomla/images/stories/rpa-cognitive-blog-img.jpg" alt="rpa cognitive blog img" width="400" height="215" style="float: right;" /></span></p>
  1714. <p><span style="font-weight: 400;">However let me do a brief recap here about it.</span></p>
  1715. <p><span style="font-weight: 400;">Dual password is the MySQL mechanism that allows you to keep two passwords active at the same time. This feature is part of a more extended set of Password management features implemented in MySQL 8 to enforce better security and secrets management, like:</span></p>
  1716. <ul>
  1717. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Internal Versus External Credentials Storage</span></li>
  1718. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Password Expiration Policy</span></li>
  1719. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Password Reuse Policy</span></li>
  1720. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Password Verification-Required Policy</span></li>
  1721. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Dual Password Support</span></li>
  1722. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Random Password Generation</span></li>
  1723. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Failed-Login Tracking and Temporary Account Locking</span></li>
  1724. </ul>
  1725. <p><span style="font-weight: 400;">The most important and requested features are the password expiration and verification policy. The problem in implementing them is the complexity of replacing passwords for accounts on very large platforms, like with thousands of applications and hundreds of MySQL servers.&nbsp;</span></p>
  1726. <p><span style="font-weight: 400;">In fact, while for a single user it is not so complex to change his own password when requested at login, for an application using thousands of sub-services it may require some time. The problem in performing the password change is that while executing the modification some services will have the updated password while others will still use the old one. Without Dual Password a segment of nodes will receive error messages in connecting creating service disruption.&nbsp;</span></p>
  1727. <p><span style="font-weight: 400;"><span style="font-weight: 400;">Now let us cover this blog topic. </span></span></p>
  1728. <p><span style="font-weight: 400;">With Dual Password it is instead possible to declare a new password keeping the old still active until the whole upgrade has been completed.&nbsp;</span></p>
  1729. <p><span style="font-weight: 400;">This highlight two very important aspects:</span></p>
  1730. <ul>
  1731. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">When automating the password update, it is better to not use a password expiration policy, but base the expiration on the completion of the new password deployment.</span></li>
  1732. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">We need to be sure the account we are changing the password to keeps the password active until we need it, and that is correctly removed when done.&nbsp;</span></li>
  1733. </ul>
  1734. <p><span style="font-weight: 400;">As you see I am focusing on the cases when we have automation and not the single interactive user update.&nbsp;</span></p>
  1735. <p><span style="font-weight: 400;">How dual password works</span></p>
  1736. <p><span style="font-weight: 400;">Let us assume we have create a user like:</span></p>
  1737. <pre class="lang:mysql decode:true">create user dualtest@'192.168.4.%' identified by 'password1';
  1738. grant all on test.* to dualtest@'192.168.4.%';
  1739. </pre>
  1740. <p><span style="font-weight: 400;">This will generate an entry in MySQL mysql.user table as:</span></p>
  1741. <pre class="lang:mysql decode:true">(root@localhost) [(none)]&gt;select user,host, plugin, authentication_string, password_last_changed,User_attributes from mysql.user where user = 'dualtest'\G
  1742. *************************** 1. row ***************************
  1743.                 user: dualtest
  1744.                 host: 192.168.4.%
  1745.               plugin: mysql_native_password
  1746. authentication_string: *668425423DB5193AF921380129F465A6425216D0
  1747. password_last_changed: 2022-11-17 08:31:37
  1748.      User_attributes: NULL
  1749. 1 row in set (0.00 sec)
  1750. </pre>
  1751. <p><span style="font-weight: 400;">At this point our user will be able to connect from any application located in the correct network and act on the </span><i><span style="font-weight: 400;">test</span></i><span style="font-weight: 400;"> schema.&nbsp;</span></p>
  1752. <p><span style="font-weight: 400;">After some time, you as application owner,will be notified by your DBA team that the user </span><i><span style="font-weight: 400;">dualtest</span></i><span style="font-weight: 400;"> is required to change the password in order to respect the security constraints.</span></p>
  1753. <p><span style="font-weight: 400;">At this point there are two options:</span></p>
  1754. <ol>
  1755. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">You have privileges&nbsp; to use Dual Password (the required dynamic privilege to use dual Password is </span><b>APPLICATION PASSWORD ADMIN</b><span style="font-weight: 400;">).</span></li>
  1756. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">You do not have the right privileges.</span></li>
  1757. </ol>
  1758. <p><span style="font-weight: 400;">In case 2 your DBA team must perform the change for you, and then they will let you know the new password.</span></p>
  1759. <p><span style="font-weight: 400;">In case 1 you can do the operation yourself.&nbsp;</span></p>
  1760. <p><span style="font-weight: 400;">In the last case what you will do is:</span><span style="font-weight: 400;"><br /></span></p>
  1761. <pre class="lang:mysql decode:true crayon-selected">ALTER USER 'dualtest'@'192.168.4.%' IDENTIFIED BY 'password2' RETAIN CURRENT PASSWORD;
  1762. </pre>
  1763. <p><span style="font-weight: 400;">Then check it is done properly:</span></p>
  1764. <pre class="lang:mysql decode:true">select user,host, plugin, authentication_string, password_last_changed,User_attributes from mysql.user where user ='dualtest' order by 1,2\G
  1765. *************************** 1. row ***************************
  1766.                 user: dualtest
  1767.                 host: 192.168.4.%
  1768.               plugin: mysql_native_password
  1769. authentication_string: *DC52755F3C09F5923046BD42AFA76BD1D80DF2E9
  1770. password_last_changed: 2022-11-17 08:46:28
  1771.      User_attributes: {"additional_password": "*668425423DB5193AF921380129F465A6425216D0"}
  1772. 1 row in set (0.00 sec)
  1773. </pre>
  1774. <p><span style="font-weight: 400;">As you can see here the OLD password has been moved to the </span><i><span style="font-weight: 400;">User_attributes</span></i><span style="font-weight: 400;"> JSON field that is used in MYSQL8 to store several values.&nbsp;</span></p>
  1775. <p><span style="font-weight: 400;">At this point you can rollout safely the password change and that change can take an hour or a week, no production impact given the applications will be able to use either of them.&nbsp;</span></p>
  1776. <p><span style="font-weight: 400;">Once the process is complete, you can ask your DBA team to remove OLD password, or do:</span></p>
  1777. <pre class="lang:mysql decode:true">ALTER USER 'dualtest'@'192.168.4.%' DISCARD OLD PASSWORD;</pre>
  1778. <p><span style="font-weight: 400;">Then check if the password has being removed properly:</span></p>
  1779. <pre class="lang:mysql decode:true">(root@localhost) [(none)]&gt;select user,host, plugin, authentication_string, password_last_changed,User_attributes from mysql.user where user ='dualtest' order by 1,2\G
  1780. *************************** 1. row ***************************
  1781.                 user: dualtest
  1782.                 host: 192.168.4.%
  1783.               plugin: mysql_native_password
  1784. authentication_string: *DC52755F3C09F5923046BD42AFA76BD1D80DF2E9
  1785. password_last_changed: 2022-11-17 08:46:28
  1786.      User_attributes: NULL
  1787. 1 row in set (0.00 sec)
  1788. </pre>
  1789. <p><span style="font-weight: 400;">If all is clean the process can be considered complete.&nbsp;</span></p>
  1790. <p><span style="font-weight: 400;">Of course all this should be automated and executed by code not by hand high level it should be more or less like this:</span></p>
  1791. <pre class="lang:sh decode:true">{}Input new password  
  1792. - Check for additional_password in User_attributes in mysql.user
  1793. &lt;&gt; If no value you can proceed otherwise exit (another change is in place)
  1794. - Read and store authentication_string for the user you need to change password
  1795. - Change current password with: Alter user ... RETAIN CURRENT PASSWORD
  1796. - Check for additional_password in User_attributes in mysql.user
  1797. &lt;&gt; If value is present and match the password stored then you can proceed otherwise exit given there is an error in Dual Password or the passwords are different
  1798. - Run update on all application nodes, and verify new password on each application node
  1799. &lt;&gt; At regular interval check the number of completed changes and check the additional_password in User_attributes in mysql.user to be sure it is still there
  1800. [] When all application nodes are up to date
  1801. &lt;&gt; If verification is successful 100%
  1802. - Remove OLD password with: ALTER USER ... DISCARD OLD PASSWORD;
  1803. - Check for additional_password in User_attributes in mysql.user
  1804. &lt;&gt; If no value is present close with OK otherwise report Error for password not removed
  1805. () complete
  1806. </pre>
  1807. <h2><span style="font-weight: 400;">Conclusion</span></h2>
  1808. <p><span style="font-weight: 400;">As also Brian mentioned, those are the small things that could make the difference when in large deployments and enterprise environments. Security is a topic that very often is underestimated in small companies or start-ups, but that is wrong, security operations like password rotation are crucial for your safety.&nbsp;</span></p>
  1809. <p><span style="font-weight: 400;">It is nice to see that MySQL is finally adopting simple but effective steps to help DBAs to implement proper procedures without causing production impact and without the need to become too creative.&nbsp;</span></p>
  1810. <h2>&nbsp;</h2>
  1811. <h2><span style="font-weight: 400;">References&nbsp;</span></h2>
  1812. <p><a href="https://www.percona.com/blog/using-mysql-8-dual-passwords/"><span style="font-weight: 400;">https://www.percona.com/blog/using-mysql-8-dual-passwords/</span></a></p>
  1813. <p><a href="https://dev.mysql.com/doc/refman/8.0/en/password-management.html#dual-passwords"><span style="font-weight: 400;">https://dev.mysql.com/doc/refman/8.0/en/password-management.html#dual-passwords</span></a></p>]]></description>
  1814. <category>MySQL</category>
  1815. <pubDate>Thu, 17 Nov 2022 16:26:45 +0000</pubDate>
  1816. </item>
  1817. <item>
  1818. <title>ProxySQL support for MySQL caching_sha2_password</title>
  1819. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/249-proxysql-support-for-mysql-caching-sha2-password</link>
  1820. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/249-proxysql-support-for-mysql-caching-sha2-password</guid>
  1821. <description><![CDATA[<p><span style="font-weight: 400;">In our time, every day we use dozens if not hundreds of applications connecting to some kind of data repository. This simple step is normally executed over the network and given&nbsp;so, it is subject to possible sniffing with all the possible related consequences.<img src="http://www.tusacentral.net/joomla/images/stories/proxysql/brokenlock.png" alt="brokenlock" style="float: right;" /><br style="clear: left;" /></span></p>
  1822. <p><span style="font-weight: 400;">Given that it is normally better to protect your connection using data encryption like SSL, or at the minimum, make the information you pass to connect less easy to be intercepted.&nbsp;</span></p>
  1823. <p><span style="font-weight: 400;">At the same time it is best practice to not store connection credential in clear text, not even inside a table in your database. Doing that is the equivalent of writing your password over a sticky note on your desk. Not a good idea.</span></p>
  1824. <p><span style="font-weight: 400;">The main options are instead in either transforming the passwords to be less identifiable like hashing or to store the information in an external centralized vault.&nbsp;</span></p>
  1825. <p><span style="font-weight: 400;">In MySQL the passwords are transformed in order to not be clear text, and several different plugins are used to authenticate the user. From version 8 MySQL uses </span><i><span style="font-weight: 400;">caching_sha2_password</span></i><span style="font-weight: 400;"> as default authentication plugin. The </span><i><span style="font-weight: 400;">caching_sha2_password</span></i><span style="font-weight: 400;"> and </span><i><span style="font-weight: 400;">sha256_password</span></i><span style="font-weight: 400;"> authentication plugins provide more secure password encryption than the </span><i><span style="font-weight: 400;">mysql_native_password</span></i><span style="font-weight: 400;"> plugin, and </span><i><span style="font-weight: 400;">caching_sha2_password</span></i><span style="font-weight: 400;"> provides better performance than </span><i><span style="font-weight: 400;">sha256_password</span></i><span style="font-weight: 400;">. Due to these superior security and performance characteristics of </span><i><span style="font-weight: 400;">caching_sha2_password</span></i><span style="font-weight: 400;">, it is as of MySQL 8.0 the preferred authentication plugin, and is also the default authentication plugin rather than mysql_native_password.</span></p>
  1826. <p><span style="font-weight: 400;">In this regard recently I got the same question again “Can we use ProxySQL with MySQL 8 authorization mechanism?”, and I decided it was time to write this short blog post.</span></p>
  1827. <p><span style="font-weight: 400;">The short answer is “Yes you can”, however do not expect to have full </span><i><span style="font-weight: 400;">caching_sha2_password</span></i><span style="font-weight: 400;"> support.</span></p>
  1828. <p><span style="font-weight: 400;">This is because ProxySQL does not fully support the </span><i><span style="font-weight: 400;">caching_sha2_password </span></i><span style="font-weight: 400;">mechanism internally and given that a “trick” must be used.&nbsp;</span></p>
  1829. <p><span style="font-weight: 400;">So, what should we do when using MySQL 8 and ProxySQL?&nbsp;</span></p>
  1830. <p><span style="font-weight: 400;">In the text below we will see what can be done to continue to use ProxySQL with MySQL and Percona server 8.&nbsp;</span></p>
  1831. <p><span style="font-weight: 400;">Note that I have used the Percona </span><i><span style="font-weight: 400;">proxysql_admin</span></i><span style="font-weight: 400;"> tool to manage the users except in the last case. <br />Percona </span><i><span style="font-weight: 400;">proxysql_admin</span></i><span style="font-weight: 400;"> tool is a nice tool that helps you to manage ProxySQL and in regard to user it also manage and synchronize users from your Percona or MySQL&nbsp;&nbsp;</span></p>
  1832. <p><span style="font-weight: 400;">In the following examples:</span></p>
  1833. <p><span style="font-weight: 400;">Proxysql is on 192.168.4.191</span></p>
  1834. <p><span style="font-weight: 400;">User name/password is msandbox/msandbox</span></p>
  1835. <h2><span style="font-weight: 400;">Using hashing.</span></h2>
  1836. <p><span style="font-weight: 400;">By default MySQL comes with </span><i><span style="font-weight: 400;">caching_sha2_password</span></i><span style="font-weight: 400;"> as such if I create a user names </span><i><span style="font-weight: 400;">msandbox</span></i><span style="font-weight: 400;"> I will have:</span><span style="font-weight: 400;"><br /></span></p>
  1837. <pre class="lang:mysql decode:true">DC1-1(root@localhost) [(none)]&gt;select user,host, authentication_string,plugin from mysql.user order by 1,2;
  1838. +----------------------------+--------------------+------------------------------------------------------------------------+-----------------------+
  1839. | user                       | host               | authentication_string                                                  | plugin                |
  1840. +----------------------------+--------------------+------------------------------------------------------------------------+-----------------------+
  1841. | msandbox                   | %                  | $A$005$Z[z@l'O%[Q5t^ EKJDgxjWXJjDpDEUv91oL7Hoh/0NydTeCzpV.aI06C9.      | caching_sha2_password |      &lt;---- this user    
  1842. +----------------------------+--------------------+------------------------------------------------------------------------+-----------------------+
  1843. </pre>
  1844. <p><span style="font-weight: 400;">Then I use percona_scheduler_admin to sync the users:</span></p>
  1845. <pre class="lang:mysql decode:true">./percona-scheduler-admin --config-file=config.toml --syncusers&nbsp;
  1846. Syncing user accounts from PXC(192.168.4.205:3306) to ProxySQL
  1847. Removing existing user from ProxySQL: msandbox
  1848. Adding user to ProxySQL: msandbox
  1849.  
  1850. Synced PXC users to the ProxySQL database!
  1851.  
  1852. mysql&gt; select * from mysql_users ;
  1853. +------------+------------------------------------------------------------------------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+------------+-----------------------------+
  1854. | username &nbsp; | password &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | active | use_ssl | default_hostgroup | default_schema | schema_locked | transaction_persistent | fast_forward | backend | frontend | max_connections | attributes | comment &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |
  1855. +------------+------------------------------------------------------------------------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+------------+-----------------------------+
  1856. | msandbox &nbsp; | $A$005$Z[z@l'O%[Q5t^ EKJDgxjWXJjDpDEUv91oL7Hoh/0NydTeCzpV.aI06C9       | 1&nbsp; &nbsp; &nbsp; | 0 &nbsp; &nbsp; &nbsp; | 100 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | NULL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 1 &nbsp; &nbsp; &nbsp; | 1&nbsp; &nbsp; &nbsp; &nbsp; | 10000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |
  1857. +------------+------------------------------------------------------------------------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+------------+-----------------------------+</pre>
  1858. <p><span style="font-weight: 400;">And set the query rules:</span></p>
  1859. <pre class="lang:mysql decode:true">insert into mysql_query_rules (rule_id,proxy_port,username,destination_hostgroup,active,retries,match_digest,apply) values(1048,6033,'msandbox',100,1,3,'^SELECT.*FOR UPDATE',1);
  1860. insert into mysql_query_rules (rule_id,proxy_port,username,destination_hostgroup,active,retries,match_digest,apply) values(1050,6033,'msandbox',101,1,3,'^SELECT.*$',1);
  1861.  
  1862. load mysql query rules to run;save mysql query rules to disk;
  1863. </pre>
  1864. <p><span style="font-weight: 400;">Now I try to connect passing by ProxySQL:</span></p>
  1865. <pre class="lang:sh decode:true"># mysql -h 192.168.4.191 -P6033  -umsandbox -pmsandbox
  1866. ERROR 1045 (28000): ProxySQL Error: Access denied for user 'msandbox'@'192.168.4.191' (using password: YES)
  1867. </pre>
  1868. <p><span style="font-weight: 400;">My account will fail to connect given failed authentication.</span></p>
  1869. <p><span style="font-weight: 400;">To fix this I need to drop the user and recreate it with a different authentication plugin in my MySQL server:</span></p>
  1870. <pre class="lang:mysql decode:true">drop user msandbox@'%';
  1871. create user 'msandbox'@'%' identified with mysql_native_password  BY 'msandbox';
  1872. grant select on *.* to 'msandbox'@'%';
  1873.  
  1874. select user,host, authentication_string,plugin from mysql.user order by 1,2;
  1875. +----------+--------------------+-------------------------------------------+-----------------------+
  1876. | user     | host               | authentication_string                     | plugin                |
  1877. +----------+--------------------+-------------------------------------------+-----------------------+
  1878. | msandbox | %                  | *6C387FC3893DBA1E3BA155E74754DA6682D04747 | mysql_native_password |
  1879. +----------+--------------------+-------------------------------------------+-----------------------+
  1880. </pre>
  1881. <p><span style="font-weight: 400;">At this point I can re-run </span></p>
  1882. <pre class="lang:sh decode:true">./percona-scheduler-admin --config-file=config.toml --syncusers</pre>
  1883. <p><span style="font-weight: 400;">if I try to connect again:</span><span style="font-weight: 400;"><br /></span></p>
  1884. <pre class="lang:mysql decode:true"># mysql -h 192.168.4.191 -P6033&nbsp; -umsandbox -pmsandbox
  1885. mysql: [Warning] Using a password on the command line interface can be insecure.
  1886. Welcome to the MySQL monitor.&nbsp; Commands end with ; or \g.
  1887. Your MySQL connection id is 6708563
  1888. Server version: 8.0.28 (ProxySQL). &lt;---------------------------- Connecting to proxysql
  1889.  
  1890. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  1891.  
  1892. Oracle is a registered trademark of Oracle Corporation and/or its
  1893. affiliates. Other names may be trademarks of their respective
  1894. owners.
  1895.  
  1896. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  1897.  
  1898. mysql&gt; show global variables like 'version%';
  1899. +-------------------------+------------------------------------------------------------------------------------+
  1900. | Variable_name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Value&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |
  1901. +-------------------------+------------------------------------------------------------------------------------+
  1902. | version &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 8.0.25-15.1 &nbsp; &nbsp; &nbsp; &nbsp; &lt;--- Percona/MySQL version &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |
  1903. | version_comment &nbsp; &nbsp; &nbsp; &nbsp; | Percona XtraDB Cluster binary (GPL) 8.0.25, Revision 8638bb0, WSREP version 26.4.3 |
  1904. | version_compile_machine | x86_64 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |
  1905. | version_compile_os&nbsp; &nbsp; &nbsp; | Linux&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |
  1906. | version_compile_zlib&nbsp; &nbsp; | 1.2.11 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |
  1907. | version_suffix&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | .1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |
  1908. +-------------------------+------------------------------------------------------------------------------------+
  1909. 6 rows in set (0.02 sec)</pre>
  1910. <p><span style="font-weight: 400;">This is the only way to keep the password hashed in MySQL and in ProxySQL.</span></p>
  1911. <h2><span style="font-weight: 400;">Not using Hashing</span></h2>
  1912. <p><span style="font-weight: 400;">What if you cannot use mysql_native_password for the password in your MySQL server?</span></p>
  1913. <p><span style="font-weight: 400;">There is a way to still connect, however I do not recommend it given for me is highly insecure, but for completeness I am going to illustrate it.</span></p>
  1914. <p><span style="font-weight: 400;">First of all disable password hashing in Proxysql:</span></p>
  1915. <pre class="lang:mysql decode:true">update global_variables set Variable_Value='false' where Variable_name='admin-hash_passwords'; </pre>
  1916. <p><span style="font-weight: 400;">At this point instead sync the user you can locally create the user like:</span></p>
  1917. <pre class="lang:mysql decode:true">insert into mysql_users (username,password,active,default_hostgroup,default_schema,transaction_persistent,comment) values ('msandbox','msandbox',1,100,'mysql',1,'generic test for security');&nbsp;
  1918. mysql&gt; select * from runtime_mysql_users where username ='msandbox';&nbsp;
  1919. +----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+------------+---------------------------+
  1920. | username | password | active | use_ssl | default_hostgroup | default_schema | schema_locked | transaction_persistent | fast_forward | backend | frontend | max_connections | attributes | comment &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |
  1921. +----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+------------+---------------------------+
  1922. | msandbox | msandbox | 1&nbsp; &nbsp; &nbsp; | 0 &nbsp; &nbsp; &nbsp; | 100 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | mysql&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 1 &nbsp; &nbsp; &nbsp; | 0&nbsp; &nbsp; &nbsp; &nbsp; | 10000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | generic test for security |
  1923. | msandbox | msandbox | 1&nbsp; &nbsp; &nbsp; | 0 &nbsp; &nbsp; &nbsp; | 100 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | mysql&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0 &nbsp; &nbsp; &nbsp; | 1&nbsp; &nbsp; &nbsp; &nbsp; | 10000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | generic test for security |
  1924. +----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+------------+---------------------------+</pre>
  1925. <p><span style="font-weight: 400;">As you can see doing that will prevent the password to be hashed and instead it will be clear text.</span><span style="font-weight: 400;"></span></p>
  1926. <p><span style="font-weight: 400;">At this point you will be able to connect to MySQL 8 using the caching_sha2_password, but the password is visible in ProxySQL.</span></p>
  1927. <p><span style="font-weight: 400;">Let me repeat, I DO NOT recommend using it this way, because for me it is highly insecure.&nbsp;</span></p>
  1928. <p>&nbsp;</p>
  1929. <h1><span style="font-weight: 400;">Conclusion</span></h1>
  1930. <p><span style="font-weight: 400;">While it is still possible to configure your user in MySQL to connect using ProxySQL, it is obvious that we have a gap in the way ProxySQL supports security.&nbsp;</span></p>
  1931. <p><span style="font-weight: 400;">The hope is that this gap will be filled soon by the ProxySQL development team, also if looking to the past issues this seems pending from years now.&nbsp;</span></p>
  1932. <h1><span style="font-weight: 400;">References</span></h1>
  1933. <p class="p1"><span class="s1"><a href="https://proxysql.com/documentation/mysql-8-0/">https://proxysql.com/documentation/mysql-8-0/</a></span></p>
  1934. <p class="p1"><span class="s1"><a href="https://github.com/sysown/proxysql/issues/2580">https://github.com/sysown/proxysql/issues/2580</a></span></p>
  1935. <p class="p2"><span class="s2">https://www.percona.com/blog/upgrade-your-libraries-authentication-plugin-caching_sha2_password-cannot-be-loaded/</span></p>]]></description>
  1936. <category>MySQL</category>
  1937. <pubDate>Thu, 03 Nov 2022 13:47:19 +0000</pubDate>
  1938. </item>
  1939. <item>
  1940. <title>Zero impact on index creation with Aurora 3</title>
  1941. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/248-zero-impact-on-index-creation-with-aurora-3</link>
  1942. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/248-zero-impact-on-index-creation-with-aurora-3</guid>
  1943. <description><![CDATA[<p><span style="font-weight: 400;"><span style="font-weight: 400;"><img src="http://www.tusacentral.net/joomla/images/stories/ddl/aurora_ddl_notes.jpeg" alt="aurora ddl notes" style="float: right;" /></span>Last quarter of 2021 AWS released Aurora version 3. This new version aligns Aurora with the latest MySQL 8 version porting many of the advantages MySQL 8 has over previous versions.</span></p>
  1944. <p><span style="font-weight: 400;">While this brings a lot of new interesting features for Aurora, what we are going to cover here is to see how DDLs behave when using the ONLINE option. With a quick comparison with what happens in MySQL 8 standard and with Group Replication.&nbsp;</span></p>
  1945. <h2><span style="font-weight: 400;">Tests</span></h2>
  1946. <p><span style="font-weight: 400;">All tests were run on an Aurora instance r6g.large with secondary availability zone.<br /></span><span style="font-weight: 400;">The test was composed by:</span></p>
  1947. <p><span style="font-weight: 400;">&nbsp; &nbsp; &nbsp; &nbsp; 4 connections</span></p>
  1948. <ul>
  1949. <li style="list-style-type: none;">
  1950. <ul>
  1951. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">#1 to perform ddl</span></li>
  1952. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">#2 to perform insert data in the table I am altering</span></li>
  1953. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">#3 to perform insert data on a different table&nbsp;</span></li>
  1954. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">#4 checking the other node operations</span></li>
  1955. </ul>
  1956. </li>
  1957. </ul>
  1958. <p><span style="font-weight: 400;">In the Aurora instance, a sysbench schema with 10 tables and 5 million rows was created, just to get a bit of traffic. While the test table with 5ml rows as well was:</span><span style="font-weight: 400;"><br /></span></p>
  1959. <pre class="lang:mysql decode:true">CREATE TABLE `windmills_test` (
  1960.  `id` bigint NOT NULL AUTO_INCREMENT,
  1961.  `uuid` char(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  1962.  `millid` smallint NOT NULL,
  1963.  `kwatts_s` int NOT NULL,
  1964.  `date` date NOT NULL,
  1965.  `location` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  1966.  `active` tinyint NOT NULL DEFAULT '1',
  1967.  `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  1968.  `strrecordtype` char(3) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  1969.  PRIMARY KEY (`id`),
  1970.  KEY `IDX_millid` (`millid`,`active`),
  1971.  KEY `IDX_active` (`id`,`active`),
  1972.  KEY `kuuid_x` (`uuid`),
  1973.  KEY `millid_x` (`millid`),
  1974.  KEY `active_x` (`active`),
  1975.  KEY `idx_1` (`uuid`,`active`)
  1976. ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin ROW_FORMAT=DYNAMIC
  1977. </pre>
  1978. <p><span style="font-weight: 400;">The executed commands:</span></p>
  1979. <pre class="lang:sh decode:true">Connection 1:
  1980.    ALTER TABLE windmills_test ADD INDEX idx_1 (`uuid`,`active`), ALGORITHM=INPLACE, LOCK=NONE;
  1981.    ALTER TABLE windmills_test drop INDEX idx_1, ALGORITHM=INPLACE;
  1982.    
  1983. Connection 2:
  1984. while [ 1 = 1 ];do da=$(date +'%s.%3N');mysql --defaults-file=./my.cnf -D windmills_large -e "insert into windmills_test  select null,uuid,millid,kwatts_s,date,location,active,time,strrecordtype from windmills4 limit 1;" -e "select count(*) from windmills_large.windmills_test;" &gt; /dev/null;db=$(date +'%s.%3N'); echo "$(echo "($db - $da)"|bc)";sleep 1;done
  1985.  
  1986. Connection 3:
  1987. while [ 1 = 1 ];do da=$(date +'%s.%3N');mysql --defaults-file=./my.cnf -D windmills_large -e "insert into windmills3  select null,uuid,millid,kwatts_s,date,location,active,time,strrecordtype from windmills4 limit 1;" -e "select count(*) from windmills_large.windmills_test;" &gt; /dev/null;db=$(date +'%s.%3N'); echo "$(echo "($db - $da)"|bc)";sleep 1;done
  1988.  
  1989. Connections 4:
  1990.     while [ 1 = 1 ];do echo "$(date +'%T.%3N')";mysql --defaults-file=./my.cnf -h &lt;secondary aurora instance&gt; -D windmills_large -e "show full processlist;"|egrep -i -e "(windmills_test|windmills_large)"|grep -i -v localhost;sleep 1;done
  1991.    
  1992. </pre>
  1993. <p>Operations:<br />1) start inserts from connections<br />2) start commands in connections 4 - 5 on the other nodes<br />3) execute: <span style="background-color: #f4f4f4; font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 12.8px;">DC1-1(root@localhost) [windmills_large]&gt;ALTER TABLE windmills_test ADD INDEX idx_1 (`uuid`,`active`), ALGORITHM=INPLACE, LOCK=NONE;</span></p>
  1994. <p><span style="font-weight: 400;">With this, what I was looking to capture is the operation impact in doing a common action as creating an Index. My desired expectation is to have no impact when doing operations that are declared “ONLINE” such as creating an index, as well as data consistency between nodes.&nbsp;</span></p>
  1995. <p><span style="font-weight: 400;">Let us see what happened…</span></p>
  1996. <h2><span style="font-weight: 400;">Results</span></h2>
  1997. <p><span style="font-weight: 400;">While running the insert in the same table, performing the alter:</span></p>
  1998. <pre class="lang:mysql decode:true">mysql&gt;  ALTER TABLE windmills_test ADD INDEX idx_1 (`uuid`,`active`), ALGORITHM=INPLACE, LOCK=NONE;
  1999. Query OK, 0 rows affected (16.51 sec)
  2000. Records: 0  Duplicates: 0  Warnings: 0
  2001. </pre>
  2002. <p><span style="font-weight: 400;">Is NOT stopping the operation in the same table or any other table in the Aurora instance.</span></p>
  2003. <p><span style="font-weight: 400;">We can only identify a minimal performance impact:</span></p>
  2004. <pre class="lang:sh decode:true">[root@ip-10-0-0-11 tmp]# while [ 1 = 1 ];do da=$(date +'%s.%3N');mysql --defaults-file=./my.cnf -D windmills_large -e "insert into windmills_test  select null,uuid,millid,kwatts_s,date,location,active,time,strrecordtype from windmills4 limit 1;" -e "select count(*) from windmills_large.windmills_test;" &gt; /dev/null;db=$(date +'%s.%3N'); echo "$(echo "($db - $da)"|bc)";sleep 1;done
  2005. .347
  2006. .283
  2007. .278
  2008. .297
  2009. .291
  2010. .317
  2011. .686  ← start
  2012. &lt;Snip&gt;
  2013. .512  ← end
  2014. .278
  2015. .284
  2016. .279
  2017. </pre>
  2018. <p><span style="font-weight: 400;">The secondary node is not affected at all, and this is because Aurora managed at storage level the data replication. Given that there is no such thing as Apply from Relaylog, as we have in standard MySQL asynchronous or data replicated with Group Replication.&nbsp;&nbsp;</span></p>
  2019. <p><span style="font-weight: 400;">The result is that in Aurora 3, we can have zero impact index (or any other ONLINE/INSTANT) operation, with this I include the data replicated in the other instances for High Availability.&nbsp;</span></p>
  2020. <p><span style="font-weight: 400;">If we compare this with Group replication (see <a href="https://www.percona.com/blog/online-ddl-with-group-replication-in-mysql-8-0-27/">blog</a>):</span></p>
  2021. <pre class="lang:sh decode:true">                                GR         Aurora 3
  2022. Time on hold for insert for altering table   ~0.217 sec   ~0.523 sec
  2023. Time on hold for insert for another table   ~0.211 sec   ~0.205 sec
  2024. </pre>
  2025. <p><span style="font-weight: 400;">However, keep in mind that MySQL with Group Replication will still need to apply the data on the Secondaries. This means that if your alter was taking 10 hours to build the index, the Secondary nodes will be misaligned with the Source for approximately another 10 hours.&nbsp;</span></p>
  2026. <p><span style="font-weight: 400;">With Aurora 3 or with PXC, changes will be there when Source has completed the operation.&nbsp;&nbsp;&nbsp;&nbsp;</span></p>
  2027. <p><span style="font-weight: 400;">What about Percona XtraDB Cluster (PXC)? Well, with PXC we have a different scenario:</span></p>
  2028. <pre class="lang:sh decode:true">                               PXC(NBO)     Aurora 3
  2029. Time on hold for insert for altering table   ~120 sec      ~0.523 sec
  2030. Time on hold for insert for another table   ~25  sec      ~0.205 sec</pre>
  2031. <p><span style="font-weight: 400;">We will have a higher impact while doing the Alter operation, but the data will be on all nodes at the same time maintaining a high level of consistency in the cluster.&nbsp;</span></p>
  2032. <h2><span style="font-weight: 400;">Conclusion</span></h2>
  2033. <p><span style="font-weight: 400;">Aurora is not for all use, and not for all budgets, however it has some very good aspects like the one we have just seen. The Difference between standard MySQL and Aurora is not in the time of holding/locking (aka operation impact), but on the HA aspects. If I have my data/structure on all my Secondary at the same time of the Source, I will feel much more comfortable, than having to wait an additional T time.&nbsp;</span></p>
  2034. <p><span style="font-weight: 400;">This is why PXC in that case is a better alternative if you can afford locking time, if not, well Aurora 3 is your solution, just do your math properly and be conservative with the instance resources.&nbsp;</span></p>
  2035. <p>&nbsp;</p>]]></description>
  2036. <category>MySQL</category>
  2037. <pubDate>Wed, 20 Apr 2022 12:05:56 +0000</pubDate>
  2038. </item>
  2039. <item>
  2040. <title>A face to face with semi-synchronous replication</title>
  2041. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/247-a-face-to-face-with-semi-synchronous-replication</link>
  2042. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/247-a-face-to-face-with-semi-synchronous-replication</guid>
  2043. <description><![CDATA[<p><a href="http://www.tusacentral.net/joomla/images/stories/semi-sync/face_to_face.jpeg"><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/face_to_face.jpeg" alt="" width="300" height="212" class="size-medium wp-image-80671 alignright" style="float: right;" /></a></p>
  2044. <p><span style="font-weight: 400;">Last month I performed a review of the Percona Operator for MySQL Server (<a href="https://www.percona.com/doc/kubernetes-operator-for-mysql/ps/index.html">https://www.percona.com/doc/kubernetes-operator-for-mysql/ps/index.html</a>) which is still Alpha.&nbsp; That operator is based on Percona Server and uses standard asynchronous replication, with the option to activate semi-synchronous&nbsp; replication to gain higher levels of data consistency between nodes.&nbsp;</span></p>
  2045. <p><span style="font-weight: 400;">The whole solution is composed as:</span></p>
  2046. <p><a href="https://www.percona.com/blog/wp-content/uploads/2022/04/operator.svg"><img src="https://www.percona.com/blog/wp-content/uploads/2022/04/operator.svg" alt="" width="499" height="409" class="alignnone wp-image-80663" /></a></p>
  2047. <p><span style="font-weight: 400;">Additionally, Orchestrator (</span><a href="https://github.com/openark/orchestrator"><span style="font-weight: 400;">https://github.com/openark/orchestrator</span></a><span style="font-weight: 400;">) is used to manage the topology and the settings to enable on the replica nodes, the semi-synchronous flag if required.<br /></span><span style="font-weight: 400;">While we have not too much to say when using standard Asynchronous replication, I want to spend two words on the needs and expectations on the semi-synchronous (semi-sync) solution.&nbsp;</span></p>
  2048. <h2><span style="font-weight: 400;">A look into semi-synchronous</span></h2>
  2049. <p><span style="font-weight: 400;">Difference between Async and Semi-sync.<br /></span>Asynchronous:</p>
  2050. <p><a href="http://www.tusacentral.net/joomla/images/stories/semi-sync/async-replication-diagram.png"><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/async-replication-diagram.png" alt="" width="725" height="304" class="alignnone size-full wp-image-80662" /></a></p>
  2051. <p><span style="font-weight: 400;">The above diagram represents the standard asynchronous replication. This method is expected by design, to have transactions committed on the Source that are not present on the Replicas. The Replica is supposed to </span><i><span style="font-weight: 400;">catch-up</span></i><span style="font-weight: 400;"> when possible.&nbsp;&nbsp;&nbsp;</span></p>
  2052. <p><span style="font-weight: 400;">It is also important to understand that there are two steps in replication:</span></p>
  2053. <ul>
  2054. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Data copy, which is normally very fast. The Data is copied from the binlog of the Source to the relay log on the Replica (IO_Thread).</span></li>
  2055. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Data apply, where the data is read from the relay log on the Replica node and written inside the database itself (SQL_Thread). This step is normally the bottleneck and while there are some parameters to tune, the efficiency to apply transactions depends on many factors including schema design.&nbsp;</span></li>
  2056. </ul>
  2057. <p><span style="font-weight: 400;">Production deployments that utilize the Asynchronous solution are typically designed to manage the possible inconsistent scenario given data on Source is not supposed to be on Replica at commit. At the same time the level of High Availability assigned to this solution is lower than the one we normally obtain with (virtually-)synchronous replication, given we may need to wait for the Replicare to catch-up the gap accumulated in the relay-logs before performing the fail-over.</span></p>
  2058. <p>Semi-sync:</p>
  2059. <p><a href="http://www.tusacentral.net/joomla/images/stories/semi-sync/semisync-replication-diagram.png"><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/semisync-replication-diagram.png" alt="" width="725" height="396" class="alignnone size-full wp-image-80665" /></a></p>
  2060. <p><span style="font-weight: 400;">The above diagram represents the Semi-sync replication method.The introduction of semi-sync adds a checking step on the Source before it returns the acknowledgement to the client.<br /></span><span style="font-weight: 400;">This step happens at the moment of the data-copy, so when the data is copied from the Binary-log on Source to the Relay-log on Replica.&nbsp;</span></p>
  2061. <p><span style="font-weight: 400;">This is important, there is NO mechanism to ensure a more resilient or efficient data replication, there is only an additional step, that tells the Source to wait a given amount of time for an answer from N replicas, and then return the acknowledgement or timeout and return to the client no matter what.&nbsp;</span></p>
  2062. <p><span style="font-weight: 400;">This mechanism is introducing a </span><i><span style="font-weight: 400;">possible</span></i><span style="font-weight: 400;"> significant delay in the service, without giving the 100% guarantee of data consistency.&nbsp;</span></p>
  2063. <p><span style="font-weight: 400;">In terms of </span><i><span style="font-weight: 400;">availability</span></i><span style="font-weight: 400;"> of the service, when in presence of high load, this method may lead the Source to stop serving the request while waiting for acknowledgements, significantly reducing the availability of the service itself.&nbsp;&nbsp;&nbsp;</span></p>
  2064. <p><span style="font-weight: 400;">At the same time only acceptable settings for rpl_semi_sync_source_wait_point is AFTER_SYNC (default) because:&nbsp; </span><i><span style="font-weight: 400;">In the event of source failure, all transactions committed on the source have been replicated to the replica (saved to its relay log). An unexpected exit of the source server and failover to the replica is lossless because the replica is up to date.</span></i></p>
  2065. <p><span style="font-weight: 400;">All clear? No? Let me simplify the thing.&nbsp;</span></p>
  2066. <ul>
  2067. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">In standard replication you have two moments (I am simplifying)</span>
  2068. <ul>
  2069. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Copy data from Source to Replica</span></li>
  2070. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Apply data in the Replica node</span></li>
  2071. </ul>
  2072. </li>
  2073. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">There is no certification on the data applied about its consistency with the Source</span></li>
  2074. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">With asynchronous the Source task is to write data in the binlog and forget</span></li>
  2075. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">With semi-sync the Source writes the data on binlog and waits </span><b><i>T</i></b><span style="font-weight: 400;"> seconds to receive </span><i><span style="font-weight: 400;">acknowledgement</span></i><span style="font-weight: 400;"> from </span><b><i>N</i></b><span style="font-weight: 400;"> servers about them having received the data.</span></li>
  2076. </ul>
  2077. <p><span style="font-weight: 400;">To enable semi-sync you follow these steps:&nbsp; </span><a href="https://dev.mysql.com/doc/refman/8.0/en/replication-semisync-installation.html"><span style="font-weight: 400;">https://dev.mysql.com/doc/refman/8.0/en/replication-semisync-installation.html</span></a><span style="font-weight: 400;"></span></p>
  2078. <p><span style="font-weight: 400;">In short:</span></p>
  2079. <ul>
  2080. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Register the plugins</span></li>
  2081. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Enable Source rpl_semi_sync_source_enabled=1</span></li>
  2082. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Enable Replica rpl_semi_sync_replica_enabled = 1</span>
  2083. <ul>
  2084. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">If replication is already running STOP/START REPLICA IO_THREAD</span></li>
  2085. </ul>
  2086. </li>
  2087. </ul>
  2088. <p><span style="font-weight: 400;">And here starts the fun, be ready for many “</span><i><span style="font-weight: 400;">wait whaaat?”</span></i><span style="font-weight: 400;">.&nbsp;</span></p>
  2089. <p><span style="font-weight: 400;">What is the T and N I have just mentioned above?</span></p>
  2090. <p><span style="font-weight: 400;">Well the T is a timeout that you can set to avoid having the source wait forever for the Replica acknowledgement. The default is 10 seconds. What happens if the Source waits for more than the timeout?&nbsp; <i><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/wait_whaat.jpeg" alt="" width="115" height="79" class="wp-image-80666 alignright" style="float: right;" /></i><br /></span><b><i>rpl_semi_sync_source_timeout</i></b><i><span style="font-weight: 400;"> controls how long the source waits on a commit for acknowledgment from a replica before timing out and </span></i><b><i>reverting to asynchronous replication</i></b><i><span style="font-weight: 400;">.</span></i></p>
  2091. <p><span style="font-weight: 400;">Careful of the wording here! The manual says </span><b>SOURCE</b><span style="font-weight: 400;">, so it is not that MySQL revert to asynchronous, by transaction or connection, </span><span style="font-weight: 400;">it is for the <strong>whole server</strong>.</span></p>
  2092. <p><span style="font-weight: 400;">Now analyzing the work-log (see </span><a href="https://dev.mysql.com/worklog/task/?id=1720"><span style="font-weight: 400;">https://dev.mysql.com/worklog/task/?id=1720</span></a><span style="font-weight: 400;"> and more in the references) the Source should revert to semi-synchronous as soon as all involved replicas are aligned again.&nbsp;</span></p>
  2093. <p><span style="font-weight: 400;">However, checking the code (see&nbsp; </span><a href="https://github.com/mysql/mysql-server/blob/beb865a960b9a8a16cf999c323e46c5b0c67f21f/plugin/semisync/semisync_source.cc#L844"><span style="font-weight: 400;">https://github.com/mysql/mysql-server/blob/beb865a960b9a8a16cf999c323e46c5b0c67f21f/plugin/semisync/semisync_source.cc#L844</span></a><span style="font-weight: 400;"> and following), we can see that we do not have a 100% guarantee that the Source will be able to switch back.&nbsp;</span></p>
  2094. <p><span style="font-weight: 400;">Also in the code:</span><span style="font-weight: 400;"><br /></span><i><span style="font-weight: 400;">But, it is not that easy to detect that the replica has caught up.&nbsp; This is caused by the fact that MySQL's replication protocol is&nbsp; asynchronous, meaning that if thesource does not use the semi-sync protocol, the replica would not send anything to thesource.</span></i></p>
  2095. <p><span style="font-weight: 400;">In all the runned tests the Source was not able to switch back. In short Source was moving out from semi-sync and that was </span><span style="font-weight: 400;">forever</span><span style="font-weight: 400;">, no rollback. Keep in mind that while we go ahead.</span></p>
  2096. <p><span style="font-weight: 400;">What is the N I mentioned above? It represents the number of Replicas that must provide the acknowledgement back.&nbsp;</span></p>
  2097. <p><span style="font-weight: 400;">If you have a cluster of 10 nodes you may need to have only 2 of them involved in the semi-sync, no need to include them all. But if you have a cluster of 3 nodes where 1 is the Source, relying on 1 Replica only, is not really secure. What I mean here is that if you choose to be semi-synchronous to ensure the data replicates, having it enabled for one single node is not enough, if that node crashes or whatever, you are doomed, as such you need at least 2 nodes with semi-sync.</span></p>
  2098. <p><span style="font-weight: 400;">Anyhow, the point is that if one of the Replica takes more than T to reply, the whole mechanism stops working, probably forever.&nbsp;</span></p>
  2099. <p><span style="font-weight: 400;">As we have seen above, to enable semi-sync on Source we manipulate the value of the GLOBAL variable </span><i><span style="font-weight: 400;">rpl_semi_sync_source_enabled</span></i><span style="font-weight: 400;">.</span></p>
  2100. <p><span style="font-weight: 400;">However if I check the value of </span><i><span style="font-weight: 400;">rpl_semi_sync_source_enabled</span></i><span style="font-weight: 400;"> when the Source shift to simple Asynchronous replication because timeout:</span></p>
  2101. <p><span style="font-weight: 400;">select @@rpl_semi_sync_source_enabled;</span></p>
  2102. <pre class="lang:mysql decode:true">select @@rpl_semi_sync_source_enabled;
  2103. +--------------------------------+
  2104. | @@rpl_semi_sync_source_enabled |
  2105. +--------------------------------+
  2106. |                              1 |
  2107. +--------------------------------+
  2108. </pre>
  2109. <p><span style="font-weight: 400;">As you can see the Global variable reports a value of 1, meaning that semi-sync is active also if not.</span></p>
  2110. <p><span style="font-weight: 400;">In the documentation it is reported that to monitor the semi-sync activity we should check for Rpl_semi_sync_source_status. Which means that you can have <a href="https://www.percona.com/blog/wp-content/uploads/2022/04/wait_whaat.jpeg"><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/wait_whaat.jpeg" alt="" width="113" height="77" class="wp-image-80666 alignright" style="float: right;" /></a> Rpl_semi_sync_source_status = 0 and rpl_semi_sync_source_enabled =1 at the same time.</span></p>
  2111. <p><span style="font-weight: 400;">Is this a bug? Well according to documentation:</span><span style="font-weight: 400;"><br /></span><i><span style="font-weight: 400;">When the source switches between asynchronous or semisynchronous replication due to commit-blocking timeout or a replica catching up, it sets the value of the Rpl_semi_sync_source_status or Rpl_semi_sync_source_status status variable appropriately. Automatic fallback from semisynchronous to asynchronous replication on the source means that it is possible for the rpl_semi_sync_source_enabled or rpl_semi_sync_source_enabled system variable to have a value of 1 on the source side even when semisynchronous replication is in fact not operational at the moment. You can monitor the Rpl_semi_sync_source_status or Rpl_semi_sync_source_status status variable to determine whether the source currently is using asynchronous or semisynchronous replication.</span></i></p>
  2112. <p><b>It is not a bug</b><span style="font-weight: 400;">. However, because you documented it, it doesn’t change the fact this is a weird/unfriendly/counterintuitive way of doing, that opens the door to many, many possible issues. Especially given you know the Source may fail to switch semi-synch back.&nbsp;&nbsp;</span></p>
  2113. <p><span style="font-weight: 400;">Just to close this part, we can summarize as follows:</span></p>
  2114. <ul>
  2115. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">You activate semi-sync setting a global variable</span></li>
  2116. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Server/Source can disable it (silently) without changing that variable&nbsp;</span></li>
  2117. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Server will never restore semi-sync automatically</span></li>
  2118. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">The way to check if semi-sync works is to use the Status variable</span></li>
  2119. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">When Rpl_semi_sync_source_status = 0 and rpl_semi_sync_source_enabled =1 you had a Timeout and Source is now working in asynchronous replication</span></li>
  2120. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">The way to reactivate semi-sync is to set rpl_semi_sync_source_enabled&nbsp; to OFF first then rpl_semi_sync_source_enabled = ON.&nbsp;</span></li>
  2121. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Replicas can be set with semi-sync ON/OFF but unless you do not STOP/START the replica_IO_THREAD the state of the variable can be inconsistent with the state of the Server.</span></li>
  2122. </ul>
  2123. <p><span style="font-weight: 400;">What can go wrong?</span></p>
  2124. <h2><span style="font-weight: 400;">Semi-synchronous is not seriously affecting the performance</span></h2>
  2125. <p><span style="font-weight: 400;">Others had already discussed semi-sync performance in better details. However I want to add some color given the recent experience with our operator testing.<br /></span><span style="font-weight: 400;">In the next graphs I will show you the behavior of writes/reads using Asynchronous replication and the same load with Semi-synchronous.<br /></span><span style="font-weight: 400;">For the record the test was a simple Sysbench-tpcc test using 20 tables, 20 warehouses, 256 threads for 600 seconds.&nbsp;&nbsp;&nbsp;</span></p>
  2126. <p><a href="http://www.tusacentral.net/joomla/images/stories/semi-sync/2.png"><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/2.png" alt="" width="900" height="401" class="alignnone wp-image-80652 size-large" /></a> <a href="http://www.tusacentral.net/joomla/images/stories/semi-sync/3.png"><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/3.png" alt="" width="900" height="421" class="alignnone size-large wp-image-80653" /></a></p>
  2127. <p><span style="font-weight: 400;">The one above indicates a nice and consistent set of load in r/w with minimal fluctuations. This is what we like to have.&nbsp;</span></p>
  2128. <p><span style="font-weight: 400;">The graphs below, represent the exact same load on the exact same environment but with semi-sync activated and no timeout.&nbsp;</span></p>
  2129. <p><a href="http://www.tusacentral.net/joomla/images/stories/semi-sync/9.png"><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/9.png" alt="" width="900" height="421" class="alignnone wp-image-80657 size-large" /></a> <a href="http://www.tusacentral.net/joomla/images/stories/semi-sync/10.png"><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/10.png" alt="" width="900" height="420" class="alignnone wp-image-80658 size-large" /></a></p>
  2130. <p><span style="font-weight: 400;">Aside from the performance loss (we went from Transaction 10k/s to 3k/s), the constant stop/go imposed by the semi-sync mechanism has a very bad effect on the application behavior when you have many concurrent threads and high loads. I challenge any serious production system to work in this way.&nbsp;&nbsp;&nbsp;</span></p>
  2131. <p><span style="font-weight: 400;">Of course results are inline with this yoyo game:</span></p>
  2132. <p><a href="http://www.tusacentral.net/joomla/images/stories/semi-sync/1c.png"><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/1c.png" alt="" width="900" height="356" class="alignnone size-large wp-image-80651" /></a></p>
  2133. <p><span style="font-weight: 400;">In the best case, when all was working as expected, and no crazy stuff happening I had something around the 60% loss. I am not oriented to see this as&nbsp; a minor performance drop.&nbsp;</span></p>
  2134. <h2><span style="font-weight: 400;">But at least your data is safe</span></h2>
  2135. <p><span style="font-weight: 400;">As already stated at the beginning the scope of semi-synchronous replication is to guarantee that the data in server A reaches server B before returning the OK to the application.&nbsp;</span></p>
  2136. <p><span style="font-weight: 400;">In short, given a period of 1 second we should have minimal transactions in flight and limited transactions in the apply queue. While for standard replication (asynchronous), we may have … thousands.&nbsp;</span></p>
  2137. <p><span style="font-weight: 400;">In the graphs below we can see two lines:</span></p>
  2138. <ul>
  2139. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">The yellow line represents the number of GTIDs “in flight” from Source to destination, Y2 axes.&nbsp; In case of Source crash, those transactions are lost and we will have data loss.</span></li>
  2140. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">The blue line represents the number of GTIDs already copied over from Source to Replica but not applied in the database Y1 axes. In case of Source crash we must wait for the Replica to process these entries, before making the node Write active, or we will have data inconsistency.</span></li>
  2141. </ul>
  2142. <p><span style="font-weight: 400;">Asynchronous replication:</span></p>
  2143. <p><a href="http://www.tusacentral.net/joomla/images/stories/semi-sync/4.png"><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/4.png" alt="" width="900" height="526" class="alignnone wp-image-80654 size-large" /></a></p>
  2144. <p><span style="font-weight: 400;">As expected we can see a huge queue in applying the transactions from relay-log, and some spike of transactions in flight.&nbsp;</span></p>
  2145. <p><span style="font-weight: 400;">Using Semi-synchronous replication:</span></p>
  2146. <p><a href="http://www.tusacentral.net/joomla/images/stories/semi-sync/8.png"><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/8.png" alt="" width="900" height="421" class="alignnone size-large wp-image-80656" /></a></p>
  2147. <p><span style="font-weight: 400;">Yes, apparently we have reduced the queue and no spikes so no data loss.</span></p>
  2148. <p><span style="font-weight: 400;">But this happens&nbsp; when all goes as expected, and we know in production this is not the normal.<br /></span><span style="font-weight: 400;">What if we need to enforce the semi-sync but at the same time we cannot set the Timeout to ridiculous values like 1 week?&nbsp;</span></p>
  2149. <p><span style="font-weight: 400;">Simple, we need to have a check that puts back the semi-sync as soon as it is silently disabled (for any reason).<br /></span><span style="font-weight: 400;">However doing this without waiting for the Replicas to cover the replication gap, cause the following interesting effects:</span></p>
  2150. <p><a href="http://www.tusacentral.net/joomla/images/stories/semi-sync/5.png"><img src="http://www.tusacentral.net/joomla/images/stories/semi-sync/5.png" alt="" width="900" height="525" class="alignnone size-large wp-image-80655" /></a></p>
  2151. <p><span style="font-weight: 400;">Thousands of transactions queued and shipped with the result of having a significant increase of the possible data loss and still a huge number of data to apply from the relay-log.&nbsp;</span></p>
  2152. <p><span style="font-weight: 400;">So the only possible alternative is to set the Timeout to a crazy value, However this can cause a full production stop in the case a Replica hangs or for any reason it disables the semi-sync locally.&nbsp;</span></p>
  2153. <p>&nbsp;</p>
  2154. <h2><span style="font-weight: 400;">Conclusion</span></h2>
  2155. <p><span style="font-weight: 400;">First of all I want to say that the tests on our operator using Asynchronous replication, shows a consistent behavior with the standard deployments in the cloud or premises.&nbsp; It has the same benefits, like better performance and same possible issues as longer time to failover when it needs to wait a Replica to apply the relay-log queue.&nbsp;</span></p>
  2156. <p><span style="font-weight: 400;">The semi-synchronous flag in the operator is disabled, and the tests I have done bring me to say “keep it like that!”. At least unless you know very well what you are doing and are able to deal with a semi-sync timeout of days.</span></p>
  2157. <p>I was happy to have the chance to perform these tests, because they gives me a way/time/need to investigate more on the semi-synchronous feature.<br /><span style="font-weight: 400;">Personally, I was not convinced about the semi-synchronous replication when it came out, and I am not now. I never saw a less consistent and less trustable feature in MySQL as semi-sync.&nbsp;&nbsp;</span></p>
  2158. <p><span style="font-weight: 400;">If you need to have a higher level of synchronicity in your database just go for Group Replication, or Percona XtraDB Cluster and stay away from semi-sync.&nbsp;</span></p>
  2159. <p><span style="font-weight: 400;">Otherwise, stay on Asynchronous replication, which is not perfect but it is predictable.&nbsp;&nbsp;</span></p>
  2160. <h2><span style="font-weight: 400;">References</span></h2>
  2161. <p><a href="https://www.percona.com/blog/2012/01/19/how-does-semisynchronous-mysql-replication-work/"><span style="font-weight: 400;">https://www.percona.com/blog/2012/01/19/how-does-semisynchronous-mysql-replication-work/</span></a></p>
  2162. <p><a href="https://www.percona.com/blog/percona-monitoring-and-management-mysql-semi-sync-summary-dashboard/"><span style="font-weight: 400;">https://www.percona.com/blog/percona-monitoring-and-management-mysql-semi-sync-summary-dashboard/</span></a></p>
  2163. <p><a href="https://www.percona.com/blog/2012/06/14/comparing-percona-xtradb-cluster-with-semi-sync-replication-cross-wan/">https://www.percona.com/blog/2012/06/14/comparing-percona-xtradb-cluster-with-semi-sync-replication-cross-wan/</a></p>
  2164. <p><a href="https://datto.engineering/post/lossless-mysql-semi-sync-replication-and-automated-failover"><span style="font-weight: 400;">https://datto.engineering/post/lossless-mysql-semi-sync-replication-and-automated-failover</span></a></p>
  2165. <p><a href="https://planetscale.com/blog/mysql-semi-sync-replication-durability-consistency-and-split-brains"><span style="font-weight: 400;">https://planetscale.com/blog/mysql-semi-sync-replication-durability-consistency-and-split-brains</span></a></p>
  2166. <p><a href="https://percona.community/blog/2018/08/23/question-about-semi-synchronous-replication-answer-with-all-the-details/"><span style="font-weight: 400;">https://percona.community/blog/2018/08/23/question-about-semi-synchronous-replication-answer-with-all-the-details/</span></a></p>
  2167. <p><a href="https://dev.mysql.com/doc/refman/8.0/en/replication-semisync-installation.html"><span style="font-weight: 400;">https://dev.mysql.com/doc/refman/8.0/en/replication-semisync-installation.html</span></a></p>
  2168. <p><a href="https://dev.mysql.com/worklog/task/?id=1720"><span style="font-weight: 400;">https://dev.mysql.com/worklog/task/?id=1720</span></a></p>
  2169. <p><a href="https://dev.mysql.com/worklog/task/?id=6630"><span style="font-weight: 400;">https://dev.mysql.com/worklog/task/?id=6630</span></a></p>
  2170. <p><a href="https://dev.mysql.com/worklog/task/?id=4398"><span style="font-weight: 400;">https://dev.mysql.com/worklog/task/?id=4398</span></a></p>
  2171. <p><a href="https://github.com/mysql/mysql-server/blob/beb865a960b9a8a16cf999c323e46c5b0c67f21f/plugin/semisync/semisync_source.cc#L844"><span style="font-weight: 400;">https://github.com/mysql/mysql-server/blob/beb865a960b9a8a16cf999c323e46c5b0c67f21f/plugin/semisync/semisync_source.cc#L844</span></a></p>
  2172. <p><a href="https://github.com/mysql/mysql-server/blob/beb865a960b9a8a16cf999c323e46c5b0c67f21f/plugin/semisync/semisync_source.cc#L881"><span style="font-weight: 400;">https://github.com/mysql/mysql-server/blob/beb865a960b9a8a16cf999c323e46c5b0c67f21f/plugin/semisync/semisync_source.cc#L881</span></a></p>]]></description>
  2173. <category>MySQL</category>
  2174. <pubDate>Tue, 12 Apr 2022 10:00:01 +0000</pubDate>
  2175. </item>
  2176. <item>
  2177. <title>Online DDL with Group Replication In MySQL 8.0.27</title>
  2178. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/246-online-ddl-with-group-replication-in-mysql-8-0-27</link>
  2179. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/246-online-ddl-with-group-replication-in-mysql-8-0-27</guid>
  2180. <description><![CDATA[<p><span style="font-weight: 400;">Last April 2021 I wrote an <a href="https://www.percona.com/blog/2021/04/15/online-ddl-with-group-replication-in-percona-server-for-mysql-8-0-22/">article</a> about Online DDL and Group Replication. At that time we were dealing with MySQL 8.0.23 </span><span style="font-weight: 400;">and also opened a <a href="https://bugs.mysql.com/bug.php?id=103421">bug</a> report </span><span style="font-weight: 400;">which did not have the right answer to the case presented.&nbsp;</span></p>
  2181. <p><span style="font-weight: 400;">Anyhow, in that article I have shown how an online DDL was de facto locking the whole cluster for a very long time even when using the consistency level set to EVENTUAL.</span></p>
  2182. <p><span style="font-weight: 400;">This article is to give justice to the work done by the MySQL/Oracle engineers to correct that annoying inconvenience.&nbsp;</span></p>
  2183. <p><span style="font-weight: 400;">Before going ahead, let us remember how an Online DDL was propagated in a group replication cluster, and identify the differences with what happens now, all with the consistency level set to EVENTUAL (<a href="https://dev.mysql.com/doc/refman/8.0/en/group-replication-configuring-consistency-guarantees.html">see</a></span><span style="font-weight: 400;">).</span></p>
  2184. <p><span style="font-weight: 400;">In MySQL 8.0.23 we were having:</span></p>
  2185. <table>
  2186. <tbody>
  2187. <tr>
  2188. <td><a href="https://www.percona.com/blog/wp-content/uploads/2022/01/1-gr-ddl.png"><img src="http://www.tusacentral.net/joomla/images/stories/gr_ddl_8_0_27/1-gr-ddl.png" alt="1 gr ddl" width="201" height="222" class="alignnone size-full wp-image-79683" /></a></td>
  2189. <td><a href="https://www.percona.com/blog/wp-content/uploads/2022/01/gr-ddl-2-old.png"><img src="http://www.tusacentral.net/joomla/images/stories/gr_ddl_8_0_27/gr-ddl-2-old.png" alt="gr ddl 2 old" width="201" height="222" class="alignnone size-full wp-image-79689" /></a></td>
  2190. <td><a href="https://www.percona.com/blog/wp-content/uploads/2022/01/gr-ddl-3-old.png"><img src="http://www.tusacentral.net/joomla/images/stories/gr_ddl_8_0_27/gr-ddl-3-old.png" alt="gr ddl 3 old" width="211" height="242" class="alignnone size-full wp-image-79684" /></a></td>
  2191. </tr>
  2192. </tbody>
  2193. </table>
  2194. <p><span style="font-weight: 400;">While in MySQL 8.0.27 we have:</span></p>
  2195. <table>
  2196. <tbody>
  2197. <tr>
  2198. <td><a href="https://www.percona.com/blog/wp-content/uploads/2022/01/1-gr-ddl.png"><img src="http://www.tusacentral.net/joomla/images/stories/gr_ddl_8_0_27/1-gr-ddl-new.png" alt="1 gr ddl new" width="201" height="222" class="alignnone size-full wp-image-79683" /></a></td>
  2199. <td><a href="https://www.percona.com/blog/wp-content/uploads/2022/01/gr-ddl-2-new.png"><img src="http://www.tusacentral.net/joomla/images/stories/gr_ddl_8_0_27/gr-ddl-2-new.png" alt="gr ddl 2 new" width="231" height="257" class="alignnone size-full wp-image-79686" /></a></td>
  2200. <td><a href="https://www.percona.com/blog/wp-content/uploads/2022/01/gr-ddl-3-new.png"><img src="http://www.tusacentral.net/joomla/images/stories/gr_ddl_8_0_27/gr-ddl-3-new.png" alt="gr ddl 3 new" width="201" height="212" class="alignnone size-full wp-image-79687" /></a></td>
  2201. </tr>
  2202. </tbody>
  2203. </table>
  2204. <p>&nbsp;</p>
  2205. <p><span style="font-weight: 400;">As you can see from the images we have 3 different phases. Phase 1 is the same between version 8.0.23 and version 8.0.27.&nbsp;</span></p>
  2206. <p><span style="font-weight: 400;">Phase 2 and 3 instead are quite different. In MySQL 8.0.23 after the DDL is applied on the Primary it is propagated to the other nodes, but a metalock was also acquired and the control was NOT returned. The result was that not only the session executing the DDL was kept on hold, but also all the other sessions performing modifications.&nbsp;</span></p>
  2207. <p><span style="font-weight: 400;">Only when the operation was over on all secondaries, the DDL was pushed to Binlog and disseminated for Asynchronous replication, lock raised and operation can restart.</span></p>
  2208. <p><span style="font-weight: 400;">Instead, in MySQL 8.0.27,&nbsp; once the operation is over on the primary the DDL is pushed to binlog, disseminated to the secondaries and control returned. The result is that the write operations on primary have no interruption whatsoever and the DDL is distributed to secondary and Asynchronous replication at the same time.&nbsp;</span></p>
  2209. <p><span style="font-weight: 400;">This is a fantastic improvement, available only with consistency level EVENTUAL, but still, fantastic.</span></p>
  2210. <h3><span style="font-weight: 400;">Let's see some numbers.</span></h3>
  2211. <p><span style="font-weight: 400;">To test the operation, I have used the same approach used in the previous tests in the article mentioned above.</span></p>
  2212. <pre class="lang:sh decode:true">Connection 1:
  2213.    ALTER TABLE windmills_test ADD INDEX idx_1 (`uuid`,`active`), ALGORITHM=INPLACE, LOCK=NONE;
  2214.    ALTER TABLE windmills_test drop INDEX idx_1, ALGORITHM=INPLACE;
  2215.    
  2216. Connection 2:
  2217. while [ 1 = 1 ];do da=$(date +'%s.%3N');/opt/mysql_templates/mysql-8P/bin/mysql --defaults-file=./my.cnf -uroot -D windmills_large -e "insert into windmills_test  select null,uuid,millid,kwatts_s,date,location,active,time,strrecordtype from windmill7 limit 1;" -e "select count(*) from windmills_large.windmills_test;" &gt; /dev/null;db=$(date +'%s.%3N'); echo "$(echo "($db - $da)"|bc)";sleep 1;done
  2218.  
  2219. Connection 3:
  2220. while [ 1 = 1 ];do da=$(date +'%s.%3N');/opt/mysql_templates/mysql-8P/bin/mysql --defaults-file=./my.cnf -uroot -D windmills_large -e "insert into windmill8  select null,uuid,millid,kwatts_s,date,location,active,time,strrecordtype from windmill7 limit 1;" -e "select count(*) from windmills_large.windmills_test;" &gt; /dev/null;db=$(date +'%s.%3N'); echo "$(echo "($db - $da)"|bc)";sleep 1;done
  2221.  
  2222. Connections 4-5:
  2223.     while [ 1 = 1 ];do echo "$(date +'%T.%3N')";/opt/mysql_templates/mysql-8P/bin/mysql --defaults-file=./my.cnf -uroot -D windmills_large -e "show full processlist;"|egrep -i -e "(windmills_test|windmills_large)"|grep -i -v localhost;sleep 1;done
  2224. </pre>
  2225. <p><span style="font-weight: 400;">Modifying a table with ~5 million rows:</span></p>
  2226. <pre class="lang:mysql decode:true">node1-DC1 (root@localhost) [windmills_large]&gt;select count(*) from  windmills_test;
  2227. +----------+
  2228. | count(*) |
  2229. +----------+
  2230. |  5002909 |
  2231. +----------+
  2232. </pre>
  2233. <p><span style="font-weight: 400;">The numbers below represent the time second.milliseconds taken by the operation to complete. While I was also catching the state of the ALTER on the other node I am not reporting it here given it is not relevant.&nbsp;</span></p>
  2234. <pre class="lang:sh decode:true">EVENTUAL (on the primary only)
  2235. -------------------
  2236. Node 1 same table:
  2237. .184
  2238. .186 &lt;--- no locking during alter on the same node
  2239. .184
  2240. &lt;snip&gt;
  2241. .184
  2242. .217 &lt;--- moment of commit
  2243. .186
  2244. .186
  2245. .186
  2246. .185
  2247.  
  2248. Node 1 another table :
  2249. .189
  2250. .198 &lt;--- no locking during alter on the same node
  2251. .188
  2252. &lt;snip&gt;
  2253. .191
  2254. .211  &lt;--- moment of commit
  2255. .194
  2256. </pre>
  2257. <p><span style="font-weight: 400;">As you can see there is just a very small delay at the moment of commit but other impact.</span></p>
  2258. <p><span style="font-weight: 400;">Now if we compare this with the recent tests I have done for PXC Non Blocking operation (see <a href="https://www.percona.com/blog/percona-xtradb-cluster-non-blocking-operation-for-online-schema-upgrade/">here</a></span><span style="font-weight: 400;">) with same number of rows and same kind of table/data:</span></p>
  2259. <table border="1">
  2260. <thead>
  2261. <tr><th>Action</th><th align="right">Group Replication</th><th align="right">PXC (NBO)</th></tr>
  2262. </thead>
  2263. <tbody>
  2264. <tr>
  2265. <td>Time on hold for insert in altering table</td>
  2266. <td align="right">~ 0.217 sec</td>
  2267. <td align="right">~ 120 sec</td>
  2268. </tr>
  2269. <tr>
  2270. <td>Time on hold for insert in another table</td>
  2271. <td align="right">~ 0.211 sec</td>
  2272. <td align="right">~ 25 sec</td>
  2273. </tr>
  2274. </tbody>
  2275. </table>
  2276. <p>&nbsp;</p>
  2277. <p><span style="font-weight: 400;"><strong>However</strong>, yes there is a <strong>however</strong>, PXC was maintaining consistency between the different nodes during the DDL execution, while MySQL 8.0.27 with Group Replication was postponing consistency on the secondaries, thus Primary and Secondary were not in sync until full DDL finalization on the secondaries.</span></p>
  2278. <h1><span style="font-weight: 400;">Conclusions</span></h1>
  2279. <p><span style="font-weight: 400;">MySQL 8.0.27 comes with this nice fix that significantly reduces the impact of an online DDL operation on a busy server. But we can still observe a significant misalignment of the data between the nodes when a DDL is executing.&nbsp;</span></p>
  2280. <p><span style="font-weight: 400;">On the other hand PXC with NBO is a bit more “expensive” in time, but nodes remain aligned all the time.</span></p>
  2281. <p><span style="font-weight: 400;">At the end is what is more important for you to choose one or the other solution, consistency vs. operational impact.</span></p>
  2282. <p><span style="font-weight: 400;">Great MySQL to all.</span></p>]]></description>
  2283. <category>MySQL</category>
  2284. <pubDate>Tue, 11 Jan 2022 13:04:00 +0000</pubDate>
  2285. </item>
  2286. <item>
  2287. <title>A look into Percona XtraDB Cluster Non Blocking Operation for Online Schema Upgrade</title>
  2288. <link>http://www.tusacentral.net/joomla/index.php/mysql-blogs/245-a-look-into-percona-xtradb-cluster-non-blocking-operation-for-online-schema-upgrade</link>
  2289. <guid isPermaLink="true">http://www.tusacentral.net/joomla/index.php/mysql-blogs/245-a-look-into-percona-xtradb-cluster-non-blocking-operation-for-online-schema-upgrade</guid>
  2290. <description><![CDATA[<p><span style="font-weight: 400;">Percona XtraDB Cluster 8.0.25 has introduced a new option to perform online schema modifications: NBO (<a href="https://www.percona.com/doc/percona-xtradb-cluster/LATEST/features/nbo.html#nbo">Non Blocking Operation</a>).</span></p>
  2291. <p><span style="font-weight: 400;">When using PXC the cluster relies on </span><b>wsrep_OSU_method</b><span style="font-weight: 400;"> parameter to define the Online Schema Upgrade (OSU) method the node uses to replicate DDL statements.&nbsp;&nbsp;<img src="http://www.tusacentral.net/joomla/images/stories/NBO/breaking_bariers.jpg" alt="breaking bariers" width="400" height="239" style="float: right;" /></span></p>
  2292. <p><span style="font-weight: 400;">Until now we normally have 3 options:</span></p>
  2293. <ul>
  2294. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Use Total Isolation Order (TOI, the default)</span></li>
  2295. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Use Rolling Schema Upgrade (RSU)</span></li>
  2296. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">Use Percona’s online schema change tool (TOI + <a href="https://www.percona.com/doc/percona-toolkit/LATEST/pt-online-schema-change.html">PTOSC</a>)</span></li>
  2297. </ul>
  2298. <p><span style="font-weight: 400;">Each method has some positive and negative aspects. TOI will lock the whole cluster from being able to accept data modifications for the entire time it takes to perform the DDL operation. RSU will misalign the schema definition between the nodes, and in any case the node performing the DDL operation is still locked. Finally TOI+PTOSC will rely on creating triggers and copying data, so in some cases this can be very impactful.&nbsp;</span></p>
  2299. <p><span style="font-weight: 400;">The new Non Blocking Operation (NBO) method is to help to reduce the impact on the cluster and make it easier to perform some DDL operations.</span></p>
  2300. <p><span style="font-weight: 400;">At the moment we only support a limited set of operations with NBO like:</span></p>
  2301. <ul>
  2302. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">ALTER INDEX</span></li>
  2303. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">CREATE INDEX</span></li>
  2304. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">DROP INDEX</span></li>
  2305. </ul>
  2306. <p><span style="font-weight: 400;">Any other command will result in an error message ER_NOT_SUPPORTED_YET.</span></p>
  2307. <p><span style="font-weight: 400;">But let us see how it works and what is the impact while we will also compare it with the default method TOI.</span></p>
  2308. <p><span style="font-weight: 400;">What we will do is working with 4 connections:</span></p>
  2309. <p style="padding-left: 40px;"><span style="font-weight: 400;">1 to perform ddl<br /></span><span style="font-weight: 400;">2 to perform insert data in the table being altered<br /></span><span style="font-weight: 400;">3 to perform insert data on a different table&nbsp;<br /></span><span style="font-weight: 400;">4-5 checking the other two nodes operations</span></p>
  2310. <p><span style="font-weight: 400;">PXC must be at least Ver 8.0.25-15.1.</span></p>
  2311. <p><span style="font-weight: 400;">The table we will modify is :</span></p>
  2312. <pre class="lang:mysql decode:true">DC1-1(root@localhost) [windmills_s]&gt;show create table windmills_test\G
  2313. *************************** 1. row ***************************
  2314.       Table: windmills_test
  2315. Create Table: CREATE TABLE `windmills_test` (
  2316.  `id` bigint NOT NULL AUTO_INCREMENT,
  2317.  `uuid` char(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  2318.  `millid` smallint NOT NULL,
  2319.  `kwatts_s` int NOT NULL,
  2320.  `date` date NOT NULL,
  2321.  `location` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  2322.  `active` tinyint NOT NULL DEFAULT '1',
  2323.  `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  2324.  `strrecordtype` char(3) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  2325.  PRIMARY KEY (`id`),
  2326.  KEY `IDX_millid` (`millid`,`active`),
  2327.  KEY `IDX_active` (`id`,`active`),
  2328.  KEY `kuuid_x` (`uuid`),
  2329.  KEY `millid_x` (`millid`),
  2330.  KEY `active_x` (`active`)
  2331. ) ENGINE=InnoDB AUTO_INCREMENT=8199260 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin ROW_FORMAT=DYNAMIC
  2332. 1 row in set (0.00 sec)
  2333. </pre>
  2334. <p><span style="font-weight: 400;">And contains ~5 million rows.</span></p>
  2335. <pre class="lang:sh decode:true">DC1-1(root@localhost) [windmills_s]&gt;select count(*) from windmills_test;
  2336. +----------+
  2337. | count(*) |
  2338. +----------+
  2339. |  5002909 |
  2340. +----------+
  2341. 1 row in set (0.44 sec)
  2342. </pre>
  2343. <p><span style="font-weight: 400;">The commands.<br /></span><span style="font-weight: 400;">Connection 1:</span></p>
  2344. <pre class="lang:sh decode:true">  ALTER TABLE windmills_test ADD INDEX idx_1 (`uuid`,`active`), ALGORITHM=INPLACE;
  2345.  ALTER TABLE windmills_test drop INDEX idx_1, ALGORITHM=INPLACE;
  2346. </pre>
  2347. <p>&nbsp;</p>
  2348. <p><span style="font-weight: 400;">Connection 2:</span></p>
  2349. <pre class="lang:sh decode:true">while [ 1 = 1 ];do da=$(date +'%s.%3N');/opt/mysql_templates/PXC8P/bin/mysql --defaults-file=./my.cnf -uroot -D windmills_s -e "insert into windmills_test  select null,uuid,millid,kwatts_s,date,location,active,time,strrecordtype from windmills7 limit 1;" -e "select count(*) from windmills_s.windmills_test;" &gt; /dev/null;db=$(date +'%s.%3N'); echo "$(echo "($db - $da)"|bc)";sleep 1;done</pre>
  2350. <p>&nbsp;</p>
  2351. <p><span style="font-weight: 400;">Connection 3:</span></p>
  2352. <pre class="lang:sh decode:true"> while [ 1 = 1 ];do da=$(date +'%s.%3N');/opt/mysql_templates/PXC8P/bin/mysql --defaults-file=./my.cnf -uroot -D windmills_s -e "insert into windmills8  select null,uuid,millid,kwatts_s,date,location,active,time,strrecordtype from windmills7 limit 1;" -e "select count(*) from windmills_s.windmills_test;" &gt; /dev/null;db=$(date +'%s.%3N'); echo "$(echo "($db - $da)"|bc)";sleep 1;done</pre>
  2353. <p>&nbsp;</p>
  2354. <p><span style="font-weight: 400;">Connections 4-5:</span></p>
  2355. <pre class="lang:sh decode:true">while [ 1 = 1 ];do echo "$(date +'%T.%3N')";/opt/mysql_templates/PXC8P/bin/mysql --defaults-file=./my.cnf -uroot -D windmills_s -e "show full processlist;"|egrep -i -e "(windmills_test|windmills_s)"|grep -i -v localhost;sleep 1;done</pre>
  2356. <p><span style="font-weight: 400;">Operations:</span></p>
  2357. <ul>
  2358. <li><span style="font-weight: 400;">start inserts from connections</span></li>
  2359. <li><span style="font-weight: 400;">start commands in connections 4 - 5 on the other nodes</span></li>
  2360. <li><span style="font-weight: 400;">execute:&nbsp;</span>
  2361. <ul>
  2362. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">for TOI&nbsp;</span>
  2363. <ul>
  2364. <li aria-level="2">
  2365. <pre class="">DC1-1(root@localhost) [windmills_s]&gt;SET SESSION wsrep_OSU_method=TOI;</pre>
  2366. </li>
  2367. </ul>
  2368. </li>
  2369. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">for NBO</span>
  2370. <ul>
  2371. <li aria-level="2">
  2372. <pre class="">DC1-1(root@localhost) [windmills_s]&gt;SET SESSION wsrep_OSU_method=NBO;</pre>
  2373. </li>
  2374. </ul>
  2375. </li>
  2376. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">For both</span>
  2377. <ul>
  2378. <li>
  2379. <pre class="">DC1-1(root@localhost) [windmills_s]&gt;ALTER TABLE windmills_test ADD INDEX idx_1 (`uuid`,`active`), ALGORITHM=INPLACE, LOCK=shared;</pre>
  2380. </li>
  2381. </ul>
  2382. </li>
  2383. </ul>
  2384. </li>
  2385. </ul>
  2386. <h1>&nbsp;</h1>
  2387. <h1 style="padding-left: 40px;"><span style="font-weight: 400;">Let us run it</span></h1>
  2388. <h2><span style="font-weight: 400;">Altering a table with TOI.</span></h2>
  2389. <pre class="lang:sh decode:true">DC1-1(root@localhost) [windmills_s]&gt;ALTER TABLE windmills_test ADD INDEX idx_1 (`uuid`,`active`), ALGORITHM=INPLACE;
  2390. Query OK, 0 rows affected (1 min 4.74 sec)
  2391. Records: 0  Duplicates: 0  Warnings: 0
  2392. </pre>
  2393. <p>&nbsp;</p>
  2394. <p><span style="font-weight: 400;">Inserts in the altering table (connection 2):</span></p>
  2395. <pre class="lang:sh decode:true">.450
  2396. .492
  2397. 64.993 &lt;--- Alter blocks all inserts on the table we are altering
  2398. .788
  2399. .609
  2400. </pre>
  2401. <p>&nbsp;</p>
  2402. <p><span style="font-weight: 400;">Inserts on the other table (connection 3):</span></p>
  2403. <pre class="lang:sh decode:true">.455
  2404. .461
  2405. 64.161 &lt;--- Alter blocks all inserts on all the other tables as well
  2406. .641
  2407. .483
  2408. </pre>
  2409. <p>&nbsp;</p>
  2410. <p><span style="font-weight: 400;">On the other nodes at the same time of the ALTER we can see:</span></p>
  2411. <pre class="lang:sh decode:true">Id  User             db         Command Time  State             Info                                                                            Time_ms Rows_sent Rows_examined
  2412. 15 system user windmills_s Query 102  altering table ALTER TABLE windmills_test ADD INDEX idx_1 (`uuid`,`active`), ALGORITHM=INPLACE 102238 0       0    &lt;--- time from start
  2413. </pre>
  2414. <p><span style="font-weight: 400;">So in short we have the whole cluster locked for ~64 seconds. During this period of time, all the operations to modify data or structure were on hold.&nbsp;</span></p>
  2415. <h2>&nbsp;</h2>
  2416. <h2><span style="font-weight: 400;">Let us now try with NBO</span></h2>
  2417. <p><span style="font-weight: 400;">Inserts in the altering table:</span></p>
  2418. <pre class="lang:sh decode:true">.437
  2419. .487
  2420. 120.758 &lt;---- Execution time increase
  2421. .617
  2422. .510
  2423. </pre>
  2424. <p>&nbsp;</p>
  2425. <p><span style="font-weight: 400;">Inserts on the other table:</span></p>
  2426. <pre class="lang:sh decode:true">.468
  2427. .485
  2428. 25.061 &lt;---- still a metalock, but not locking the other tables for the whole duration
  2429. .494
  2430. .471
  2431. </pre>
  2432. <p>&nbsp;</p>
  2433. <p><span style="font-weight: 400;">On the other nodes at the same time of the ALTER we can see:</span></p>
  2434. <pre class="lang:sh decode:true">Id      User         db             Command Time  State             Info                                                                            Time_ms Rows_sent Rows_examined
  2435. 110068 system user windmills_s Connect 86  altering table ALTER TABLE windmills_test ADD INDEX idx_1 (`uuid`,`active`), ALGORITHM=INPLACE 120420 0          0
  2436. </pre>
  2437. <p>&nbsp;</p>
  2438. <p><span style="font-weight: 400;">In this case what is also interesting to note is that:</span></p>
  2439. <ol>
  2440. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">We have a moment of metalock:</span><ol>
  2441. <li aria-level="2">
  2442. <pre class="">110174 pmm 127.0.0.1:42728 NULL Query 2 Waiting for table metadata lock  SELECT x FROM information_schema.tables&nbsp; WHERE TABLE_SCHEMA = 'windmills_s' 1486 10  &nbsp; 0</pre>
  2443. </li>
  2444. <li aria-level="2">
  2445. <pre class="">110068  system user connecting host windmills_s Connect 111 closing tables ALTER TABLE windmills_test ADD INDEX idx_1 (`uuid`,`active`), ALGORITHM=INPLACE 111000 0 0</pre>
  2446. </li>
  2447. </ol></li>
  2448. <li><span style="font-weight: 400;">The execution time is longer </span></li>
  2449. </ol>
  2450. <p><span style="font-weight: 400;">Summarizing:</span></p>
  2451. <pre class="lang:sh decode:true">                                      TOI            NBO
  2452. Time on hold for insert for altering table   ~64 sec     ~120 sec
  2453. Time on hold for insert for another table   ~64 sec      ~25 sec
  2454. metalock                       whole time   only at the end
  2455. </pre>
  2456. <h2>&nbsp;</h2>
  2457. <h2><span style="font-weight: 400;">What is happening, what are the differences and why takes longer with NBO?</span></h2>
  2458. <p><span style="font-weight: 400;">Let see at very high level how the two works:</span></p>
  2459. <ul>
  2460. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">TOI: when you issue a DDL like ADD INDEX a metadata lock is taken on the table and it will be released only at the end of the operation. During this time, you cannot:&nbsp;</span>
  2461. <ul>
  2462. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Perform DMLs on any cluster node</span></li>
  2463. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">Alter another table in the cluster</span></li>
  2464. </ul>
  2465. </li>
  2466. <li style="font-weight: 400;" aria-level="1"><span style="font-weight: 400;">NBO: the metadata lock is taken at the start and at the end for a very brief period of time. The ADD INDEX operation will then work on each node independently. The lock taken at the end is to have all the nodes agree on the operation and commit or roll back (using cluster error voting). This final phase costs a bit more in time and is what adds a few seconds to the operation execution. But during the operation:</span>
  2467. <ul>
  2468. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">You can alter another table (using NBO)</span></li>
  2469. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">You can continue to insert data, except in the table(s) you are altering.</span></li>
  2470. <li style="font-weight: 400;" aria-level="2"><span style="font-weight: 400;">On node crash the operation will continue on the other nodes, and if successful it will persist.&nbsp;&nbsp;</span></li>
  2471. </ul>
  2472. </li>
  2473. </ul>
  2474. <p><span style="font-weight: 400;">In short the cluster server behavior changes significantly when using NBO, offering significant flexibility compared to TOI. The cost in time should not linearly increase with the dimension of the table, but more in relation to the single node efficiency in performing the ALTER operation.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p>
  2475. <h1><span style="font-weight: 400;">Conclusion</span></h1>
  2476. <p><span style="font-weight: 400;">NBO can be significantly helpful to reduce the impact of DDL on the cluster, for now limited to the widely used creation/modification/drop of an index. But in the future … we may expand it.&nbsp;</span></p>
  2477. <p><span style="font-weight: 400;">The feature is still a technology preview, so do not trust in production, but test it and let us know what you think.&nbsp;</span></p>
  2478. <p><span style="font-weight: 400;">Final comment. Another distribution has introduced NBO, but only if you buy the enterprise version.</span></p>
  2479. <p><span style="font-weight: 400;">Percona, which is truly open source with facts not just words, has implemented NBO in standard PXC, and the code is fully open source. This is not the first one, but just another of the many features Percona is offering for free, while others ask you to buy the enterprise version.</span></p>
  2480. <p><span style="font-weight: 400;">Enjoy the product and let us have your feedback!</span></p>
  2481. <p><span style="font-weight: 400;">Great MySQL to all!&nbsp;</span></p>
  2482. <p>&nbsp;</p>]]></description>
  2483. <category>MySQL</category>
  2484. <pubDate>Fri, 10 Dec 2021 10:00:29 +0000</pubDate>
  2485. </item>
  2486. </channel>
  2487. </rss>
  2488.  

If you would like to create a banner that links to this page (i.e. this validation result), do the following:

  1. Download the "valid RSS" banner.

  2. Upload the image to your own server. (This step is important. Please do not link directly to the image on this server.)

  3. Add this HTML to your page (change the image src attribute if necessary):

If you would like to create a text link instead, here is the URL you can use:

http://www.feedvalidator.org/check.cgi?url=http%3A//www.tusacentral.net/joomla/index.php/mysql-blogs%3Fformat%3Dfeed%26type%3Drss

Copyright © 2002-9 Sam Ruby, Mark Pilgrim, Joseph Walton, and Phil Ringnalda