<?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 Archives - IT Blog Site</title>
	<atom:link href="https://www.lavatelli.it/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lavatelli.it/category/mysql/</link>
	<description>Lavatelli IT Blog Site</description>
	<lastBuildDate>Mon, 24 Apr 2017 14:40:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.5</generator>

<image>
	<url>https://www.lavatelli.it/wp-content/uploads/2019/02/ice_dragon-150x145.gif</url>
	<title>Mysql Archives - IT Blog Site</title>
	<link>https://www.lavatelli.it/category/mysql/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Mysql DB size</title>
		<link>https://www.lavatelli.it/mysql-table-size-db/</link>
		
		<dc:creator><![CDATA[Franz]]></dc:creator>
		<pubDate>Mon, 24 Apr 2017 14:40:00 +0000</pubDate>
				<category><![CDATA[Mysql]]></category>
		<guid isPermaLink="false">http://www.lavatelli.it/?p=403</guid>

					<description><![CDATA[<p>With the following query you will get summary of all DB size SELECT table_schema AS "Database",ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"FROM information_schema.TABLESGROUP BY table_schema; You can also explode single DB and get size of each table with the following query (change db_name with the name of database you want to ...</p>
<p>The post <a href="https://www.lavatelli.it/mysql-table-size-db/">Mysql DB size</a> appeared first on <a href="https://www.lavatelli.it">IT Blog Site</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="entry">


<p class="wp-block-paragraph">With the following query you will get summary of all DB size</p>



<pre class="wp-block-preformatted">SELECT table_schema AS "Database",<br>ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"<br>FROM information_schema.TABLES<br>GROUP BY table_schema;</pre>



<p class="wp-block-paragraph">You can also explode single DB and get size of each table with the following query (change db_name with the name of database you want to analize)</p>



<pre class="wp-block-preformatted">SELECT table_name AS "Table",<br>ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"<br>FROM information_schema.TABLES<br>WHERE table_schema = "db_name"<br>ORDER BY (data_length + index_length) DESC;</pre>



<p class="wp-block-paragraph">Otherwise you can get size of table on all database sort by size with the following queyr</p>



<pre class="wp-block-code"><code>SELECT 
     table_schema as `Database`, 
     table_name AS `Table`, 
     round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` 
FROM information_schema.TABLES 
ORDER BY (data_length + index_length) DESC;</code></pre>


</div><p><a class="a2a_button_email" href="https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fmysql-table-size-db%2F&amp;linkname=Mysql%20DB%20size" title="Email" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fmysql-table-size-db%2F&amp;linkname=Mysql%20DB%20size" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fmysql-table-size-db%2F&amp;linkname=Mysql%20DB%20size" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fmysql-table-size-db%2F&amp;linkname=Mysql%20DB%20size" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fmysql-table-size-db%2F&amp;linkname=Mysql%20DB%20size" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.lavatelli.it%2Fmysql-table-size-db%2F&#038;title=Mysql%20DB%20size" data-a2a-url="https://www.lavatelli.it/mysql-table-size-db/" data-a2a-title="Mysql DB size"></a></p><p>The post <a href="https://www.lavatelli.it/mysql-table-size-db/">Mysql DB size</a> appeared first on <a href="https://www.lavatelli.it">IT Blog Site</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Create a MySQL Slave using Replication with No Downtime</title>
		<link>https://www.lavatelli.it/create-a-mysql-slave-using-replication-with-no-downtime/</link>
		
		<dc:creator><![CDATA[Franz]]></dc:creator>
		<pubDate>Tue, 22 Nov 2016 14:38:52 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[hcp]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[no downtime]]></category>
		<category><![CDATA[replication]]></category>
		<guid isPermaLink="false">http://www.lavatelli.it/?p=380</guid>

					<description><![CDATA[<p>I have a customer who has over 100GB of MySQL data and taking their site down for even a few minutes is not feasible. I really wanted to get a slave set up in case the main server ever dies. Even though the server is backed up, it would take 2-3 hours (or longer) to ...</p>
<p>The post <a href="https://www.lavatelli.it/create-a-mysql-slave-using-replication-with-no-downtime/">Create a MySQL Slave using Replication with No Downtime</a> appeared first on <a href="https://www.lavatelli.it">IT Blog Site</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="entry">
<div class="entry-content">
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-382" src="http://www.lavatelli.it/wp-content/uploads/2016/11/2013060316014742_1.jpg" alt="2013060316014742_1" width="475" height="323" /></p>
<p>I have a customer who has over 100GB of MySQL data and taking their site down for even a few minutes is not feasible. I really wanted to get a slave set up in case the main server ever dies. Even though the server is backed up, it would take 2-3 hours (or longer) to restore the MySQL server which is not very acceptable.</p>
<p>The solution is to use replication. The traditional problem with this approach is locking the tables for so long while the mysqldump happens… for a database this size, close to 4-5 hours.</p>
<p>Idera’s Free Tool called <a href="http://www.lavatelli.it/linux-shadow-copy/">Linux Hot Copy (hcp)</a> was the answer I was looking for. By using hcp, you can lock the tables, make a near instant “snapshot”, record the master position, and unlock the tables. At your leisure, just copy the snapshot of the mysql data to your slave device, and start up your replication! This makes setting up new slaves a snap with minimal impact on your business.</p>
<p><i>First off, I will assume you have a production MySQL server in use and running. In my scenario, I am using CentOS 5.6 64Bit and MySQL 5.5. This tutorial will probably will work for older versions as well. I also will assume you know how to edit and copy files at the linux command line. If you don’t, you probably should get help from an experienced system administrator.</i></p>
<p>If you have not done so already, set up another mysql server for your slave. It should be a decent server, equal to your current live production server so you can switch to it in the event of failure.</p>
<p>I will also assume:</p>
<p><strong>master server = 192.168.1.100</strong><br />
<strong>slave server = 192.168.2.200</strong></p>
<p><i>You’ll need to substitute your IP Addressess in place of mine.</i></p>
<p><b>On Master Server (192.168.1.100):</b></p>
<p><b>1. Install <a href="http://www.lavatelli.it/linux-shadow-copy/">Linux Hot Copy. Linux Hot Copy</a></b>. If you need help with installation, here’s some <a href="http://www.lavatelli.it/linux-shadow-copy/">documentation</a></p>
<p><b>2. Setup your Server ID and enable bin-logs.</b> Note that bin logs record every change to your database, so make sure you have ample space to continue!)</p>
<p>Edit your /etc/my.cnf file and put these lines at the top, just under the [mysqld] line.</p>
<pre><code># enable mysql bin logs and server-id for mysql replication
       log-bin=mysql-bin
       server-id=1</code></pre>
<p>Restart MySQL so bin logs are started. e.g. /etc/init.d/mysql restart you can verify it’s working by issuing the show master statusG command.</p>
<p><b>3. Create a user that has replication privs on the Master Server.</b></p>
<pre><code>mysql&gt; GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.2.200' IDENTIFIED BY 'password';</code></pre>
<p>4. The next few steps will need to be done <strong>quickly</strong> so that you minimize your mysql server’s downtime. Make sure you know up-front the device (e.g. /dev/sda2) where your MySQL installation is located (typically /var/lib/mysql on CentOS):</p>
<p><b>Lock your Master MySQL Tables and show the status location of the bin log….</b></p>
<pre><code>mysql&gt; FLUSH TABLES WITH READ LOCK; SHOW MASTER STATUS;</code></pre>
<p><b>Make sure you record and copy the information down, e.g. the filename and log position</b></p>
<p>From the command line, enter the following command, replacing /dev/sda2 with your raw device:</p>
<pre><code>hcp /mnt/snap /dev/sda2</code></pre>
<p>Back to MySQL, unlock your tables:</p>
<pre><code>mysql&gt; unlock tables;</code></pre>
<p>Now you have a perfect copy of your “frozen” data at the following location: (may vary)..</p>
<pre><code>FROZEN DATA LOCATION:
/mnt/snap</code></pre>
<p><b>On Slave Server: 192.168.2.200</b></p>
<p>On the slave server, make sure MySQL is stopped and move the old mysql folder: (<b>make sure this is the SLAVE SERVER 192.168.2.200 and NOT the live server!</b>):</p>
<pre><code>/etc/init.d/mysql stop
mv /var/lib/mysql /var/lib/mysql.old</code></pre>
<p><b>Back on the Master Server: 192.168.1.100</b></p>
<p>1. Copy the “frozen” mysql data:</p>
<pre><code>rsync -avz /mnt/snap  root@192.168.2.200:/var/lib/mysql</code></pre>
<p>2. Copy my.cnf to slave:</p>
<pre><code>scp /etc/my.cnf root@slaveip_or_host:/etc/my.cnf</code></pre>
<p>3. Once the Copy is Complete you can delete your “hot copy”</p>
<pre><code>hcp -r /dev/hcp1</code></pre>
<p><b>Now, go to your Slave Server: 192.168.2.200</b></p>
<p>1. edit /etc/my.cnf and change server-id to 2 and comment out or delete the log-bin line you added from the master..</p>
<p>2. start up mysql, and then enter commands to connect to master.. replacing the log file and position number with the ones you recorded earlier:</p>
<pre><code>mysql&gt; CHANGE MASTER TO 
      MASTER_HOST='192.168.1.100', 
      MASTER_USER='repl', 
      MASTER_PASSWORD='password', 
      MASTER_LOG_FILE='mysql-bin.000001',
      MASTER_LOG_POS=12345678;</code></pre>
<pre><code>mysql&gt; START SLAVE;

 mysql&gt; SHOW SLAVE STATUS/G;</code></pre>
<p>MySQL will show how far it’s behind, it might take a few minutes to catch up depending on the number of changes that happened to your database during the copy.</p>
<p>I hope you enjoyed this tutorial on MySQL Replication with no downtime. Now it’s easy!</p>
</div>
</div>
<p><a class="a2a_button_email" href="https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fcreate-a-mysql-slave-using-replication-with-no-downtime%2F&amp;linkname=Create%20a%20MySQL%20Slave%20using%20Replication%20with%20No%20Downtime" title="Email" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fcreate-a-mysql-slave-using-replication-with-no-downtime%2F&amp;linkname=Create%20a%20MySQL%20Slave%20using%20Replication%20with%20No%20Downtime" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fcreate-a-mysql-slave-using-replication-with-no-downtime%2F&amp;linkname=Create%20a%20MySQL%20Slave%20using%20Replication%20with%20No%20Downtime" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fcreate-a-mysql-slave-using-replication-with-no-downtime%2F&amp;linkname=Create%20a%20MySQL%20Slave%20using%20Replication%20with%20No%20Downtime" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fcreate-a-mysql-slave-using-replication-with-no-downtime%2F&amp;linkname=Create%20a%20MySQL%20Slave%20using%20Replication%20with%20No%20Downtime" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.lavatelli.it%2Fcreate-a-mysql-slave-using-replication-with-no-downtime%2F&#038;title=Create%20a%20MySQL%20Slave%20using%20Replication%20with%20No%20Downtime" data-a2a-url="https://www.lavatelli.it/create-a-mysql-slave-using-replication-with-no-downtime/" data-a2a-title="Create a MySQL Slave using Replication with No Downtime"></a></p><p>The post <a href="https://www.lavatelli.it/create-a-mysql-slave-using-replication-with-no-downtime/">Create a MySQL Slave using Replication with No Downtime</a> appeared first on <a href="https://www.lavatelli.it">IT Blog Site</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Dumping and importing from/to MySQL in an UTF-8 safe way</title>
		<link>https://www.lavatelli.it/dumping-and-importing-fromto-mysql-in-an-utf-8-safe-way/</link>
		
		<dc:creator><![CDATA[Franz]]></dc:creator>
		<pubDate>Mon, 23 Sep 2013 14:58:58 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[restore]]></category>
		<category><![CDATA[utf8]]></category>
		<guid isPermaLink="false">http://www.lavatelli.it/?p=3</guid>

					<description><![CDATA[<p>In a nutshell: to avoid your shell character set from messing with imports, use -r to export and SOURCE when importing. Dumping safely Do not do this, since it might screw up encoding: mysqldump -uroot -p database &#62; utf8.dump # this is bad Better do: mysqldump -uroot -p database -r utf8.dump Note that when your ...</p>
<p>The post <a href="https://www.lavatelli.it/dumping-and-importing-fromto-mysql-in-an-utf-8-safe-way/">Dumping and importing from/to MySQL in an UTF-8 safe way</a> appeared first on <a href="https://www.lavatelli.it">IT Blog Site</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="entry">
<p>In a nutshell: to avoid your shell character set from messing with imports, use -r to export and SOURCE when importing.<br />
Dumping safely</p>
<p>Do not do this, since it might screw up encoding:</p>
<p>mysqldump -uroot -p database &gt; utf8.dump # this is bad</p>
<p>Better do:</p>
<p>mysqldump -uroot -p database -r utf8.dump</p>
<p>Note that when your MySQL server is not set to UTF-8 you need to do mysqldump &#8211;default-character-set=latin (!) to get a correctly encoded dump.</p>
<p>If you only want to dump the structure without data, use</p>
<p>mysqldump -uroot -p &#8211;no-data database -r utf8.dump</p>
<p>Importing a dump safely</p>
<p>Do not do this, since it might screw up encoding:</p>
<p>mysql -u username -p database SOURCE utf8.dump</p>
</div>
<p><a class="a2a_button_email" href="https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fdumping-and-importing-fromto-mysql-in-an-utf-8-safe-way%2F&amp;linkname=Dumping%20and%20importing%20from%2Fto%20MySQL%20in%20an%20UTF-8%20safe%20way" title="Email" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fdumping-and-importing-fromto-mysql-in-an-utf-8-safe-way%2F&amp;linkname=Dumping%20and%20importing%20from%2Fto%20MySQL%20in%20an%20UTF-8%20safe%20way" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fdumping-and-importing-fromto-mysql-in-an-utf-8-safe-way%2F&amp;linkname=Dumping%20and%20importing%20from%2Fto%20MySQL%20in%20an%20UTF-8%20safe%20way" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fdumping-and-importing-fromto-mysql-in-an-utf-8-safe-way%2F&amp;linkname=Dumping%20and%20importing%20from%2Fto%20MySQL%20in%20an%20UTF-8%20safe%20way" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.lavatelli.it%2Fdumping-and-importing-fromto-mysql-in-an-utf-8-safe-way%2F&amp;linkname=Dumping%20and%20importing%20from%2Fto%20MySQL%20in%20an%20UTF-8%20safe%20way" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.lavatelli.it%2Fdumping-and-importing-fromto-mysql-in-an-utf-8-safe-way%2F&#038;title=Dumping%20and%20importing%20from%2Fto%20MySQL%20in%20an%20UTF-8%20safe%20way" data-a2a-url="https://www.lavatelli.it/dumping-and-importing-fromto-mysql-in-an-utf-8-safe-way/" data-a2a-title="Dumping and importing from/to MySQL in an UTF-8 safe way"></a></p><p>The post <a href="https://www.lavatelli.it/dumping-and-importing-fromto-mysql-in-an-utf-8-safe-way/">Dumping and importing from/to MySQL in an UTF-8 safe way</a> appeared first on <a href="https://www.lavatelli.it">IT Blog Site</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Object Caching 77/95 objects using Redis
Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Minified using Redis

Served from: www.lavatelli.it @ 2026-11-21 08:56:03 by W3 Total Cache
-->