Errors starting mysql after moving to a new directory Ubuntu 18.04
mysql  Ver 14.14 Distrib 5.7.29, for Linux (x86_64)


I moved my mysql installation from the default /var/lib/mysql location to an external drive, using the following:

sudo /etc/init.d/mysql stop
sudo rsync -av /var/lib/mysql /media/E
sudo mv /var/lib/mysql /var/lib/mysql.bak


and then edited the /etc/mysql/mysql.conf.d/mysqld.cnf file to point the datadir param to its new location media/E/mysql.

Attempting to restart mysql, I got:

[....] Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.


On the off chance, I went back and edited the log_error param within the mysql.conf.d file to point to its new location as well (as it previously pointed to the original /var/lib/mysql location).  Still wouldn't start, and left with the following output from journalctl -xe:

chris@chris-x1c6:/usr/share/mysql$ journalctl -xe
Feb 29 12:36:46 chris-x1c6 audit[26261]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/media/E/mysql/error.log" pid=26261 comm="mysqld" reque
Feb 29 12:36:46 chris-x1c6 audit[26261]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/media/E/mysql/error.log" pid=26261 comm="mysqld" reque
Feb 29 12:36:46 chris-x1c6 audit[26261]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/media/E/mysql/error.log" pid=26261 comm="mysqld" reque
Feb 29 12:36:46 chris-x1c6 audit[26261]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/media/E/mysql/error.log" pid=26261 comm="mysqld" reque
Feb 29 12:36:46 chris-x1c6 audit[26261]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/media/E/mysql/error.log" pid=26261 comm="mysqld" reque
Feb 29 12:36:46 chris-x1c6 audit[26261]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/media/E/mysql/error.log" pid=26261 comm="mysqld" reque
Feb 29 12:36:46 chris-x1c6 mysqld[26259]: 2020-02-29T20:36:46.356540Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for
Feb 29 12:36:46 chris-x1c6 mysqld[26259]: 2020-02-29T20:36:46.357247Z 0 [Warning] Can't create test file /media/E/mysql/chris-x1c6.lower-test
Feb 29 12:36:46 chris-x1c6 mysqld[26259]: 2020-02-29T20:36:46.357287Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.29-0ubuntu0.18.04.1) starting as process 26261 ...
Feb 29 12:36:46 chris-x1c6 mysqld[26259]: 2020-02-29T20:36:46.359205Z 0 [Warning] Can't create test file /media/E/mysql/chris-x1c6.lower-test
Feb 29 12:36:46 chris-x1c6 mysqld[26259]: 2020-02-29T20:36:46.359247Z 0 [Warning] Can't create test file /media/E/mysql/chris-x1c6.lower-test
Feb 29 12:36:46 chris-x1c6 mysqld[26259]: 2020-02-29T20:36:46.359818Z 0 [ERROR] Could not open file '/media/E/mysql/error.log' for error logging: Permission denied
Feb 29 12:36:46 chris-x1c6 mysqld[26259]: 2020-02-29T20:36:46.359828Z 0 [ERROR] Aborting
Feb 29 12:36:46 chris-x1c6 mysqld[26259]: 2020-02-29T20:36:46.359846Z 0 [Note] Binlog end
Feb 29 12:36:46 chris-x1c6 mysqld[26259]: Initialization of mysqld failed: 0
Feb 29 12:36:46 chris-x1c6 mysqld[26259]: 2020-02-29T20:36:46.359874Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
Feb 29 12:36:46 chris-x1c6 systemd[1]: mysql.service: Control process exited, code=exited status=1
Feb 29 12:36:46 chris-x1c6 systemd[1]: mysql.service: Failed with result 'exit-code'.
Feb 29 12:36:46 chris-x1c6 systemd[1]: Failed to start MySQL Community Server.


I've found other answers (here, here) that suggest tweaking AppArmor policy settings, but seems a little janky and wonder:

(1) if I did something wrong in moving the existing mysql installation;

(2) whether there's a solution preferable to editing the AppArmor policy file.
After a bit of trial and error, was able to get it to work using this approach plus modifying the log_error variable within the mysqld.cnf file to point to the new location as well.  

Adding a line to deal with AppArmor was required (it's included in the linked tutorial), but otherwise works without issue.