<?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 | KC's Blog</title>
	<atom:link href="https://www.kjctech.net/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.kjctech.net</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2023 18:20:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/www.kjctech.net/wp-content/uploads/2016/12/cropped-KC-Logo.png?fit=32%2C32&#038;ssl=1</url>
	<title>MySQL | KC's Blog</title>
	<link>https://www.kjctech.net</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">24634607</site>	<item>
		<title>Monitoring and Restart MySQL Service Automatically with Monit</title>
		<link>https://www.kjctech.net/monitoring-and-restart-mysql-service-automatically-with-monit/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-and-restart-mysql-service-automatically-with-monit</link>
					<comments>https://www.kjctech.net/monitoring-and-restart-mysql-service-automatically-with-monit/#respond</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Tue, 25 Feb 2020 07:14:52 +0000</pubDate>
				<category><![CDATA[Network]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Monit]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">https://www.kjctech.net/?p=4449</guid>

					<description><![CDATA[<p>I have a Ubuntu VPS that runs a bunch of websites powered by MySQL server at the back end. For whatever reason, the websites just kept turning down because of the crush of the MySQL service. I could scale up the server to dip in more memory or set up some sort of monitoring system to monitor and restart MySQL [&#8230;]</p>
The post <a href="https://www.kjctech.net/monitoring-and-restart-mysql-service-automatically-with-monit/">Monitoring and Restart MySQL Service Automatically with Monit</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>I have a Ubuntu VPS that runs a bunch of websites powered by MySQL server at the back end. For whatever reason, the websites just kept turning down because of the crush of the MySQL service. I could scale up the server to dip in more memory or set up some sort of monitoring system to monitor and restart MySQL service when it&#8217;s down.</p>



<p>I took the latter route with the help of <a rel="noreferrer noopener" aria-label="m/monit (opens in a new tab)" href="https://mmonit.com/monit/" target="_blank">m/monit</a>, a small open-source utility for managing and monitoring Linux systems.  Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. </p>



<figure class="wp-block-image size-large"><a href="//i0.wp.com/kjctech.net/wp-content/uploads/2020/02/image.png" data-rel="lightbox-image-0" data-rl_title="" data-rl_caption="" title=""><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="600" height="231" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image.png?resize=600%2C231&#038;ssl=1" alt="" class="wp-image-4450" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image.png?resize=600%2C231&amp;ssl=1 600w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image.png?resize=450%2C173&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image.png?resize=250%2C96&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image.png?resize=768%2C296&amp;ssl=1 768w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image.png?resize=700%2C269&amp;ssl=1 700w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image.png?resize=520%2C200&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image.png?resize=360%2C139&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image.png?resize=100%2C38&amp;ssl=1 100w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image.png?w=1177&amp;ssl=1 1177w" sizes="(max-width: 600px) 100vw, 600px" /></a></figure>



<p> While it may sound complicated, setting it up is actually quite straightforward.</p>



<h2 class="wp-block-heading">Installation</h2>



<p>As always, update the system first to keep the system update-to-date first.</p>



<pre class="wp-block-preformatted">sudo apt update &amp; sudo apt upgrade</pre>



<p>Then, install Monit from the Ubuntu repository.</p>



<pre class="wp-block-preformatted">sudo apt install monit</pre>



<p>To verify the version after the installation, </p>



<pre class="wp-block-preformatted">sudo monit -V</pre>



<h2 class="wp-block-heading">Configure the web service</h2>



<p>The nice thing about Monit is that it comes with a web interface for monitoring and managing the configured services. The default port is on 2812 but you can change that by modifying the configuration file.</p>



<pre class="wp-block-preformatted">sudo nano /etc/monit/monitrc</pre>



<p>First, change the default monitoring interval if needed.</p>



<pre class="wp-block-preformatted">set daemon 120</pre>



<p>Then, to enable and change the web interface settings, uncomment or change the following lines.</p>



<pre class="wp-block-preformatted">set httpd port 2812
  use address localhost    # only accept connection from localhost
  allow admin:monit        # required user credential</pre>



<p>If you need to check the web interface remotely, comment out the localhost line and add the following instead.</p>



<pre class="wp-block-preformatted">allow ipaddress/32</pre>



<h2 class="wp-block-heading">Monitoring MySQL and Apache services</h2>



<p>To monitor the MySQL service,</p>



<pre class="wp-block-preformatted">sudo nano /etc/monit/conf.d/mysql</pre>



<p>and add the following lines:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: Code example:; notranslate">
check process mysql with pidfile /run/mysqld/mysqld.pid
    start program = &quot;/usr/sbin/service mysql start&quot; with timeout 60 seconds
    stop program  = &quot;/usr/sbin/service mysql stop&quot;
    if failed unixsocket /var/run/mysqld/mysqld.sock then restart
</pre></div>


<p>To monitor the Apache service,</p>



<pre class="wp-block-preformatted">sudo nano /etc/monit/conf.d/apache</pre>



<p>and add the following lines:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: Code example:; notranslate">
check process apache2 with pidfile /run/apache2/apache2.pid
    start program = &quot;/bin/systemctl start apache2.service&quot; with timeout 15 seconds
    stop program  = &quot;/bin/systemctl stop apache2.service&quot;
    restart program = &quot;/bin/systemctl restart apache2.service&quot;
</pre></div>


<p>Now, reload the Monit service,</p>



<pre class="wp-block-preformatted">sudo service monit reload</pre>



<p>And check the web interface now.</p>



<figure class="wp-block-image size-large"><a href="//i0.wp.com/kjctech.net/wp-content/uploads/2020/02/image-1.png" data-rel="lightbox-image-1" data-rl_title="" data-rl_caption="" title=""><img decoding="async" width="1208" height="690" src="https://i1.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image-1.png?fit=600%2C343&amp;ssl=1" alt="" class="wp-image-4451" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image-1.png?w=1208&amp;ssl=1 1208w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image-1.png?resize=450%2C257&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image-1.png?resize=600%2C343&amp;ssl=1 600w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image-1.png?resize=250%2C143&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image-1.png?resize=768%2C439&amp;ssl=1 768w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image-1.png?resize=700%2C400&amp;ssl=1 700w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image-1.png?resize=520%2C297&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image-1.png?resize=360%2C206&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2020/02/image-1.png?resize=100%2C57&amp;ssl=1 100w" sizes="(max-width: 640px) 100vw, 640px" /></a></figure>The post <a href="https://www.kjctech.net/monitoring-and-restart-mysql-service-automatically-with-monit/">Monitoring and Restart MySQL Service Automatically with Monit</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/monitoring-and-restart-mysql-service-automatically-with-monit/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4449</post-id>	</item>
		<item>
		<title>Fixing Unknown Collation utf8mb4_unicode_520_ci</title>
		<link>https://www.kjctech.net/fixing-unknown-collation-utf8mb4_unicode_520_ci/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fixing-unknown-collation-utf8mb4_unicode_520_ci</link>
					<comments>https://www.kjctech.net/fixing-unknown-collation-utf8mb4_unicode_520_ci/#respond</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Fri, 02 Nov 2018 00:06:11 +0000</pubDate>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">https://www.kjctech.net/?p=4213</guid>

					<description><![CDATA[<p>I was trying to restore a database to a MySQL server on a test machine and this error occurred: #1273 - Unknown collation: 'utf8mb4_unicode_520_ci' The problem is, the server that runs the live database is MySQL 5.7 that supports utf8mb4_unicode_520_ci but the test server I run is only MySQL 5.5 which does not support this specific encoding. By the way, [&#8230;]</p>
The post <a href="https://www.kjctech.net/fixing-unknown-collation-utf8mb4_unicode_520_ci/">Fixing Unknown Collation utf8mb4_unicode_520_ci</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>I was trying to restore a database to a MySQL server on a test machine and this error occurred:</p>



<pre class="wp-block-preformatted">#1273 - Unknown collation: 'utf8mb4_unicode_520_ci'</pre>



<p>The problem is, the server that runs the live database is MySQL 5.7 that supports utf8mb4_unicode_520_ci but the test server I run is only MySQL 5.5 which does not support this specific encoding.</p>



<p>By the way, to check which version of MySQL you are running, run the following command:</p>



<pre class="wp-block-preformatted">mysql -V</pre>



<p>The easiest way to fix this collation error is to upgrade MySQL 5.5 to either 5.6 or 5.7. Since the version of my test machine is Ubuntu 14.04, I can easily upgrade it to 5.6 by following:</p>



<pre class="wp-block-code"><code class="">sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mysql-client-core-5.6
sudo apt-get install mysql-client-5.6
sudo apt-get install mysql-server-5.6</code></pre>



<p>The restore went successfully once the server is upgraded to 5.6.</p>



<p>You may want to back up all databases and restore them back, in case anything goes wrong.</p>



<p>To back up all databases at once,</p>



<pre class="wp-block-preformatted">mysqldump --lock-all-tables -u root -p --all-databases > dump.sql</pre>



<p>To restore them all once the server is upgraded,</p>



<pre class="wp-block-preformatted">mysql -u root -p &lt; dump.sql</pre>



<p>If upgrading MySQL isn&#8217;t an option for you, you will need to modify the backup file by replacing all <strong>utf8mb4_unicode_520_ci</strong> with <strong>utf8mb4_unicode_ci</strong>. Not ideal, but still works.</p>The post <a href="https://www.kjctech.net/fixing-unknown-collation-utf8mb4_unicode_520_ci/">Fixing Unknown Collation utf8mb4_unicode_520_ci</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/fixing-unknown-collation-utf8mb4_unicode_520_ci/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4213</post-id>	</item>
	</channel>
</rss>
