Bug #94880 Incorrect and dangerous error message from MY-013236
Submitted: 3 Apr 2019 3:52 Modified: 21 May 2019 17:40
Reporter: Martin Amps Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Logging Severity:S3 (Non-critical)
Version:8.0.13, 8.0.15 OS:Any
Assigned to: CPU Architecture:Any

[3 Apr 2019 3:52] Martin Amps
Description:
When starting MySQL as an unprivileged user it can emit a dangerous and misleading error message instructing you to erroneously delete your data directory.

[mamps@ec2-54-221-22-160.compute-1.amazonaws.com dev-us1]$ /usr/sbin/mysqld --initialize --datadir=/mnt/mysql --user=mysql
mysqld: Can't create directory '/mnt/mysql/' (OS errno 17 - File exists)
2019-04-03T03:50:10.250702Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.13-3) initializing of server in progress as process 28772
2019-04-03T03:50:10.252028Z 0 [ERROR] [MY-010187] [Server] Could not open file '/var/log/mysql/error.log' for error logging: Permission denied
2019-04-03T03:50:10.252051Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /mnt/mysql/ is unusable. You can safely remove it.
2019-04-03T03:50:10.252057Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-04-03T03:50:10.252233Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.13-3)  Percona Server (GPL), Release 3, Revision a920dd6.

This is categorically _not_ safe, as evidenced by all of my binlogs:

[mamps@ec2-54-221-22-160.compute-1.amazonaws.com dev-us1]$ sudo sh -c 'ls /mnt/mysql/mysql-bin*'
/mnt/mysql/mysql-bin.000152  /mnt/mysql/mysql-bin.000155  /mnt/mysql/mysql-bin.000158  /mnt/mysql/mysql-bin.000161  /mnt/mysql/mysql-bin.000164  /mnt/mysql/mysql-bin.000167
/mnt/mysql/mysql-bin.000153  /mnt/mysql/mysql-bin.000156  /mnt/mysql/mysql-bin.000159  /mnt/mysql/mysql-bin.000162  /mnt/mysql/mysql-bin.000165  /mnt/mysql/mysql-bin.index
/mnt/mysql/mysql-bin.000154  /mnt/mysql/mysql-bin.000157  /mnt/mysql/mysql-bin.000160  /mnt/mysql/mysql-bin.000163  /mnt/mysql/mysql-bin.000166

Service starts fine when privileged:

[mamps@ec2-54-221-22-160.compute-1.amazonaws.com dev-us1]$ sudo /usr/sbin/mysqld --initialize --datadir=/mnt/mysql --user=mysql
[mamps@ec2-54-221-22-160.compute-1.amazonaws.com dev-us1]$ echo $?
1

How to repeat:
Try to start mysql via an unprivileged user akin to:

/usr/sbin/mysqld --initialize --datadir=/mnt/mysql --user=mysql

Suggested fix:
- Probably never recommend removing the datadir
- Detect privilege issues and report accordingly
[3 Apr 2019 4:32] Martin Amps
Upon a closer look this is clearly related to `--initialize` being passed, however this is called via the centos init scripts upon startup so I'd argue the messaging could still be improved from the MySQL side to mitigate anyone erroneously wiping out their datadir 

(example: https://fossies.org/linux/mysql/packaging/rpm-sles/mysql.init )
[3 Apr 2019 6:20] MySQL Verification Team
Hello Martin,

Thank you for the report and feedback.

regards,
Umesh
[21 May 2019 17:40] Paul DuBois
Posted by developer:
 
Fixed in 8.0.17.

For failed data directory initialization, the server could produce a
message indicating that the directory could be removed, even if the
server itself did not create it. The message now indicates that only
files in the directory created by the server can be removed.