Mysql – Can’t install thesql-server on fresh Ubuntu 16.04

installationMySQLubuntu-16.04

TLDR

Installing mysql-server-5.7 fails at

Renaming removed key_buffer and myisam-recover options (if present)

Question 1: How do I fix the issue described below?

Question 2: Why does it occur?

Background

I'm at my wits' end trying to solve this.
Earlier today I was booting a fresh DB instance on an Ubuntu VM with the intention to run keep the MYSQL db files on a separate drive and log files on a 3rd drive. I booted a fresh Ubuntu 16.04 LTM virtual machine on Microsoft Azure. Then I attached 2 disks to it, initialized thier file systems, and mounted them to /mysql and /log respectively. Next I moved /var/log to /log and replaced /var/log with a symlink pointing to /log.

Then, when I tried to install mysql server (using defaults):

sudo apt-get mysql-server
sudo apt-get mysql-server-5.7

The installation always fails at Renaming removed key_buffer and myisam-recover options (if present).

I've tried:

  1. sudo dpkg-reconfigure mysql-server-5.1,
  2. sudo apt-get purge mysql-common mysql-server-5.1,
  3. sudo rm /etc/mysql/my.cnf /etc/mysql/my.cnf.fallback /etc/mysql/my.cnf.migrated my.cnf.wba.bak /etc/alternatives/my.cnf,
  4. sudo systemctl enable mysql.service
  5. sudo apt-get remove --purge mysql*
  6. sudo update-alternatives --remove my.cnf /etc/mysql/my.cnf.migrated
  7. All 3 workarounds here
    Note: workaround 3 fails halfway through because sudo service mysql start fails.

    Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

Furthermore, I read and tried several of Canonical's threads to no avail, particularly, this, and this. Whatever workaround or fix I try, I always get the same error at the same place.

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-cloud-tools-4.4.0-81 linux-cloud-tools-4.4.0-81-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
Suggested packages:
  mailx tinyca
The following NEW packages will be installed:
  mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7 mysql-server-core-5.7
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/18.2 MB of archives.
After this operation, 160 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 ... 94155 files and directories currently installed.)
Preparing to unpack .../mysql-common_5.7.18-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-common (5.7.18-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-client-core-5.7.
Preparing to unpack .../mysql-client-core-5.7_5.7.18-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-client-core-5.7 (5.7.18-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-client-5.7.
Preparing to unpack .../mysql-client-5.7_5.7.18-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-client-5.7 (5.7.18-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-server-core-5.7.
Preparing to unpack .../mysql-server-core-5.7_5.7.18-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-server-core-5.7 (5.7.18-0ubuntu0.16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up mysql-common (5.7.18-0ubuntu0.16.04.1) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Selecting previously unselected package mysql-server-5.7.
(Reading database ... 94311 files and directories currently installed.)
Preparing to unpack .../mysql-server-5.7_5.7.18-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mysql-server-5.7 (5.7.18-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.7.18-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-server (5.7.18-0ubuntu0.16.04.1) ...
Processing triggers for systemd (229-4ubuntu17) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up mysql-client-core-5.7 (5.7.18-0ubuntu0.16.04.1) ...
Setting up mysql-client-5.7 (5.7.18-0ubuntu0.16.04.1) ...
Setting up mysql-server-core-5.7 (5.7.18-0ubuntu0.16.04.1) ...
Setting up mysql-server-5.7 (5.7.18-0ubuntu0.16.04.1) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Fri 2017-06-30 22:14:16 UTC; 30ms ago
  Process: 8314 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
  Process: 8312 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 8304 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 8312 (code=exited, status=1/FAILURE)

Jun 30 22:14:16 PMCTMYSQLWEBDEV systemd[1]: Failed to start MySQL Community Server.
Jun 30 22:14:16 PMCTMYSQLWEBDEV systemd[1]: mysql.service: Unit entered failed state.
Jun 30 22:14:16 PMCTMYSQLWEBDEV systemd[1]: mysql.service: Failed with result 'exit-code'.
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
Processing triggers for systemd (229-4ubuntu17) ...
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Processing triggers for ureadahead (0.100.0-19) ...
Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

From reading an extensive thread on launchpad.net, I know that this was a relatively common occurrence last year, particularly due to a changed configuration directive; however, I'm installing this on a fresh VM, therefore no configurations were changed. Either way, every solution proposed there, the installation still fails. I understand that it's failing when attempting to configure mysql-server after the installation, but I don't understand why it keeps failing at this point.

Shell Outputs

Running systemctl status mysql.service outputs:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Fri 2017-06-30 23:02:31 UTC; 28s ago
  Process: 18500 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 18491 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 18500 (code=exited, status=1/FAILURE);         : 18501 (mysql-systemd-s)
    Tasks: 2
   Memory: 312.0K
      CPU: 563ms
   CGroup: /system.slice/mysql.service
           └─control
             ├─18501 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─18571 sleep 1

Running journalctl -xe outputs a wall-o-text:

Jun 30 23:03:33 MYVMSERVERNAME kernel: audit: type=1400 audit(1498863813.150:4573): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/log
Jun 30 23:03:33 MYVMSERVERNAME kernel: audit: type=1400 audit(1498863813.150:4574): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/log
Jun 30 23:03:33 MYVMSERVERNAME systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Jun 30 23:03:36 MYVMSERVERNAME systemd[1]: Time has been changed
-- Subject: Time change
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The system clock has been changed to REALTIME microseconds after January 1st, 1970.
Jun 30 23:03:36 MYVMSERVERNAME systemd[1]: snapd.refresh.timer: Adding 51min 45.765270s random time.
Jun 30 23:03:36 MYVMSERVERNAME systemd[1]: apt-daily.timer: Adding 9h 36min 3.316616s random time.
Jun 30 23:03:36 MYVMSERVERNAME systemd[4309]: Time has been changed
-- Subject: Time change
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The system clock has been changed to REALTIME microseconds after January 1st, 1970.
Jun 30 23:03:41 MYVMSERVERNAME systemd[4309]: Time has been changed
-- Subject: Time change
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The system clock has been changed to REALTIME microseconds after January 1st, 1970.
Jun 30 23:03:41 MYVMSERVERNAME systemd[1]: Time has been changed
-- Subject: Time change
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The system clock has been changed to REALTIME microseconds after January 1st, 1970.
Jun 30 23:03:41 MYVMSERVERNAME systemd[1]: snapd.refresh.timer: Adding 28min 53.776594s random time.
Jun 30 23:03:41 MYVMSERVERNAME systemd[1]: apt-daily.timer: Adding 2h 8min 50.808503s random time.
Jun 30 23:03:46 MYVMSERVERNAME systemd[1]: Time has been changed
-- Subject: Time change
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The system clock has been changed to REALTIME microseconds after January 1st, 1970.
Jun 30 23:03:46 MYVMSERVERNAME systemd[1]: snapd.refresh.timer: Adding 5h 21min 26.938184s random time.
Jun 30 23:03:46 MYVMSERVERNAME systemd[1]: apt-daily.timer: Adding 10h 8min 22.523179s random time.
Jun 30 23:03:46 MYVMSERVERNAME systemd[4309]: Time has been changed
-- Subject: Time change
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The system clock has been changed to REALTIME microseconds after January 1st, 1970.
Jun 30 23:03:51 MYVMSERVERNAME systemd[4309]: Time has been changed
-- Subject: Time change
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The system clock has been changed to REALTIME microseconds after January 1st, 1970.
Jun 30 23:03:51 MYVMSERVERNAME systemd[1]: Time has been changed
-- Subject: Time change
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The system clock has been changed to REALTIME microseconds after January 1st, 1970.
Jun 30 23:03:51 MYVMSERVERNAME systemd[1]: snapd.refresh.timer: Adding 1h 36min 20.966420s random time.
Jun 30 23:03:51 MYVMSERVERNAME systemd[1]: apt-daily.timer: Adding 2h 46min 45.417443s random time.

Running sudo grep -Er 'key.buffer|myisam.recover' /etc/mysql outputs:

/etc/mysql/mysql.conf.d/mysqld.cnf:key_buffer_size              = 16M
/etc/mysql/mysql.conf.d/mysqld.cnf:myisam-recover-options  = BACKUP

/etc/mysql/my.cnf

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

/etc/mysql/mysql.conf.d/mysqld.cnf

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
#
# * Basic Settings
#
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1
#
# * Fine Tuning
#
key_buffer_size         = 16M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries       = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
#log_bin                        = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size   = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

Best Answer

What to do when you get whacked by the mysql installation bug in Ubuntu 16.04LTS:

In my case the problem was triggered by a missing /etc/mysql/my.cnf.fallback configuration file.

Possible workaround:

In /var/log/apt/history.log

Start-Date: 2017-01-20 10:42:27
Commandline: aptdaemon role='role-commit-packages' sender=':1.126'
Upgrade: mysql-server-5.7:amd64 (5.7.16-0ubuntu0.16.04.1, 5.7.17-0ubuntu0.16.04.1), mysql-server:amd64 (5.7.16-0ubuntu0.16.04.1, 5.7.17-0ubuntu0.16.04.1), mysql-client:amd64 (5.7.16-0ubuntu0.16.04.1, 5.7.17-0ubuntu0.16.04.1), libmysqlclient20:amd64 (5.7.16-0ubuntu0.16.04.1, 5.7.17-0ubuntu0.16.04.1), libmysqlclient20:i386 (5.7.16-0ubuntu0.16.04.1, 5.7.17-0ubuntu0.16.04.1), mysql-server-core-5.7:amd64 (5.7.16-0ubuntu0.16.04.1, 5.7.17-0ubuntu0.16.04.1)
Error: Sub-process /usr/bin/dpkg returned an error code (1)
End-Date: 2017-01-20 10:42:27

In /var/log/apt/term.log

Log started: 2017-01-20 10:42:27
Setting up mysql-common (5.7.17-0ubuntu0.16.04.1) ...
update-alternatives: error: alternative path /etc/mysql/my.cnf.fallback doesn't exist
dpkg: error processing package mysql-common (--configure):
 subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
 mysql-common
Log ended: 2017-01-20 10:42:27

So the problem for me seems to be the missing the /etc/mysql/my.cnf.fallback file.

ll /etc/myql
drwxr-xr-x 4 root root 4096 gen 20 10:59 ./
drwxr-xr-x 189 root root 12288 gen 19 12:44 ../
drwxr-xr-x 2 root root 4096 gen 20 09:43 conf.d/
-rw------- 1 root root 317 nov 19 10:57 debian.cnf
-rwxr-xr-x 1 root root 120 ott 24 17:13 debian-start*
lrwxrwxrwx 1 root root 24 nov 18 21:12 my.cnf -> /etc/alternatives/my.cnf
-rw-r--r-- 1 root root 3028 nov 18 21:27 my.cnf.migrated
-rw-r--r-- 1 root root 682 lug 11 2016 mysql.cnf
drwxr-xr-x 2 root root 4096 nov 18 22:24 mysql.conf.d/

So, because the symlink:

my.cnf -> /etc/alternatives/my.cnf

points back to:

/etc/alternatives/my.cnf -> /etc/mysql/mysql.cnf

i assumed (crossing my fingers) that /etc/mysql/mysql.cnf should be eligible as alternative fallback:

sudo cp /etc/mysql/mysql.cnf /etc/mysql/my.cnf.fallback

Run the apt tool to complete the upgrade.

This worked for me.

Initial bug report: https://bugs.launchpad.net/bugs/1579708

Title: mysql maintainer scripts fail if files in /etc/mysql have been deleted locally

Status in mysql-5.5 package in Ubuntu:
  Invalid
Status in mysql-5.6 package in Ubuntu:
  Invalid
Status in mysql-5.7 package in Ubuntu:
  Invalid

Bug description:

A common report is that MySQL-related maintainer scripts have failed after files in /etc/mysql/ have been deleted. This is expected behaviour since policy is that users' modifications of conf files (for example, files in /etc/mysql/) should be preserved.

The logic is that if you have modified /etc/mysql/, it is presumed that those modifications are what you want. Packaging cannot fix up any broken customizations for you, so for example if you have deleted those files, then packaging will be broken.

Before attempting to fix this up, make sure to take a full backup of your system and in particular any databases (by default in /var/lib/mysql) in case your attempt results in destruction of your data.

To fix this situation up, you could try purging all mysql-related packages (particularly mysql-common, mariadb-server-* and/or mysql-server-*) and reinstalling them. Note that just removing the packages will not work since dpkg will preserve your local modifications to /etc/mysql/ as designed.

Since this behaviour is by design, this is not a bug in Ubuntu that will be fixed and so this bug's status is set to Invalid to reflect this.

Related Topic