Description:
When MySQL Community 5.7 is installed on a fresh server but using an existing my.cnf where datadir is not specified, initialize fails and mysqld is not able to start. If there is an empty (or default my.cnf from mariadb-libs or no my.cnf) it works.
How to repeat:
1. Have a fresh installed CentOS 7
2. install mysql-community:
- yum install http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
- yum install mysql-community-server.x86_64
3. be sure mysqld is stopped and /var/lib/mysql empry
- systemctl stop mysqld.service
- rm -rf /var/lib/mysql/*
4. edit my.cnf to have something like:
[mysqld]
log-error=/var/log/mysqld3_error.log
pid-file=/var/run/mysqld/mysqld.pid
gtid-mode=on
enforce-gtid-consistency
log-slave-updates
server_id=3
master_info_repository=TABLE
relay_log_info_repository=TABLE
log-bin=mysql3-bin
5. start mysqld
- systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
in error log:
2016-06-29T11:52:30.772063Z 0 [Note] InnoDB: Waiting for purge to start
2016-06-29T11:52:30.822333Z 0 [Note] InnoDB: 5.7.13 started; log sequence number 0
2016-06-29T11:52:30.825145Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Table 'mysql.plugin' doesn't exist
2016-06-29T11:52:30.827624Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2016-06-29T11:52:30.838882Z 0 [Note] Salting uuid generator variables, current_pid: 19578, server_start_time: 1467201150, bytes_sent: 0,
2016-06-29T11:52:30.840017Z 0 [Note] Generated uuid: 'f59a8016-3def-11e6-a3ce-08002774c31b', server_start_time: 5510717095508443896, bytes_sent: 44976960
2016-06-29T11:52:30.840036Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f59a8016-3def-11e6-a3ce-08002774c31b.
2016-06-29T11:52:30.842006Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-06-29T11:52:30.845183Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2016-06-29T11:52:30.873415Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2016-06-29T11:52:30.875919Z 0 [Note] IPv6 is available.
2016-06-29T11:52:30.875938Z 0 [Note] - '::' resolves to '::';
2016-06-29T11:52:30.875966Z 0 [Note] Server socket created on IP: '::'.
2016-06-29T11:52:30.878554Z 0 [Warning] Failed to open optimizer cost constant tables
2016-06-29T11:52:30.880482Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2016-06-29T11:52:30.880529Z 0 [ERROR] Aborting
------
Initialize created a directory: /var/lib/mysql:-
# ls /var/lib/mysql\:-/
auto.cnf client-key.pem ib_logfile1 performance_schema server-key.pem
ca-key.pem ib_buffer_pool mysql private_key.pem sys
ca.pem ibdata1 mysql3-bin.000001 public_key.pem
client-cert.pem ib_logfile0 mysql3-bin.index server-cert.pem
Why there ?
To fix, just add the datadir in my.cnf, even if it's the default:
datadir=/var/lib/mysql
When using mysqld --initialize-insecure --user=mysql --datadir=/var/lib/mysql it works.
Suggested fix:
Don't create those table in /var/lib/mysql:- and create them in the right folder.
The problem is related to /usr/bin/mysqld_pre_systemd
datadir=$(get_option mysqld datadir "/var/lib/mysql${instance+:-$instance}" $instance)
$instance is empty and datadir is then /var/lib/mysql:-