<?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> &#187; mysql 更改数据库文件位置</title>
	<atom:link href="http://www.liguosong.com/tag/mysql-%e6%9b%b4%e6%94%b9%e6%95%b0%e6%8d%ae%e5%ba%93%e6%96%87%e4%bb%b6%e4%bd%8d%e7%bd%ae/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.liguosong.com</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2018 01:02:19 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.2</generator>
		<item>
		<title>Change the MySql data default directory</title>
		<link>http://www.liguosong.com/2014/05/04/change-mysql-data-default-directory/</link>
		<comments>http://www.liguosong.com/2014/05/04/change-mysql-data-default-directory/#comments</comments>
		<pubDate>Sun, 04 May 2014 08:59:26 +0000</pubDate>
		<dc:creator>lgs</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql 更改数据库文件位置]]></category>

		<guid isPermaLink="false">http://www.liguosong.com/?p=266</guid>
		<description><![CDATA[注意：在操作之前，要先备份好数据库。 默认情况下，MySql的数据库文件位于/var/lib/mysql下。于 [...]]]></description>
				<content:encoded><![CDATA[<p><span style="color: #ff0000;">注意：在操作之前，要先备份好数据库。</span><br />
默认情况下，MySql的数据库文件位于/var/lib/mysql下。于是想着把现在的数据库文件移动到挂载的硬盘上。找了一些办法，例如一起移动socket，datadir等等。但是移动完成后不能启动。最终找到了一个很完美的方案。<span id="more-266"></span></p>
<ul>
<li><span style="line-height: 1.714285714; font-size: 1rem;"><span style="line-height: 1.714285714; font-size: 1rem;">停止Mysql服务<br />
</span></span></p>
<pre class="brush:ps">sudo /etc/init.d/mysql stop</pre>
</li>
<li><span style="line-height: 1.714285714; font-size: 1rem;"><span style="line-height: 1.714285714; font-size: 1rem;">复制现在的数据库文件到新的路径下<br />
</span></span></p>
<pre class="brush:ps">sudo cp -R -p /var/lib/mysql /path/to/new/datadir</pre>
</li>
<li><span style="line-height: 1.714285714; font-size: 1rem;">更改MySql的配置文件.在my.cnf中查找datadir，将其值更改为新的路径。</span></li>
<li><span style="line-height: 1.714285714; font-size: 1rem;"><span style="line-height: 1.714285714; font-size: 1rem;">修改usr.sbin.mysqld。如不明白为什么修改这个文件，查看一下AppArmor</span></span>
<pre class="brush:ps">sudo vi /etc/apparmor.d/usr.sbin.mysqld</pre>
<p>从/var/lib/mysql到最后，先复制一下。然后将原来的值全部用#注释掉。如果有注释的，最好也加一个注释，这样就会知道哪些注释是默认的，哪些注释是你新添加的。注释完后，在最后一行粘贴刚才复制的内容。并将/var/lib/mysql的值换成新的路径</li>
<li><span style="line-height: 1.714285714; font-size: 1rem;"><span style="line-height: 1.714285714; font-size: 1rem;">启动MySql</span></span>
<pre class="brush:ps">sudo service mysql start</pre>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.liguosong.com/2014/05/04/change-mysql-data-default-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
