When I run command
mysql -u root -p
I got an error
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
When I try to run mysql service
service mysql start
it gets timed out with message
Job for mysql.service failed because a timeout was exceeded. See "systemctl status mysql.service" and "journalctl -xe" for details.
Logs
Jan 08 23:44:48 monal-Lenovo-IdeaPad-Z510 audit[30814]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=30814 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=123 ouid=0 Jan 08 23:44:48 monal-Lenovo-IdeaPad-Z510 audit[30814]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/30814/status" pid=30814 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=123 ouid=123 Jan 08 23:44:48 monal-Lenovo-IdeaPad-Z510 audit[30814]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/usr/my.cnf" pid=30814 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=123 ouid=0 Jan 08 23:44:48 monal-Lenovo-IdeaPad-Z510 kernel: audit: type=1400 audit(1483899288.523:210): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/30814/status" pid=30814 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=123 ouid=123 Jan 08 23:44:48 monal-Lenovo-IdeaPad-Z510 kernel: audit: type=1400 audit(1483899288.523:211): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=30814 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=123 ouid=0 Jan 08 23:44:48 monal-Lenovo-IdeaPad-Z510 kernel: audit: type=1400 audit(1483899288.523:212): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/30814/status" pid=30814 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=123 ouid=123 Jan 08 23:44:48 monal-Lenovo-IdeaPad-Z510 kernel: audit: type=1400 audit(1483899288.523:213): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/usr/my.cnf" pid=30814 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=123 ouid=0 Jan 08 23:44:48 monal-Lenovo-IdeaPad-Z510 mysqld_safe[30539]: 170108 23:44:48 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended Jan 08 23:45:01 monal-Lenovo-IdeaPad-Z510 CRON[30867]: pam_unix(cron:session): session opened for user root by (uid=0) Jan 08 23:45:01 monal-Lenovo-IdeaPad-Z510 CRON[30868]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1) Jan 08 23:45:01 monal-Lenovo-IdeaPad-Z510 CRON[30867]: pam_unix(cron:session): session closed for user root
Best Answer
First stop the mysql instance. You will need to copy the exact /var/lib/mysql directory to your new data directory, preserving its permission. So use rsync with -a option
Also change the data dir path in mysql.cnf file
You will need to add alias to apparmor so that it allows mysql to write to the new directory
To add alias:
and then add this line to bottom
Restart the apparmor
and now start mysql. It should work