<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL &#8211; BeatificaBytes</title>
	<atom:link href="https://www.BeatificaBytes.be/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.BeatificaBytes.be</link>
	<description>The Joys of Computing</description>
	<lastBuildDate>Sun, 27 Sep 2020 10:22:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8</generator>
	<item>
		<title>How to remote access MySQL  on openHabian (RPI 4)</title>
		<link>https://www.BeatificaBytes.be/how-to-remote-access-mysql-on-openhabian-rpi-4/</link>
					<comments>https://www.BeatificaBytes.be/how-to-remote-access-mysql-on-openhabian-rpi-4/#respond</comments>
		
		<dc:creator><![CDATA[vletroye]]></dc:creator>
		<pubDate>Sun, 27 Sep 2020 10:22:20 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">http://www.beatificabytes.be/?p=4841</guid>

					<description><![CDATA[I wanted to use phpMyAdmin on a Synology to access a MySQL running on a RPI with openHabian. Here is my how-to:]]></description>
										<content:encoded><![CDATA[
<p style="text-align: justify;">I wanted to use phpMyAdmin on a Synology to access a MySQL running on a RPI with openHabian. Here is my how-to:</p>
<p style="text-align: justify;"><span class="collapseomatic " id="id69b2e49ac73fa"  tabindex="0" title="Click to Read More"    >Click to Read More</span><span id='swap-id69b2e49ac73fa'  class='colomat-swap' style='display:none;'>Click to Close</span><div id="target-id69b2e49ac73fa" class="collapseomatic_content ">
<p style="text-align: justify;">First connect on your openHabian using a ssh console.</p>
<p style="text-align: justify;">Obviously, you need MySQL to be installed and configured:</p>
<blockquote>
<p style="text-align: justify;">sudo apt update</p>
<p style="text-align: justify;"><span style="font-size: inherit;">sudo apt upgrade</span></p>
<p style="text-align: justify;"><span style="font-size: inherit;">sudo apt install mariadb-server</span></p>
<p style="text-align: justify;"><span style="font-size: inherit;">sudo mysql_secure_installation</span></p>
</blockquote>
<p style="text-align: justify;">Then, double check that MySQL is running and listening on port 3306<br />netstat -plantu | grep 3306</p>
<p style="text-align: justify;">If nothing is displayed by this command, MySQL is not listening on the port 3306.</p>
<p style="text-align: justify;">Enter MySQL as root with the command:</p>
<blockquote>
<p style="text-align: justify;">sudo mysql -uroot -p</p>
</blockquote>
<p style="text-align: justify;">Check the port used by MySQL</p>
<blockquote>
<p>SHOW GLOBAL VARIABLES LIKE &#8216;PORT&#8217;;</p>
</blockquote>
<p style="text-align: justify;">Then, type the following MySQL commands to create an account and a database, and grant both local and remote access for this account on the database:</p>
<blockquote>
<p>CREATE USER &#8216;&lt;YourAccount&gt;&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8216;&lt;YourPassword&gt;&#8217;;</p>
<p>CREATE DATABASE &lt;YourDatabase&gt;;</p>
<p>GRANT ALL PRIVILEGES ON &lt;YourDatabase&gt;.* TO &#8216;&lt;YourAccount&gt;&#8217;@&#8217;localhost&#8217;;</p>
<p>GRANT ALL PRIVILEGES ON *.* to &#8216;&lt;YourAccount&gt;&#8217;@&#8217;169.254.0.%&#8217; identified by &#8216;&lt;YourAccountPassword&gt;&#8217; WITH GRANT OPTION;</p>
<p>FLUSH PRIVILEGES;</p>
</blockquote>
<p style="text-align: justify;">Here above, I do grant access from all machines in my local network with &#8216;169.254.0.%&#8217;. One can restrict access to one machine with its specific address, such as : &#8216;169.254.0.200&#8217;</p>
<p style="text-align: justify;">Now, edit 50-server.cnf and configure MySQL to not listen anymore on its local IP only (simply comment the line bind-address) :</p>
<blockquote>
<p style="text-align: justify;">sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf</p>
</blockquote>
<pre style="text-align: justify;"># Instead of skip-networking the default is now to listen only on<br /># localhost which is more compatible and is not less secure.<br />#bind-address = 127.0.0.1</pre>
<p style="text-align: justify;">Finally, restart MySQL for the changes above to be applied:</p>
<blockquote>
<p style="text-align: justify;">sudo service mysqld restart</p>
</blockquote>
<p style="text-align: justify;">You can now edit the config of phpMyAdmin to access the MySQL on your RPI. If it is running on Synology, look <a href="https://www.beatificabytes.be/how-to-add-multiple-hosts-in-phpmyadmin-on-synology/" target="_blank" rel="noopener noreferrer">here</a>.</p>
<p style="text-align: justify;"></div>
<div class="pvc_clear"></div><p id="pvc_stats_4841" class="pvc_stats total_only  " data-element-id="4841" style=""><i class="pvc-stats-icon medium" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" version="1.0" viewBox="0 0 502 315" preserveAspectRatio="xMidYMid meet"><g transform="translate(0,332) scale(0.1,-0.1)" fill="" stroke="none"><path d="M2394 3279 l-29 -30 -3 -207 c-2 -182 0 -211 15 -242 39 -76 157 -76 196 0 15 31 17 60 15 243 l-3 209 -33 29 c-26 23 -41 29 -80 29 -41 0 -53 -5 -78 -31z"/><path d="M3085 3251 c-45 -19 -58 -50 -96 -229 -47 -217 -49 -260 -13 -295 52 -53 146 -42 177 20 16 31 87 366 87 410 0 70 -86 122 -155 94z"/><path d="M1751 3234 c-13 -9 -29 -31 -37 -50 -12 -29 -10 -49 21 -204 19 -94 39 -189 45 -210 14 -50 54 -80 110 -80 34 0 48 6 76 34 21 21 34 44 34 59 0 14 -18 113 -40 219 -37 178 -43 195 -70 221 -36 32 -101 37 -139 11z"/><path d="M1163 3073 c-36 -7 -73 -59 -73 -102 0 -56 133 -378 171 -413 34 -32 83 -37 129 -13 70 36 67 87 -16 290 -86 209 -89 214 -129 231 -35 14 -42 15 -82 7z"/><path d="M3689 3066 c-15 -9 -33 -30 -42 -48 -48 -103 -147 -355 -147 -375 0 -98 131 -148 192 -74 13 15 57 108 97 206 80 196 84 226 37 273 -30 30 -99 39 -137 18z"/><path d="M583 2784 c-38 -19 -67 -74 -58 -113 9 -42 211 -354 242 -373 16 -10 45 -18 66 -18 51 0 107 52 107 100 0 39 -1 41 -124 234 -80 126 -108 162 -133 173 -41 17 -61 16 -100 -3z"/><path d="M4250 2784 c-14 -9 -74 -91 -133 -183 -95 -150 -107 -173 -107 -213 0 -55 33 -94 87 -104 67 -13 90 8 211 198 130 202 137 225 78 284 -27 27 -42 34 -72 34 -22 0 -50 -8 -64 -16z"/><path d="M2275 2693 c-553 -48 -1095 -270 -1585 -649 -135 -104 -459 -423 -483 -476 -23 -49 -22 -139 2 -186 73 -142 361 -457 571 -626 285 -228 642 -407 990 -497 242 -63 336 -73 660 -74 310 0 370 5 595 52 535 111 1045 392 1455 803 122 121 250 273 275 326 19 41 19 137 0 174 -41 79 -309 363 -465 492 -447 370 -946 591 -1479 653 -113 14 -422 18 -536 8z m395 -428 c171 -34 330 -124 456 -258 112 -119 167 -219 211 -378 27 -96 24 -300 -5 -401 -72 -255 -236 -447 -474 -557 -132 -62 -201 -76 -368 -76 -167 0 -236 14 -368 76 -213 98 -373 271 -451 485 -162 444 86 934 547 1084 153 49 292 57 452 25z m909 -232 c222 -123 408 -262 593 -441 76 -74 138 -139 138 -144 0 -16 -233 -242 -330 -319 -155 -123 -309 -223 -461 -299 l-81 -41 32 46 c18 26 49 83 70 128 143 306 141 649 -6 957 -25 52 -61 116 -79 142 l-34 47 45 -20 c26 -10 76 -36 113 -56z m-2057 25 c-40 -58 -105 -190 -130 -263 -110 -324 -59 -707 132 -981 25 -35 42 -64 37 -64 -19 0 -241 119 -326 174 -188 122 -406 314 -532 468 l-58 71 108 103 c185 178 428 349 672 473 66 33 121 60 123 61 2 0 -10 -19 -26 -42z"/><path d="M2375 1950 c-198 -44 -350 -190 -395 -379 -18 -76 -8 -221 19 -290 114 -284 457 -406 731 -260 98 52 188 154 231 260 27 69 37 214 19 290 -38 163 -166 304 -326 360 -67 23 -215 33 -279 19z"/></g></svg></i> <img decoding="async" width="16" height="16" alt="Loading" src="https://www.BeatificaBytes.be/wp-content/plugins/page-views-count/ajax-loader-2x.gif" border=0 /></p><div class="pvc_clear"></div>]]></content:encoded>
					
					<wfw:commentRss>https://www.BeatificaBytes.be/how-to-remote-access-mysql-on-openhabian-rpi-4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>From WordPress 3.3 to 3.4 on Synology: Almost YAUN !!</title>
		<link>https://www.BeatificaBytes.be/yaun-from-wordpress-3-3-to-3-4-on-synology/</link>
					<comments>https://www.BeatificaBytes.be/yaun-from-wordpress-3-3-to-3-4-on-synology/#respond</comments>
		
		<dc:creator><![CDATA[vletroye]]></dc:creator>
		<pubDate>Sat, 03 Nov 2012 23:01:06 +0000</pubDate>
				<category><![CDATA[Synology]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[DS209+]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">/wordpress/?p=588</guid>

					<description><![CDATA[No! I don&#8217;t mean &#8220;Yet Another Unix Nerd&#8221;!!! But upgrading WordPress from 3.3 to 3.4 on my DS209+ was almost &#8220;Yet Another Upgrade Nightmare&#8221; 🙂]]></description>
										<content:encoded><![CDATA[<p style="text-align: justify">No! I don&#8217;t mean &#8220;Yet Another Unix Nerd&#8221;!!!</p>
<p style="text-align: justify">But upgrading WordPress from 3.3 to 3.4 on my DS209+ was almost &#8220;Yet Another Upgrade Nightmare&#8221; <img src="https://s.w.org/images/core/emoji/15.1.0/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p style="text-align: justify"><span class="collapseomatic " id="id69b2e49ac8e99"  tabindex="0" title="Click to Read More"    >Click to Read More</span><span id='swap-id69b2e49ac8e99'  class='colomat-swap' style='display:none;'>Click to Close</span><div id="target-id69b2e49ac8e99" class="collapseomatic_content "></p>
<p style="text-align: justify">Upgrading a package for Synology is usually really a piece of cake. Unfortunately, the upgrade package for WordPress caused me difficulties.</p>
<p style="text-align: justify"><span style="text-decoration: underline"><strong>First issue: MySQL password</strong></span></p>
<p style="text-align: justify">The setup failed quite immediately after downloading, complaining that there was possibly an issue with the MySQL password. After some investigation, it appeared to me that :</p>
<ul style="text-align: justify">
<li>the DSM Package Center is running as Synology&#8217;s &#8220;root&#8221; user and</li>
<li>the setup of WordPress was trying to access MySql with that account but without any password.</li>
</ul>
<div style="text-align: justify">I found on Synology&#8217;s Forum that &#8220;<em>Current wordpress package requires an default mysql account root with empty password to create database successfully. If you have set mysql root password before, please install phpMyAdmin to reset the password first.</em>&#8220;</div>
<div style="text-align: justify"></div>
<p style="text-align: justify">And unfortunately (although quite normal), I did set a password for the MySql &#8220;root&#8221; user in the past&#8230; So, as suggested in the message above, I did reset MySql root password to blank.</p>
<div style="text-align: justify">
<ul>
<li>Go to phpMyAdmin, opened the &#8220;Users&#8221; tab and clicked &#8220;Edit Privileges&#8221; for the user &#8220;root&#8221; with Host=localhost.</li>
<li>In the &#8220;Edit Privileges&#8221; dialog box, scroll down to the &#8220;Change Password&#8221; area and select &#8220;No Password&#8221; before clicking &#8220;Go&#8221;.</li>
<li>Finally, back to the &#8220;Users&#8221; page, click &#8220;Create PHP code&#8221; to apply the change. At that moment, phpMyAdmin could prompt you to re-enter your credentials (root with a blank password).</li>
</ul>
</div>
<p style="text-align: justify">I did next restart the update of the WordPress which finally completed fine. But&#8230;</p>
<p style="text-align: justify"><span style="text-decoration: underline"><strong>Next issue: Page Not Found</strong></span></p>
<p style="text-align: justify">My Blog was not reachable anymore after the upgrade ? Damned&#8230; WordPress was imply disabled&#8230; I had to click &#8220;Start&#8221; next to the WordPress Package in the DSM Package Center <img src="https://s.w.org/images/core/emoji/15.1.0/72x72/1f606.png" alt="😆" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p style="text-align: justify">And finally, my home page appeared&#8230; I went immediately to the administration dashboard where I discovered that the setup was actually not yet complete. In this dashboard, I found a message asking me to click a button to upgrade the database. Fortunately, nothing wrong occurred during this upgrade <img src="https://s.w.org/images/core/emoji/15.1.0/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p style="text-align: justify"><span style="text-decoration: underline"><strong>Last issue: </strong></span><span style="text-decoration: underline"><strong>This is somewhat embarrassing, isn’t it?</strong></span></p>
<p style="text-align: justify">Although the home page appeared correctly, I was not able to open anything else: no post, no &#8220;custom&#8221; pages, no categories, &#8230; For each of them, I got the WordPress&#8217; &#8220;Page Not Found&#8221;&#8230; All the permalinks appeared somewhat &#8220;corrupted&#8221;&#8230; No idea why.</p>
<p style="text-align: justify">Fortunately (bis ter et repetita), fixing this issue was not difficult. I simply had to re-enforce the right Permalinks structure.</p>
<ul>
<li>Go back to the administration dashboard and select the menu &#8220;Permalinks&#8221; under &#8220;Settings&#8221;.</li>
<li>Check that &#8220;your&#8221; structure of Permalinks is still selected and did click &#8220;Save Changes&#8221; (Even if you didn&#8217;t change the structure).</li>
</ul>
<p>And miracle! Everything went back to normal. <span style="text-align: justify">I didn&#8217;t lose any customization or plugins except my custom smilies from \web\wordpress\wp-includes\images\smilies (fortunately backuped),&#8230;</span></p>
<p><span style="text-align: justify">YASU!!</span></p>
<p><span style="text-align: justify">No! I Don&#8217;t mean &#8220;Yet Another System Utility&#8221;!!! But &#8220;Yet Another Successful Update&#8221; <img src="https://s.w.org/images/core/emoji/15.1.0/72x72/1f606.png" alt="😆" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span></p>
<p style="text-align: justify"></div></p>
<div class="pvc_clear"></div>
<p id="pvc_stats_588" class="pvc_stats total_only  " data-element-id="588" style=""><i class="pvc-stats-icon medium" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" version="1.0" viewBox="0 0 502 315" preserveAspectRatio="xMidYMid meet"><g transform="translate(0,332) scale(0.1,-0.1)" fill="" stroke="none"><path d="M2394 3279 l-29 -30 -3 -207 c-2 -182 0 -211 15 -242 39 -76 157 -76 196 0 15 31 17 60 15 243 l-3 209 -33 29 c-26 23 -41 29 -80 29 -41 0 -53 -5 -78 -31z"/><path d="M3085 3251 c-45 -19 -58 -50 -96 -229 -47 -217 -49 -260 -13 -295 52 -53 146 -42 177 20 16 31 87 366 87 410 0 70 -86 122 -155 94z"/><path d="M1751 3234 c-13 -9 -29 -31 -37 -50 -12 -29 -10 -49 21 -204 19 -94 39 -189 45 -210 14 -50 54 -80 110 -80 34 0 48 6 76 34 21 21 34 44 34 59 0 14 -18 113 -40 219 -37 178 -43 195 -70 221 -36 32 -101 37 -139 11z"/><path d="M1163 3073 c-36 -7 -73 -59 -73 -102 0 -56 133 -378 171 -413 34 -32 83 -37 129 -13 70 36 67 87 -16 290 -86 209 -89 214 -129 231 -35 14 -42 15 -82 7z"/><path d="M3689 3066 c-15 -9 -33 -30 -42 -48 -48 -103 -147 -355 -147 -375 0 -98 131 -148 192 -74 13 15 57 108 97 206 80 196 84 226 37 273 -30 30 -99 39 -137 18z"/><path d="M583 2784 c-38 -19 -67 -74 -58 -113 9 -42 211 -354 242 -373 16 -10 45 -18 66 -18 51 0 107 52 107 100 0 39 -1 41 -124 234 -80 126 -108 162 -133 173 -41 17 -61 16 -100 -3z"/><path d="M4250 2784 c-14 -9 -74 -91 -133 -183 -95 -150 -107 -173 -107 -213 0 -55 33 -94 87 -104 67 -13 90 8 211 198 130 202 137 225 78 284 -27 27 -42 34 -72 34 -22 0 -50 -8 -64 -16z"/><path d="M2275 2693 c-553 -48 -1095 -270 -1585 -649 -135 -104 -459 -423 -483 -476 -23 -49 -22 -139 2 -186 73 -142 361 -457 571 -626 285 -228 642 -407 990 -497 242 -63 336 -73 660 -74 310 0 370 5 595 52 535 111 1045 392 1455 803 122 121 250 273 275 326 19 41 19 137 0 174 -41 79 -309 363 -465 492 -447 370 -946 591 -1479 653 -113 14 -422 18 -536 8z m395 -428 c171 -34 330 -124 456 -258 112 -119 167 -219 211 -378 27 -96 24 -300 -5 -401 -72 -255 -236 -447 -474 -557 -132 -62 -201 -76 -368 -76 -167 0 -236 14 -368 76 -213 98 -373 271 -451 485 -162 444 86 934 547 1084 153 49 292 57 452 25z m909 -232 c222 -123 408 -262 593 -441 76 -74 138 -139 138 -144 0 -16 -233 -242 -330 -319 -155 -123 -309 -223 -461 -299 l-81 -41 32 46 c18 26 49 83 70 128 143 306 141 649 -6 957 -25 52 -61 116 -79 142 l-34 47 45 -20 c26 -10 76 -36 113 -56z m-2057 25 c-40 -58 -105 -190 -130 -263 -110 -324 -59 -707 132 -981 25 -35 42 -64 37 -64 -19 0 -241 119 -326 174 -188 122 -406 314 -532 468 l-58 71 108 103 c185 178 428 349 672 473 66 33 121 60 123 61 2 0 -10 -19 -26 -42z"/><path d="M2375 1950 c-198 -44 -350 -190 -395 -379 -18 -76 -8 -221 19 -290 114 -284 457 -406 731 -260 98 52 188 154 231 260 27 69 37 214 19 290 -38 163 -166 304 -326 360 -67 23 -215 33 -279 19z"/></g></svg></i> <img decoding="async" width="16" height="16" alt="Loading" src="https://www.BeatificaBytes.be/wp-content/plugins/page-views-count/ajax-loader-2x.gif" border=0 /></p>
<div class="pvc_clear"></div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.BeatificaBytes.be/yaun-from-wordpress-3-3-to-3-4-on-synology/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Schedule a Backup of all your MySQL databases on Synology</title>
		<link>https://www.BeatificaBytes.be/schedule-a-backup-of-all-your-mysql-databases-on-synology/</link>
					<comments>https://www.BeatificaBytes.be/schedule-a-backup-of-all-your-mysql-databases-on-synology/#comments</comments>
		
		<dc:creator><![CDATA[vletroye]]></dc:creator>
		<pubDate>Sat, 29 Sep 2012 20:26:08 +0000</pubDate>
				<category><![CDATA[Synology]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[DS209+]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">/wordpress/?p=127</guid>

					<description><![CDATA[It would be a good idea to schedule a daily backup of all the MySQL databases on your Synology. Those will indeed be wiped out [&#8230;]]]></description>
										<content:encoded><![CDATA[<p style="text-align: justify;">It would be a good idea to schedule a daily backup of all the MySQL databases on your Synology. Those will indeed be wiped out if by accident, you have to reset your NAS (reinstall the firmware), ex.: if you lose a disk in your RAID 0.</p>
<p style="text-align: justify;">That can be done using a shell script and a cron job as described here after.</p>
<p style="text-align: justify;"><span class="collapseomatic " id="id69b2e49ace1d1"  tabindex="0" title="How to Backup"    >How to Backup</span><span id='swap-id69b2e49ace1d1'  class='colomat-swap' style='display:none;'>Click to close</span><div id="target-id69b2e49ace1d1" class="collapseomatic_content "><br />
First, create a user with a local-read-only access on the databases. We will indeed have to let its password in the script, endangering the security. Using a local-read-only user will mitigate the risks.</p>
<ol style="text-align: justify;">
<li>Go to the web administration interface (DSM) of your NAS.</li>
<li>Install phpMYAdmin via the &#8220;Package Center&#8221; if not yet done.</li>
<li>Open phpMyAdmin via the &#8220;Start Menu&#8221; (&#8220;Main Menu&#8221;).
<ol>
<li>I am using the login &#8216;root&#8217; with the password of Syno&#8217;s &#8216;admin&#8217; user</li>
</ol>
</li>
<li>Open the &#8220;Users&#8221; tab in phpMyAdmin</li>
<li>Click &#8220;Add User&#8221; (bellow the list of existing users)</li>
<li>Enter the User Name. Ex.: backup</li>
<li>Select “localhost” as an Host.</li>
<li>Enter a password. Ex.: mysql</li>
<li>Keep “none” as “Database for user”</li>
<li>Grant the user with Global privileges: Select (in Data) and Reload, Show Databases and Lock Tables (in Administration)</li>
<li>Click “Add User” at the botton of the page</li>
</ol>
<p style="text-align: justify;">Next, create a shell scripts in a Shared Folder of the NAS (Ex.: \volume1\backup\backupMySql.sh). Working in a Shared Folder will make it easier for you to copy/open later the backups from your PC). Don&#8217;t forget to create a &#8220;Unix&#8221; file, either using the touch command in a Console or saving a file As a &#8220;Unix shell script&#8221; within Notepad++. Notice that a script created with NotePad++ and saved on the Shared Folder will belong to the user account accessing that Shared Folder (Most probably your Windows Account if like me you simply created a user on your NAS with the same login and password). A script created with &#8220;touch&#8221; in a Console will belong to the user accessing the NAS via telnet/SSH (Most probably the &#8220;root&#8221; account).</p>
<pre>[shell]#!/bin/sh
#
DIR=/volume1/backup/sqlbackup/
DATESTAMP=$(date +%Y%m%d%H%M%S)
DB_USER=backup
DB_PASS=mysql

# create backup dir if it does not exist
mkdir -p ${DIR}

# remove backups older than $DAYS_KEEP
#DAYS_KEEP=30
#find ${DIR}* -mtime +$DAYS_KEEP -exec rm -f {} \; 2&gt; /dev/null

# remove all backups except the $KEEP latest
KEEP=5
BACKUPS=`find ${DIR} -name 'mysqldump-*.gz' | wc -l | sed 's/\ //g'`
while [ $BACKUPS -ge $KEEP ]
do
  ls -tr1 ${DIR}mysqldump-*.gz | head -n 1 | xargs rm -f
  BACKUPS=`expr $BACKUPS - 1`
done

#
# create backups securely
#umask 006

# dump all the databases in a gzip file
FILENAME=${DIR}mysqldump-${DATESTAMP}.gz
/usr/syno/mysql/bin/mysqldump --user=$DB_USER --password=$DB_PASS --opt --all-databases --flush-logs | gzip &gt;&gt; $FILENAME
[/shell]
</pre>
<p style="text-align: justify;">NB: Since DSM 6.0, “/usr/syno/mysql/bin/mysqldump” has been moved to “/bin/mysqldump” !!!</p>
<p style="text-align: justify;">Possibly, type the following command in a Console (telnet/SSH) to set the user &#8216;root&#8217; as owner of the script:</p>
<pre>[shell]chown root /volume1/backup/backupMySql.sh[/shell]</pre>
<p style="text-align: justify;">IMPORTANT notice: I used to have &#8220;-u DB_USER&#8221; (with a blank space in between) in my script above and -&#8220;p$DB_USER&#8221; (without a blank) instead of &#8211;user and &#8211;password. But a reader (Fredy) reported that the script was not running fine for him unless removing the blank. As per documentation of mysqldump&#8217;s <a title="SqlDump User Param" href="http://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_user" target="_blank" rel="noopener noreferrer">user parameter</a> and <a title="SqlDump Password Param" href="http://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_user" target="_blank" rel="noopener noreferrer">password parameter</a>, there should be a blank after -u but not after -p. However, samples on the web usually illustrate the use of mysqldump with &#8220;-uroot&#8221;. So, I decided to use the more explicit notation &#8220;&#8211;user=&#8221; and &#8220;&#8211;password=&#8221;. I did test this notation with a wrong username or password and the resulting dump is indeed empty. With the correct username and password, it works fine.</p>
<p style="text-align: justify;">Since DSM 4.2, the Task Scheduler can be used to run the script on a daily basis.</p>
<ol style="text-align: justify;">
<li>Go to the Start Menu</li>
<li>Open the Control Panel</li>
<li>In the &#8220;Application Settings&#8221;, open the Task Scheduler</li>
<li>Select &#8220;Create a User-Defined Script&#8221;</li>
<li>Type a name for that &#8220;Task:&#8221;</li>
<li>Keep the &#8220;User:&#8221; root</li>
<li>In the &#8220;Run Command&#8221; pane, type:
<pre>sh /volume1/backup/backupMySql.sh</pre>
</li>
</ol>
<p style="text-align: justify;">Don&#8217;t forget the &#8220;sh&#8221; in front of your command, otherwise, it does not work (although the sample provided by Synology is missing it ?!)</p>
<p style="text-align: justify;">If you don&#8217;t use the Task Scheduler, you can add a Cron Job to execute the script, e.g. every day at 0:01. Open a Console (Telnet/SSH) and type:</p>
<pre>[shell]echo "1       0       *       *       *       root    sh /volume1/backup/backupMySql.sh" &gt;&gt; /etc/crontab[/shell]</pre>
<p style="text-align: justify;">FYI, a cron line syntax is &#8220;mm hh dd MMM DDD user task&#8221; where:</p>
<ul style="text-align: justify;">
<li>mm is the minute (0..59)</li>
<li>hh is the hour (0..23)</li>
<li>dd is the day in the month (1..31)</li>
<li>MMM is the month (jan, feb, &#8230; or 1..12)</li>
<li>DDD is the day in the week (sun, mon, &#8230; or 0..7 where 0 and 7 beeing both sunday)</li>
</ul>
<p style="text-align: justify;">The following values can also be used:</p>
<ul style="text-align: justify;">
<li>* : a every unit (0, 1, 2, 3, 4&#8230;)</li>
<li>5,8 : at unit 5 et 8</li>
<li>2-5 : units 2 to 5 (2, 3, 4, 5)</li>
<li>*/3 : every 3 units (0, 3, 6, 9&#8230;)</li>
<li>10-20/3 : every 3 units, from 10th to 20th (10, 13, 16, 19)</li>
</ul>
<p style="text-align: justify;">So, the script will start every day at 0:01h</p>
<p style="text-align: justify;">Finally, you must restart the cron daemon to activate the new job. To find the process id and send a SIGHUP signal to this one, type the following command line in a Console (Telnet/SSH):</p>
<pre>[shell]ps | grep crond | grep -v grep | awk '{print$1}' | xargs -t kill -HUP[/shell]</pre>
<p style="text-align: justify;">It should display &#8220;Kill -HUP xxxx&#8221; where xxx is the pid of the cron daemon.<br />
</div></p>
<p style="text-align: justify;"><span class="collapseomatic " id="id69b2e49ace272"  tabindex="0" title="Added on 03/01/2013"    >Added on 03/01/2013</span><span id='swap-id69b2e49ace272'  class='colomat-swap' style='display:none;'>Click to Close</span><div id="target-id69b2e49ace272" class="collapseomatic_content "></p>
<p style="text-align: justify;"><span style="text-decoration: underline;">Attention</span>: if you copy paste the command to restart the cron daemon from this page into the telnet console, some symbols will be wiped out: the ‘{ and ‘ around print$1… you have to type them manually…</p>
<p style="text-align: justify;"><span style="text-decoration: underline;">Attention</span>: if you upgrade the version of DSM, the changes made in the cron script are lost (at least, it&#8217;s what I have noticed after updating last month&#8230;). Reason why I recommend to use the new &#8220;Task Scheduler&#8221; feature available since DSM 4.2.</p>
<p style="text-align: justify;"><span style="text-decoration: underline;">Tip to edit the cron script</span>: you can use the package &#8220;Config File Editor&#8221; available <a title="Config File Editor for Synology" href="http://www.mertymade.com/syno/#cfe" target="_blank" rel="noopener noreferrer">here</a>. Once installed, you can access it via the Main Menu. Then, you have to edit the file named &#8220;Config File Editor&#8221; and add the following line:</p>
<p style="padding-left: 30px; text-align: justify;"><code>/etc/crontab,crontab</code></p>
<p style="text-align: justify;">Once this line is added and saved, &#8230; I don&#8217;t remember how to force the change to be taken into account :/. But restarting the DiskStation is enough <img src="https://s.w.org/images/core/emoji/15.1.0/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p style="text-align: justify;">Finally, back into the Config File Editor, select the &#8216;crontab&#8217; entry and modify this script, save your changes and restart the cron daemon.</p>
<p style="text-align: justify;"><span style="text-decoration: underline;">Tip to restart the cron daemon</span>: you can use the package &#8220;MODS Web Console&#8221; available <a title="Wec Console for Synology" href="https://www.beatificabytes.be/sspks/?arch=all#" target="_blank" rel="noopener noreferrer">here</a>. To install it, go to the Package Center and add the following url via the Settings &gt; Package Sources : <a href="https://www.beatificabytes.be/sspks" target="_blank" rel="noopener noreferrer">https://www.beatificabytes.be/sspks</a>. Once this url added, go to the tab &#8220;Community&#8221; and click Install on the &#8220;MODS Web Console&#8221; icon.</p>
<p style="text-align: justify;">Run the Web Console via the Main Menu, log in with &#8220;admin&#8221;/&#8221;admin&#8221; (The defaults values if not changed) and type:</p>
<p style="padding-left: 30px; text-align: justify;"><code>synoservice --restart crond</code></p>
<p style="text-align: justify;"></div></p>
<p style="text-align: justify;"><span class="collapseomatic " id="id69b2e49ace2d6"  tabindex="0" title="Added on 01/12/2013"    >Added on 01/12/2013</span><span id='swap-id69b2e49ace2d6'  class='colomat-swap' style='display:none;'>Click to Close</span><div id="target-id69b2e49ace2d6" class="collapseomatic_content "></p>
<p style="text-align: justify;">If you want a lazy solution to notify the Administrator about the success or failure of the backup, you can use the &#8216;synonotify&#8217; command (See <a title="Use Synology Notifications" href="https://www.beatificabytes.be/send-custom-email-notifications-from-scripts-running-on-a-synology/" target="_blank" rel="noopener noreferrer">details here</a>). A more advanced solution would be to configure the &#8220;Mail Server&#8221; and use its &#8216;sendmail&#8217; command:  /volume1/@appstore/MailServer/sbin/sendmail&#8230;</p>
<p style="text-align: justify;"></div></p>
<p style="text-align: justify;"><span class="collapseomatic " id="id69b2e49ace334"  tabindex="0" title="Added on 08/01/2017"    >Added on 08/01/2017</span><span id='swap-id69b2e49ace334'  class='colomat-swap' style='display:none;'>Click to Close</span><div id="target-id69b2e49ace334" class="collapseomatic_content "><br />
mysqldump has moved</p>
<ul>
<li>DSM 6.0 : /usr/syno/mysql/bin/mysqldump</li>
<li>MariaDB 5: /volume1/@appstore/MariaDB/usr/bin/mysqldump<br />
MariaDB 10: /volume1/@appstore/MariaDB10/usr/local/mariadb10/bin/mysqldump</li>
<li style="text-align: justify;"></div></li>
</ul>
<p style="text-align: justify;"><span class="collapseomatic " id="id69b2e49ace390"  tabindex="0" title="How to Restore"    >How to Restore</span><span id='swap-id69b2e49ace390'  class='colomat-swap' style='display:none;'>Click to Close</span><div id="target-id69b2e49ace390" class="collapseomatic_content "></p>
<p style="text-align: justify;">To do a full restore, simply:</p>
<ol style="text-align: justify;">
<li>Copy the archive (.gz) you plan to restore on your local PC</li>
<li>Go to &#8220;phpyMyAdmin&#8221; &gt; &#8220;Import&#8221; &gt; &#8220;Chose File&#8221; (next to <em>Browse your computer</em>).</li>
<li>Select the .gz file to be restored</li>
<li>Press &#8220;Go&#8221; at the bottom of the page (no need to change any settings)</li>
</ol>
<p style="text-align: justify;">Pay attention: this is a complete restore, I.e.: all databases are dropped and recreated from scratch.</p>
<p style="text-align: justify;">If you want to be able to restore a subset of your databases you better have to change the script to backup specific databases instead of &#8211;all-database.</p>
<p style="text-align: justify;">If you want to restore only one table &#8216;mytable&#8217; from the backup &#8216;<em>mysqldump-datetime.gz&#8217;</em>:</p>
<ol style="text-align: justify;">
<li>Unzip first the archive: gunzip <em>mysqldump-datetime.gz</em></li>
<li>Then extract the part that restore the desired table with this command: sed -n -e &#8216;/DROP TABLE.*<em>mytable</em>/,/UNLOCK TABLES;/p&#8217; <em>mysqldump-datetime</em> &gt; <em>mytabledump</em></li>
</ol>
<p style="text-align: justify;"></div><br />
Download the script <a href="http://valery.letroye.be/BeatificaBytes/backupMySql.sh" target="_blank" rel="noopener noreferrer">here</a>.</p>
<div class="pvc_clear"></div>
<p id="pvc_stats_127" class="pvc_stats total_only  " data-element-id="127" style=""><i class="pvc-stats-icon medium" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" version="1.0" viewBox="0 0 502 315" preserveAspectRatio="xMidYMid meet"><g transform="translate(0,332) scale(0.1,-0.1)" fill="" stroke="none"><path d="M2394 3279 l-29 -30 -3 -207 c-2 -182 0 -211 15 -242 39 -76 157 -76 196 0 15 31 17 60 15 243 l-3 209 -33 29 c-26 23 -41 29 -80 29 -41 0 -53 -5 -78 -31z"/><path d="M3085 3251 c-45 -19 -58 -50 -96 -229 -47 -217 -49 -260 -13 -295 52 -53 146 -42 177 20 16 31 87 366 87 410 0 70 -86 122 -155 94z"/><path d="M1751 3234 c-13 -9 -29 -31 -37 -50 -12 -29 -10 -49 21 -204 19 -94 39 -189 45 -210 14 -50 54 -80 110 -80 34 0 48 6 76 34 21 21 34 44 34 59 0 14 -18 113 -40 219 -37 178 -43 195 -70 221 -36 32 -101 37 -139 11z"/><path d="M1163 3073 c-36 -7 -73 -59 -73 -102 0 -56 133 -378 171 -413 34 -32 83 -37 129 -13 70 36 67 87 -16 290 -86 209 -89 214 -129 231 -35 14 -42 15 -82 7z"/><path d="M3689 3066 c-15 -9 -33 -30 -42 -48 -48 -103 -147 -355 -147 -375 0 -98 131 -148 192 -74 13 15 57 108 97 206 80 196 84 226 37 273 -30 30 -99 39 -137 18z"/><path d="M583 2784 c-38 -19 -67 -74 -58 -113 9 -42 211 -354 242 -373 16 -10 45 -18 66 -18 51 0 107 52 107 100 0 39 -1 41 -124 234 -80 126 -108 162 -133 173 -41 17 -61 16 -100 -3z"/><path d="M4250 2784 c-14 -9 -74 -91 -133 -183 -95 -150 -107 -173 -107 -213 0 -55 33 -94 87 -104 67 -13 90 8 211 198 130 202 137 225 78 284 -27 27 -42 34 -72 34 -22 0 -50 -8 -64 -16z"/><path d="M2275 2693 c-553 -48 -1095 -270 -1585 -649 -135 -104 -459 -423 -483 -476 -23 -49 -22 -139 2 -186 73 -142 361 -457 571 -626 285 -228 642 -407 990 -497 242 -63 336 -73 660 -74 310 0 370 5 595 52 535 111 1045 392 1455 803 122 121 250 273 275 326 19 41 19 137 0 174 -41 79 -309 363 -465 492 -447 370 -946 591 -1479 653 -113 14 -422 18 -536 8z m395 -428 c171 -34 330 -124 456 -258 112 -119 167 -219 211 -378 27 -96 24 -300 -5 -401 -72 -255 -236 -447 -474 -557 -132 -62 -201 -76 -368 -76 -167 0 -236 14 -368 76 -213 98 -373 271 -451 485 -162 444 86 934 547 1084 153 49 292 57 452 25z m909 -232 c222 -123 408 -262 593 -441 76 -74 138 -139 138 -144 0 -16 -233 -242 -330 -319 -155 -123 -309 -223 -461 -299 l-81 -41 32 46 c18 26 49 83 70 128 143 306 141 649 -6 957 -25 52 -61 116 -79 142 l-34 47 45 -20 c26 -10 76 -36 113 -56z m-2057 25 c-40 -58 -105 -190 -130 -263 -110 -324 -59 -707 132 -981 25 -35 42 -64 37 -64 -19 0 -241 119 -326 174 -188 122 -406 314 -532 468 l-58 71 108 103 c185 178 428 349 672 473 66 33 121 60 123 61 2 0 -10 -19 -26 -42z"/><path d="M2375 1950 c-198 -44 -350 -190 -395 -379 -18 -76 -8 -221 19 -290 114 -284 457 -406 731 -260 98 52 188 154 231 260 27 69 37 214 19 290 -38 163 -166 304 -326 360 -67 23 -215 33 -279 19z"/></g></svg></i> <img decoding="async" width="16" height="16" alt="Loading" src="https://www.BeatificaBytes.be/wp-content/plugins/page-views-count/ajax-loader-2x.gif" border=0 /></p>
<div class="pvc_clear"></div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.BeatificaBytes.be/schedule-a-backup-of-all-your-mysql-databases-on-synology/feed/</wfw:commentRss>
			<slash:comments>56</slash:comments>
		
		
			</item>
	</channel>
</rss>
