ubuntu下更改mysql data目录
转载,原文出自:http://blog.sina.com.cn/s/blog_6a0b2afd0100qikw.html
cp /lib/var/mysql /home/caige
在/etc/mysql/my.cnf 添加:
[mysqld]
datadir = /home/caige/mysql
sudo service mysql start 后无法启动 查看日志 发现
/usr/sbin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
[ERROR] /usr/sbin/mysqld: Can't create/write to file '/home/caige/mysql/memcache.pid' (Errcode: 13)
[ERROR] Can't start server: can't create PID file: Permission denied
很明显权限问题 ubuntu的mysql是有chroot的
修改/etc/apparmor.d/usr.sbin.mysqld
/var/lib/mysql/ r, 替换为 /home/caige/mysql/ r,
/var/lib/mysql/** rwk, 替换为 /home/caige/mysql/** rwk,
修改/etc/apparmor.d/abstractions/mysql
/var/lib/mysql/mysql.sock rw, 替换为 /home/caige/mysql/mysql.sock rw,
sudo /etc/init.d/apparmor restart 重启apparmor
sudo service mysql start 启动mysql
成功