1、安装mysql:

sudo apt-get install mysql-server-5.5

2、更改mysql的数据目录:

修改/etc/mysql/my.cnf:
将datadir=/var/lib/mysql修改为
datadir=/data/myql

3、重启mysql:

sudo /etc/init.d/mysql restart
报错:Job failed to start
sudo tail error.log
130628 13:58:47 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130628 13:58:47 InnoDB: Compressed tables use zlib 1.2.3.4
130628 13:58:47 InnoDB: Initializing buffer pool, size = 128.0M
130628 13:58:47 InnoDB: Completed initialization of buffer pool
130628 13:58:47  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.


4、修改ubuntu的selinux,即apparmor:

将与/var/lib/mysql相关的换成/data/mysql
/etc/apparmor.d/usr.sbin.mysqld
#  /var/lib/mysql/ r,
#  /var/lib/mysql/** rwk,
  /data/mysql/ r,
  /data/mysql/** rwk,
/etc/apparmor.d/abstractions/mysql
#   /var/lib/mysql/mysql.sock rw,
   /data/mysql/mysql.sock rw,


5、重启mysql,正常!!!


备注:此时如果还是不正常的话,应该是你的/data/mysql目录权限的问题!