Bug #97524 Not able to reinstall mysql
Submitted: 6 Nov 2019 22:13 Modified: 7 Nov 2019 13:14
Reporter: Deepak Subhramanian Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.7 OS:Ubuntu (16.04)
Assigned to: MySQL Verification Team CPU Architecture:Any

[6 Nov 2019 22:13] Deepak Subhramanian
Description:
I am trying to cleanup and reinstall mysql server. But it is giving me this error. 

sudo apt-get remove --purge mysql*
sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get remove dbconfig-mysql
sudo apt-get dist-upgrade
sudo apt-get install mysql-community-server

2019-11-06T22:07:28.847599Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-06T22:07:28.851105Z 0 [ERROR] Can't change data directory owner to mysql
2019-11-06T22:07:28.851134Z 0 [ERROR] Aborting

apt-get install mysql-community-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libmecab2 libnuma1 mysql-client mysql-common mysql-community-client
The following NEW packages will be installed:
  libmecab2 libnuma1 mysql-client mysql-common mysql-community-client mysql-community-server
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/43.8 MB of archives.
After this operation, 299 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 144139 files and directories currently installed.)
Preparing to unpack .../mysql-common_5.7.28-1ubuntu16.04_amd64.deb ...
Unpacking mysql-common (5.7.28-1ubuntu16.04) ...
Selecting previously unselected package libnuma1:amd64.
Preparing to unpack .../libnuma1_2.0.11-1ubuntu1.1_amd64.deb ...
Unpacking libnuma1:amd64 (2.0.11-1ubuntu1.1) ...
Selecting previously unselected package mysql-community-client.
Preparing to unpack .../mysql-community-client_5.7.28-1ubuntu16.04_amd64.deb ...
Unpacking mysql-community-client (5.7.28-1ubuntu16.04) ...
Selecting previously unselected package mysql-client.
Preparing to unpack .../mysql-client_5.7.28-1ubuntu16.04_amd64.deb ...
Unpacking mysql-client (5.7.28-1ubuntu16.04) ...
Selecting previously unselected package libmecab2.
Preparing to unpack .../libmecab2_0.996-1.2ubuntu1_amd64.deb ...
Unpacking libmecab2 (0.996-1.2ubuntu1) ...
Selecting previously unselected package mysql-community-server.
Preparing to unpack .../mysql-community-server_5.7.28-1ubuntu16.04_amd64.deb ...
Unpacking mysql-community-server (5.7.28-1ubuntu16.04) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for ureadahead (0.100.0-19.1) ...
Processing triggers for systemd (229-4ubuntu21.22) ...
Setting up mysql-common (5.7.28-1ubuntu16.04) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Setting up libnuma1:amd64 (2.0.11-1ubuntu1.1) ...
Setting up mysql-community-client (5.7.28-1ubuntu16.04) ...
Setting up mysql-client (5.7.28-1ubuntu16.04) ...
Setting up libmecab2 (0.996-1.2ubuntu1) ...
Setting up mysql-community-server (5.7.28-1ubuntu16.04) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
2019-11-06T22:07:28.847599Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-06T22:07:28.851105Z 0 [ERROR] Can't change data directory owner to mysql
2019-11-06T22:07:28.851134Z 0 [ERROR] Aborting

dpkg: error processing package mysql-community-server (--configure):
 subprocess installed post-installation script returned error exit status 1
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for ureadahead (0.100.0-19.1) ...
Processing triggers for systemd (229-4ubuntu21.22) ...
Errors were encountered while processing:
 mysql-community-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

How to repeat:
Install mysql. 

Clean using this steps and install with steps. 

sudo apt-get remove --purge mysql*
sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get remove dbconfig-mysql
sudo apt-get dist-upgrade
sudo apt-get install mysql-community-server
[7 Nov 2019 11:24] Lars Tangvald
Hi,

Have you made any changes to the config file, e.g. changing the datadir setting in /etc/mysql/mysql.conf.d/mysqld.cnf ?
If so, apparmor may be blocking access to the new datadir, since the default profile only allows access to the default paths.
You should be able to check what is blocked by running "dmesg -T | grep mysql" and looking for any "DENIED" message.
[7 Nov 2019 13:14] MySQL Verification Team
tried on latest ubuntu and it works ok so as my colleague said, please check system security