<?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>AppArmor &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/apparmor/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Wed, 12 Jul 2017 20:50:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>MySQL: Move Data Directory to a New Location on Ubuntu 16.04</title>
		<link>https://www.dbrnd.com/2017/07/mysql-move-data-directory-to-a-new-location-on-ubuntu-16-04-datadir-apparmor-mysqld/</link>
					<comments>https://www.dbrnd.com/2017/07/mysql-move-data-directory-to-a-new-location-on-ubuntu-16-04-datadir-apparmor-mysqld/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 24 Jul 2017 16:16:27 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[AppArmor]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[datadir]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tuning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<category><![CDATA[mysqld]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5687</guid>

					<description><![CDATA[<div><img width="400" height="400" src="https://www.dbrnd.com/wp-content/uploads/2017/07/MySQLMoveDataDir.png" class="attachment-post-image size-post-image wp-post-image" alt="MySQL Move Data Dir" decoding="async" fetchpriority="high" srcset="https://www.dbrnd.com/wp-content/uploads/2017/07/MySQLMoveDataDir.png 400w, https://www.dbrnd.com/wp-content/uploads/2017/07/MySQLMoveDataDir-150x150.png 150w, https://www.dbrnd.com/wp-content/uploads/2017/07/MySQLMoveDataDir-300x300.png 300w, https://www.dbrnd.com/wp-content/uploads/2017/07/MySQLMoveDataDir-65x65.png 65w" sizes="(max-width: 400px) 100vw, 400px" /></div>In this post, I am sharing required steps to move MySQL Data Directory from old location to new location. Check the current data directory of MySQL: [crayon-6ab928e5c5262967017670/] Stop the MySQL Service: [crayon-6ab928e5c5265010804063/] Confirm the inactive status of MySQL Service: [crayon-6ab928e5c5266032399894/] Output: [crayon-6ab928e5c5267885503699/] Use rsync with -av flag to copy the existing database directory to the [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="400" height="400" src="https://www.dbrnd.com/wp-content/uploads/2017/07/MySQLMoveDataDir.png" class="attachment-post-image size-post-image wp-post-image" alt="MySQL Move Data Dir" decoding="async" srcset="https://www.dbrnd.com/wp-content/uploads/2017/07/MySQLMoveDataDir.png 400w, https://www.dbrnd.com/wp-content/uploads/2017/07/MySQLMoveDataDir-150x150.png 150w, https://www.dbrnd.com/wp-content/uploads/2017/07/MySQLMoveDataDir-300x300.png 300w, https://www.dbrnd.com/wp-content/uploads/2017/07/MySQLMoveDataDir-65x65.png 65w" sizes="(max-width: 400px) 100vw, 400px" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fmysql-move-data-directory-to-a-new-location-on-ubuntu-16-04-datadir-apparmor-mysqld%2F&amp;linkname=MySQL%3A%20Move%20Data%20Directory%20to%20a%20New%20Location%20on%20Ubuntu%2016.04" 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.dbrnd.com%2F2017%2F07%2Fmysql-move-data-directory-to-a-new-location-on-ubuntu-16-04-datadir-apparmor-mysqld%2F&amp;linkname=MySQL%3A%20Move%20Data%20Directory%20to%20a%20New%20Location%20on%20Ubuntu%2016.04" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fmysql-move-data-directory-to-a-new-location-on-ubuntu-16-04-datadir-apparmor-mysqld%2F&amp;linkname=MySQL%3A%20Move%20Data%20Directory%20to%20a%20New%20Location%20on%20Ubuntu%2016.04" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fmysql-move-data-directory-to-a-new-location-on-ubuntu-16-04-datadir-apparmor-mysqld%2F&amp;linkname=MySQL%3A%20Move%20Data%20Directory%20to%20a%20New%20Location%20on%20Ubuntu%2016.04" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fmysql-move-data-directory-to-a-new-location-on-ubuntu-16-04-datadir-apparmor-mysqld%2F&amp;linkname=MySQL%3A%20Move%20Data%20Directory%20to%20a%20New%20Location%20on%20Ubuntu%2016.04" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fmysql-move-data-directory-to-a-new-location-on-ubuntu-16-04-datadir-apparmor-mysqld%2F&amp;linkname=MySQL%3A%20Move%20Data%20Directory%20to%20a%20New%20Location%20on%20Ubuntu%2016.04" title="Pocket" 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.dbrnd.com%2F2017%2F07%2Fmysql-move-data-directory-to-a-new-location-on-ubuntu-16-04-datadir-apparmor-mysqld%2F&#038;title=MySQL%3A%20Move%20Data%20Directory%20to%20a%20New%20Location%20on%20Ubuntu%2016.04" data-a2a-url="https://www.dbrnd.com/2017/07/mysql-move-data-directory-to-a-new-location-on-ubuntu-16-04-datadir-apparmor-mysqld/" data-a2a-title="MySQL: Move Data Directory to a New Location on Ubuntu 16.04"></a></p><p>In this post, I am sharing required steps to move MySQL Data Directory from old location to new location. </p>
<p><strong>Check the current data directory of MySQL:</strong></p>
<pre class="crayon-plain-tag">mysql&gt; select @@datadir;
+-----------------+
| @@datadir       |
+-----------------+
| /var/lib/mysql/ |
+-----------------+</pre> </p>
<p><strong>Stop the MySQL Service:</strong></p>
<pre class="crayon-plain-tag">sudo systemctl stop mysql</pre> </p>
<p><strong>Confirm the inactive status of MySQL Service:</strong> </p>
<pre class="crayon-plain-tag">sudo systemctl status mysql</pre>
<strong>Output:</strong></p>
<pre class="crayon-plain-tag">● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Wed 2017-07-12 19:45:48 UTC; 11s ago
 Main PID: 8841 (code=exited, status=0/SUCCESS)

Jul 12 19:11:30 ip-172-31-27-19 systemd[1]: Starting MySQL Community Server...
Jul 12 19:11:31 ip-172-31-27-19 systemd[1]: Started MySQL Community Server.
Jul 12 19:45:46 ip-172-31-27-19 systemd[1]: Stopping MySQL Community Server...
Jul 12 19:45:48 ip-172-31-27-19 systemd[1]: Stopped MySQL Community Server.</pre> </p>
<p><strong>Use rsync with -av flag to copy the existing database directory to the new location:</strong></p>
<pre class="crayon-plain-tag">sudo rsync -av /var/lib/mysql /mnt/dbrnd_mysql</pre> </p>
<p><strong>Rename old MySQL Data Directory:</strong></p>
<pre class="crayon-plain-tag">sudo mv /var/lib/mysql /var/lib/mysql.backup</pre> </p>
<p><strong>Change (datadir=) parameter in MySQL Config file (mysqld.cnf) for pointing to the New Data Location:</strong></p>
<pre class="crayon-plain-tag">sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf</pre>
<strong>My Sample mysqld.cnf:</strong></p>
<pre class="crayon-plain-tag">[mysqld]
#
# * Basic Settings
#
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /mnt/dbrnd_mysql/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking</pre> </p>
<p><strong>Now, Check below sample error:</strong></p>
<pre class="crayon-plain-tag">Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.</pre> </p>
<p><strong>To avoid above error, configure AppArmor Access Control Rules:</strong></p>
<blockquote><p><strong>AppArmor:</strong> AppArmor (&#8220;Application&#8221;) is a Linux kernel security module that allows the system administrator to restrict programs&#8217; capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths.</p></blockquote>
<p><strong>Open AppArmor for edit:</strong></p>
<pre class="crayon-plain-tag">sudo nano /etc/apparmor.d/tunables/alias</pre> </p>
<p><strong>Add new entry of new data location path:</strong></p>
<pre class="crayon-plain-tag">alias /var/lib/mysql/ -&gt; /mnt/volume-nyc1-01/mysql/,</pre>
<strong>Please check below sample output of my AppArmor:</strong><br />
Because don&#8217;t add # in new entry and also make sure that old path is there with #.</p>
<pre class="crayon-plain-tag"># ------------------------------------------------------------------
#
#    Copyright (C) 2010 Canonical Ltd.
#
#    This program is free software; you can redistribute it and/or
#    modify it under the terms of version 2 of the GNU General Public
#    License published by the Free Software Foundation.
#
# ------------------------------------------------------------------

# Alias rules can be used to rewrite paths and are done after variable
# resolution. For example, if '/usr' is on removable media:
# alias /usr/ -&gt; /mnt/usr/,
#
# Or if mysql databases are stored in /home:
# alias /var/lib/mysql/ -&gt; /var/lib/mysql/,
alias /var/lib/mysql/ -&gt; /mnt/dbrnd_mysql/mysql/,</pre> </p>
<p><strong>After change, restart the AppArmor:</strong></p>
<pre class="crayon-plain-tag">sudo systemctl restart apparmor</pre> </p>
<p><strong>Create the minimal directory structure:</strong></p>
<pre class="crayon-plain-tag">sudo mkdir /var/lib/mysql/mysql -p</pre> </p>
<p><strong>Now, Start the MySQL Service:</strong></p>
<pre class="crayon-plain-tag">sudo systemctl start mysql</pre> </p>
<p><strong>Check the status of MySQL Service:</strong></p>
<pre class="crayon-plain-tag">sudo systemctl status mysql</pre> </p>
<p><strong>Now, connect MySQL and check the new datadir location:</strong></p>
<pre class="crayon-plain-tag">mysql&gt; select @@datadir;
+-------------------------+
| @@datadir               |
+-------------------------+
| /mnt/dbrnd_mysql/mysql/ |
+-------------------------+</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/07/mysql-move-data-directory-to-a-new-location-on-ubuntu-16-04-datadir-apparmor-mysqld/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
