Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Brainiarc7/eb140201c25819ab8a5763dc5bee436d to your computer and use it in GitHub Desktop.
Save Brainiarc7/eb140201c25819ab8a5763dc5bee436d to your computer and use it in GitHub Desktop.
This is a workaround for MySQL installation bug in Ubuntu 16.04LTS. This, again, is a workaround.

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

In my case the problem is 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

enter code here

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 conffiles (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.

@sitedyno
Copy link

sitedyno commented Apr 9, 2017

This helped me out. Thanks!

@Erbros
Copy link

Erbros commented Apr 9, 2017

Thanks, this was the easiest solution I found online to this problem. =)

@mombrea
Copy link

mombrea commented Apr 10, 2017

Thank you, this fixed my issue too

@Brainiarc7
Copy link
Author

You're welcome.

@BAProductions
Copy link

Did not solve my problem

@salvatius
Copy link

thnx for pointing me in the right direction.
Altough my 5.7.20-1ubuntu14.04 was looing for my.cnf.fallback and the actual filename was my.cnf_fallback (so an underscore instead of a dot)
After rename the upgrade went smoothly

@ZCLMK
Copy link

ZCLMK commented Apr 28, 2018

yes thanks alot man this is. Understanding your logic taught me something and it worked)

@Brainiarc7
Copy link
Author

You're welcome, @ZCLMK

@indushub
Copy link

indushub commented Aug 3, 2018

Hi there. Really Appreciate. Followed all the steps.
Since I am new, I could not understand ** ll /etc/myql ** bash returns no such file.
Then I ran sudo cp /etc/mysql/myslq.cnf /etc/mysql/my.cnf.fallback
it returns cp: cannot stat '/etc/mysql/myslq.cnf': No such file or directory.
I tried to open the file and I could open the file /etc/mysql/myslq.cnf
Appreciate any help in this regard.

@justinhartman
Copy link

Hi there. Really Appreciate. Followed all the steps.
Since I am new, I could not understand ** ll /etc/myql ** bash returns no such file.
Then I ran sudo cp /etc/mysql/myslq.cnf /etc/mysql/my.cnf.fallback
it returns cp: cannot stat '/etc/mysql/myslq.cnf': No such file or directory.
I tried to open the file and I could open the file /etc/mysql/myslq.cnf
Appreciate any help in this regard.

@indushub It's a typo. The mysql is spelt incorrectly in the cp command.
Instead, try: cp /etc/mysql/mysql.cnf /etc/mysql/my.cnf.fallback

@Brainiarc7
Copy link
Author

Typo corrected.

@bond2u
Copy link

bond2u commented Apr 29, 2019

Brainiarc7, thank you for that well-written and working fix for my server. I just upgraded my Ubuntu 14.04 to 16.04 two months ago and I'm still finding issues and you solved this one. Kudos to you!

@lipusz
Copy link

lipusz commented Apr 30, 2019

Worked for me too, thanks a lot @Brainiarc7 for sharing this! 👍

@Brainiarc7
Copy link
Author

@bond2u and @lipusz you're both welcome

@asbai
Copy link

asbai commented Sep 11, 2019

This fixes my problem, thank you!

@krishnachandu
Copy link

To do this - sudo cp /etc/mysql/mysql.cnf /etc/mysql/my.cnf.fallback
I dont have etc/mysql/mysql.cnf in first case,
How to proceed?
Any leads are appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment