OS: Ubuntu 16.04
I am trying to move the MySQL data directory to another location. Here's what I did:
mysql -u root -p
select @@datadir;
Output
+-----------------+
| @@datadir |
+-----------------+
| /var/lib/mysql/ |
+-----------------+
sudo systemctl stop mysql
mkdir /data
sudo rsync -av /var/lib/mysql /data
I then verified that a /data/mysql/mysql directory was created and all the data was moved there.
Then I modified the /etc/mysql/mysql.conf.d/mysqld.cnf file:
datadir=/data/mysql
I then modified /etc/apparmor.d/tunables/alias. At the bottom of the file, added the following alias rule: alias /var/lib/mysql/ -> /data/mysql/,
then:
sudo systemctl restart apparmor
No errors so far.
I then did:
sudo mkdir /var/lib/mysql/mysql -p
followed by:
sudo systemctl start mysql
This gave me the following error message:
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
systemctl status mysql.service
gives me:
mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: activating (start-post) (Result: exit-code) since Thu 2016-09-01 08:09:04 UTC; 10s ago
Process: 20380 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Process: 20377 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 20380 (code=exited, status=1/FAILURE); : 20381 (mysql-systemd-s)
Tasks: 2
Memory: 336.0K
CPU: 221ms
CGroup: /system.slice/mysql.service
└─control
├─20381 /bin/bash /usr/share/mysql/mysql-systemd-start post
└─20430 sleep 1
Sep 01 08:09:04 db.msrv.com systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 01 08:09:04 db.msrv.com systemd[1]: Stopped MySQL Community Server.
Sep 01 08:09:04 db.msrv.com systemd[1]: Starting MySQL Community Server...
Sep 01 08:09:06 db.msrv.com systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Any ideas?