# Fix for MYSQL 8x installation failure on Ubuntu 20.04 ### Day 1 Found out there's [open bug in Ubuntu's #launchpad](https://bugs.launchpad.net/ubuntu/+source/mysql-8.0/+bug/1897381) & a discussion is [MySQL official forum](https://forums.mysql.com/read.php?11,700187,700198#msg-700198). The solution didn't works out to me. Removed couple of scripts responsbile for pre/post installations. ```bash # remove post/pre install scripts sudo rm -rf /var/lib/dpkg/info/mysql-server-8.0.preinst sudo rm -rf /var/lib/dpkg/info/mysql-server-8.0.postinst sudo rm -rf /var/lib/dpkg/info/mysql-* ``` Still no luck :( --- ### Day 2 - Research & learn Another search leads to [#CopyProgramming](https://copyprogramming.com/howto/mysql-service-is-missing-but-shows-up-on-list) which provides me a hint why `mysql` is listed as running during installtion while it is not. `Maria` - sister of `MySQL` conflicts with possible services/configs. ```bash sudo dpkg --get-selections | grep maria mariadb-client-10.1 deinstall mariadb-common deinstall mariadb-server-10.1 deinstall ``` And I removed them all. ---- ### Day 3 - Final fix ! Meanwhile some how I landed on this [#AskUbuntu](https://askubuntu.com/a/1296031/41013) which leads me to validate the service path. Upon checking, `/etc/systemd/system/mysql.service` linked to broken `mariadb.service` which may be possible culprit. I tried `mariadb` long back and it may root cause now. ```bash #link broken ls -l /etc/systemd/system/mysql* /etc/systemd/system/mysql.service ⇒ /lib/systemd/system/mariadb.service /etc/systemd/system/mysqld.service ⇒ /lib/systemd/system/mariadb.service ``` I unlinked them, correct the link & rebooted the device ```bash #correct target ls -l /lib/systemd/system/my* /lib/systemd/system/mysql.service /lib/systemd/system/mysql@.service #link fixed ls -l /etc/systemd/system/mysql* /etc/systemd/system/mysql.service ⇒ /lib/systemd/system/mysql.service /etc/systemd/system/mysqld.service ⇒ /lib/systemd/system/mysql.service ``` Did a fresh attempt of reinstalling the `mysql-server` with others. ```bash # prepare sudo apt --fix-broken install sudo apt autoclean sudo apt autoremove # make sure mysql8 is selected sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb # cleaning everything sudo rm -rf /etc/apparmor.d/abstractions/mysql /etc/apparmor.d/cache/usr.sbin.mysqld /etc/mysql /var/lib/mysql /var/log/mysql* /var/log/upstart/mysql.log* /var/run/mysqld # fresh install sudo apt install mysql-server-8.0 mysql-client mysql-common mysql-server-core-8.0 mysql-client-core-8.0 ``` **Yes! It works.** Finally I'm able to install and run MySQL after long time. ### Appendix Some use full commands: ```bash #key config files/path ls -laF /lib/systemd/system/mysql.service # path of mysql.service # fixing deps / broken packages sudo apt install -f # install the deps / broken packages sudo apt install --fix-broken sudo dpkg --configure -a # does the above with more on config missing services sudo apt install --reinstall mysql-server-8.0 #re-install the package sudo systemctl disable mysql.service # disable the service sudo systemctl enable mysql.service # enable the service # remove post/pre install scripts sudo rm -rf /var/lib/dpkg/info/mysql-* sudo dpkg --remove --force-remove-reinstreq mysql-server-8.0 #beta zone sudo apt-get --dry-run install initscripts sudo dpkg --remove --force-remove-reinstreq mysql-server-8.0 sudo apt purge apparmor # another batch sudo -i service mysql stop killall -KILL mysql mysqld_safe mysqld apt-get --yes purge mysql-server mysql-client apt-get --yes autoremove --purge apt-get autoclean deluser --remove-home mysql delgroup mysql rm -rf /etc/apparmor.d/abstractions/mysql /etc/apparmor.d/cache/usr.sbin.mysqld /etc/mysql /var/lib/mysql /var/log/mysql* /var/log/upstart/mysql.log* /var/run/mysqld updatedb sudo apt update sudo apt upgrade wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb sudo dpkg -i mysql-apt-config* apt update sudo apt update sudo apt upgrade sudo apt install mysql-server dpkg -l | grep mysql ii mysql-apt-config 0.8.12-1 all Auto configuration for MySQL APT Repo. ii mysql-client 8.0.36-0ubuntu0.20.04.1 all MySQL database client (metapackage depending on the latest version) ii mysql-client-8.0 8.0.36-0ubuntu0.20.04.1 amd64 MySQL database client binaries ii mysql-client-core-8.0 8.0.36-0ubuntu0.20.04.1 amd64 MySQL database core client binaries ii mysql-common 5.8+1.0.5ubuntu2 all MySQL database common files, e.g. /etc/mysql/my.cnf ii mysql-server-8.0 8.0.36-0ubuntu0.20.04.1 amd64 MySQL database server binaries and system database setup ii mysql-server-core-8.0 8.0.36-0ubuntu0.20.04.1 amd64 MySQL database server binaries 0 ✓ success ^_^ sudo mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 8.0.36-0ubuntu0.20.04.1 (Ubuntu) Copyright (c) 2000, 2024, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> ^DBye 0 ✓ success ^_^ ________________________________________________________________________________ thulasi@thulasi-Inspiron-15-356773.166.41.67~2024-03-02 19:46:26 $ ``` --- Encountered similar issue! Possibly this is due to dir `/var/lib/mysql_replica/` likely mounted on other disk or other partition and `AppArmor` prevent mysql accessing the dir. There's bug on this at MySQL. [Bug #82281 - mysqld --initialize reports "Permission denied", regardless of permissions](https://bugs.mysql.com/bug.php?id=82281) **Workaround:** Disable the mysqld profile for AppArmor `sudo aa-disable /usr/sbin/mysqld` ```bash dpkg -l | awk '{print $2}' | grep -i mysql | grep -v lib # list packages sudo dpkg -P --force-all $(dpkg -l | awk '{print $2}' | grep -i mysql | grep -v lib) # purge them ```