简洁的想法

仁爱、喜乐、和平、忍耐、恩慈、良善、信实、温柔、节制

Mysql 改变数据库目录不能启动

| Comments

mysql默认的目录是/var/lib/mysql, 修改该目录看起来很简单:

1
2
3
$ sudo vi /etc/mysql/my.cnf
#datadir = /var/lib/mysql
datadir = /home/neten/mysql

没想到 /etc/init.d/mysql restart 的时候启动不了了。

查看 log 是个习惯:

1
$ tail -f /var/log/syslog

发现一堆这种信息:

1
2
3
4
5
Mar 23 16:00:40 HP kernel: [ 3898.064351] type=1400 audit(1332514840.079:153): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=10919 comm="apparmor_parser"
Mar 23 16:00:40 HP kernel: [ 3898.087415] type=1400 audit(1332514840.103:154): apparmor="DENIED" operation="mknod" parent=1 profile="/usr/sbin/mysqld" name="/home/neten/mysql/HP.lower-test" pid=10923 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
Mar 23 16:00:40 HP kernel: [ 3898.087528] type=1400 audit(1332514840.103:155): apparmor="DENIED" operation="mknod" parent=1 profile="/usr/sbin/mysqld" name="/home/neten/mysql/HP.lower-test" pid=10923 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
Mar 23 16:00:40 HP kernel: [ 3898.090694] type=1400 audit(1332514840.107:156): apparmor="DENIED" operation="open" parent=1 profile="/usr/sbin/mysqld" name="/home/neten/mysql/mysql/plugin.frm" pid=10923 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=115 ouid=115
Mar 23 16:00:40 HP kernel: [ 3898.112522] type=1400 audit(1332514840.127:157): apparmor="DENIED" operation="open" parent=1 profile="/usr/sbin/mysqld" name="/home/neten/mysql/ibdata1" pid=10923 comm="mysqld" requested_mask="rw" denied_mask="rw" fsuid=115 ouid=115

看来是apparmor不认识新朋友, 那就给介绍一下吧:

1
2
3
4
$ sudo vi /etc/apparmor.d/usr.sbin.mysqld

/home/neten/mysql/ r,
/home/neten/mysql/** rwk,

重启一下, 一切OK了吧:

1
2
$ sudo /etc/init.d/apparmor restart
$ sudo /etc/init.d/mysql restart

Comments