环境安装参考: 306-Ubuntu16.04 安装LNAMP
1. 创建数据目录,并设置权限
> mkdir /51nst/data/mysql
> chown -R mysql:mysql /51nst/data/mysql
> chmod 700 -R mysql:mysql /51nst/data/mysql
复制mysql默认目录数据
> cp -arx /var/lib/mysql/* /51nst/data/mysql/
> rm -rf /51nst/data/mysql/ib_logfile*
2. 修改vim /etc/apparmor.d/usr.sbin.mysqld
> vim /etc/apparmor.d/usr.sbin.mysqld
# 找到对应部分,进行修改
# Allow data dir access
# /var/lib/mysql/ r,
# /var/lib/mysql/** rwk,
/51nst/data/mysql/ r,
/51nst/data/mysql/** rwk,
重启
> service apparmor reload
> service apparmor restart
3. 配置mysql
> vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 将对应部分进行修改
#datadir = /var/lib/mysql 修改为如下
datadir = /51nst/data/mysql
重启mysql
> service mysql restart
查看配置
> mysql -u root -p
mysql> show variables like '%datadir%';
+---------------+--------------------+
| Variable_name | Value |
+---------------+--------------------+
| datadir | /51nst/data/mysql/ |
+---------------+--------------------+
1 row in set (0.00 sec)
网友评论