MySQL not starting on Ubuntu 18.04

MySQL did not start on Ubuntu 18.04 server. This is fresh server, i removed all MySQL packages, removed configuration files.

Reinstalled MySQL.

Still MySQL fail to start with some error related to

Full error here

Initially i was thinking the problem is with Ubuntu 18.04 mysql package. So i set up another fresh Ubuntu 18.04 server, installed MySQL 5.7 and it worked prefectly fine.

Now i checked the permission for the folders. For this i enabled shell access for MySQL user.

Now i change to this user with command

I chaged to /var/log/mysql folder, it worked fine, i can write to the file /var/log/mysql/error.log. Tested with

It is not a permission problem. I checked the /var/log foler, found this is not an actual folder, a symlink to another folder.

This is caused by AppArmor. I disabled AppArmour with

Start MySQL with

I get some error related to data directory, i checked folder /var/lib/mysql and found it was empty. I created MySQL data folder with command

On restarting MySQL again, MySQL worked fine. But i can’t login as user root. When you initialize MySQL data folder, MYSQL generate and store temporary password in /var/log/mysql/error.log, to find the password, i run

You need to change this temporary password as it is set as expired by default. This can be done with command

Set a new secure password when it ask.

Fixing AppArmor

We need to tell AppArmour to allow MySQL to use /mnt/log/mysql folder for logging. To do this, edit file.

Added following to it.

Now restart AppArmor.

Now MySQL will work properly.