mysql change data dir

[ubuntu]
MySQL is a widely used and fast SQL database server. It is a client/server implementation that consists of a server daemon (mysqld) and many different client programs/libraries.

If you want to install Mysql database server in Ubuntu check this tutorial.
What is Mysql Data Directory?

Mysql data directory is important part where all the mysql databases storage location.By default MySQL data default directory located in /var/lib/mysql.If you are running out of space in /var partition you need to move this to some other location.

Note:- This is only for advanced users and before moving default directory make a backup of your mysal databases.

Procedure to follow

Open the terminal

First you need to Stop MySQL using the following command

sudo /etc/init.d/mysql stop

Now Copy the existing data directory (default located in /var/lib/mysql) using the following command

sudo cp -R -p /var/lib/mysql /path/to/new/datadir

All you need are the data files, so delete the others with the command

sudo rm /path/to/new/datadir

Note:- You will get a message about not being able to delete some directories, but that's what you want.

Now edit the MySQL configuration file with the following command

gksu gedit /etc/mysql/my.cnf

Look for the entry for "datadir", and change the path (which should be "/var/lib/mysql") to the new data directory.

Important Note:-From Ubuntu 7.10 (Gutsy Gibbon) forward, Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile for MySQL, you'll never be able to restart MySQL with the new datadir location.

In the terminal, enter the command

sudo gedit /etc/apparmor.d/usr.sbin.mysqld

Copy the lines beginning with "/var/lib/mysql", comment out the originals with hash marks ("#"), and paste the lines below the originals.

Now change "/var/lib/mysql" in the two new lines with "/path/to/new/datadir". Save and close the file.

Restart the AppArmor profiles with the command

sudo /etc/init.d/apparmor reload

( sudo vim /etc/init/mysql.conf change /var/lib/mysql to your new path)

Restart MySQL with the command

sudo /etc/init.d/mysql restart
or
sudo start mysql

(if fails, try sudo chown -R mysql:mysql /path/to/new/datadir)
Now MySQL should start with no errors, and your data will be stored in the new data directory location.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值