How to install mysql 5.5 or 5.6 on ubuntu 16.04 xenial

Published on Author JF10 Comments

Installing MySQL 5.5/6 on Ubuntu 16.06

You might be hosting your site on something like Acquia and they have recently upgraded to Ubuntu 16 Xenial.

However, you (as an awesome developer) still want to duplicate the environment as much as possible so you want to configure a local or staging server using Ubuntu, etc.

Here’s how to install MySQL 5.5/6 on Xenial.

First, a couple items:

  • apt-get install mysql

This and other methods of installation will not work. You will need to do the install manually.

4-18-2019 – End Of Life

Before installing, you should consider that 5.5 is End of Life and 5.6 is EOL in 2021.

UPDATED 7-21-17 – Scroll to the bottom

Find the correct install for MySQL 5.5/6

Go to www.mysql.com  > downloads > you will see links for older versions.

When you get to the dropdowns for OS, you will see Ubuntu. Note that these only go up to 14. Instead, select Linux/Generic. Scroll to the bottom to get the TAR Archive – select 32 or 64 bit.

Click download

On the following page look for “No thanks, just start my download.” Right click and copy the URL. Here is the URL for 5.5 as it was when I wrote this:

https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz

Connect to your server.

  1. Uninstall any existing version of MySQL
    sudo rm /var/lib/mysql/ -R
  2. Delete the MySQL profile
    sudo rm /etc/mysql/ -R
  3. Automatically uninstall mysql
    sudo apt-get autoremove mysql* --purge
    sudo apt-get remove apparmor
  4. Download version 5.5.51 from MySQL site
    wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz
  5. Add mysql user group
    sudo groupadd mysql
  6. Add mysql (not the current user) to mysql user group
    sudo useradd -g mysql mysql
  7. Extract  to /usr/local
    sudo tar -xvf mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz /usr/local/
  8. Create mysql folder in /usr/local by moving the untarred folder
    cd /usr/local
    sudo mv mysql-5.5.49-linux2.6-x86_64 mysql
  9. Set mysql directory owner and user group
    cd mysql
    sudo chown -R mysql:mysql *
  10. Install the required lib package (works with 5.6 as well)
    sudo apt-get install libaio1
  11. Execute mysql installation script
    sudo scripts/mysql_install_db --user=mysql
  12. Set mysql directory owner from outside the mysql directory
    sudo chown -R root .
  13. Set data directory owner from inside mysql directory
    sudo chown -R mysql data
  14. Copy the mysql configuration file
    sudo cp support-files/my-medium.cnf /etc/my.cnf (mysql 5.5)
    sudo cp support-files/my-default.cnf /etc/my.cnf (mysl 5.6)
  15. Start mysql
    sudo bin/mysqld_safe --user=mysql &
    sudo cp support-files/mysql.server /etc/init.d/mysql.server
  16. Initialize root user password
    sudo bin/mysqladmin -u root password '[your new password]'
  17. Add mysql path to the system
    sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
  18. Reboot!
  19. Start mysql server
    sudo /etc/init.d/mysql.server start
    
  20. Stop mysql server
    sudo /etc/init.d/mysql.server stop
  21. Check status of mysql
    sudo /etc/init.d/mysql.server status
  22. Enable myql on startup
    sudo update-rc.d -f mysql.server defaults

    Disable mysql on startup (Optional)

    sudo update-rc.d -f mysql.server remove
  23. REBOOT!
  24. Now directly use the command below to start mysql if it hasn’t
    sudo service start mysql -u root -p

Update 7-21-2017

There’s always an easier way, instructions from here.

sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty universe'
sudo apt-get update
sudo apt install mysql-server-5.6 * see note below if you get an error
sudo apt install mysql-client-5.6

You may need to

sudo rm /var/lib/mysql/debian-5.7.flag

or it will abort with Sub-process /usr/bin/dpkg returned an error code (1)

10 Responses to How to install mysql 5.5 or 5.6 on ubuntu 16.04 xenial

  1. Very nice, and it works too! Many thanks the for 101 lesson. I didn’t see the Oracle docs mentioning to chown and I suspect that was my issue.

  2. The correct is: in step 7

    Extract to /usr/local
    sudo tar -xvf mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

  3. I have followed these steps but now I want to uninstall the mysql which I installed from this tar.gz package. What steps I need to follow for this?

    • From which part of the post? There are two steps. If you are referring to the top section, follow the instructions where it says
      “Uninstall any existing version of MySQL” 🙂

  4. Hi all, I’ve got stuck at step 19. The command returns the following error message: Starting mysql.server (via systemctl): mysql.server.serviceFailed to start mysql.server.service: Unit mysql.server.service not found.
    failed!
    Any advices? Thanks!

    • I would assume that the symlinks didn’t work?

      It is a couple years down the road. Did you try to install from the repos (see the bottom)?

    • Depending on where you installed everything, it might be in here: /etc/mysql/mysql.conf.d/mysqld.cnf

      bind-address = 127.0.0.1

      For 50-server.cnf, are you running MySQL or MariaDB?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.