Skip to content

Instantly share code, notes, and snippets.

@vinodpandey
Last active March 25, 2024 18:13
Show Gist options
  • Star 41 You must be signed in to star a gist
  • Fork 33 You must be signed in to fork a gist
  • Save vinodpandey/1a4b5b8228f9a000ca236820185fc3bc to your computer and use it in GitHub Desktop.
Save vinodpandey/1a4b5b8228f9a000ca236820185fc3bc to your computer and use it in GitHub Desktop.
Install MySQL 5.6.xx on Ubuntu 18.04 & Ubuntu 20.04

MySQL Download URL

https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

Open the terminal and follow along:

  • Uninstall any existing version of MySQL
sudo rm /var/lib/mysql/ -R
  • Delete the MySQL profile
sudo rm /etc/mysql/ -R
  • Automatically uninstall mysql
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor
  • Download version 5.6.46 from MySQL site
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
  • Add mysql user group
sudo groupadd mysql
  • Add mysql (not the current user) to mysql user group
sudo useradd -g mysql mysql
  • Extract it
sudo tar -xvf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
  • Move it to /usr/local
sudo mv mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/
  • Create mysql folder in /usr/local by moving the untarred folder
cd /usr/local
sudo mv mysql-5.6.46-linux-glibc2.12-x86_64 mysql

  • set MySql directory owner and user group
cd mysql
sudo chown -R mysql:mysql *
  • Install the required lib package
sudo apt-get install libaio1 libncurses5
  • Execute mysql installation script
sudo scripts/mysql_install_db --user=mysql
  • Set mysql directory owner from outside the mysql directory
sudo chown -R root .
  • Set data directory owner from inside mysql directory
sudo chown -R mysql data
  • Copy the mysql configuration file
sudo cp support-files/my-default.cnf /etc/my.cnf
  • Start mysql
sudo bin/mysqld_safe --user=mysql &
sudo cp support-files/mysql.server /etc/init.d/mysql.server
  • Set root user password
sudo bin/mysqladmin -u root password '[your new password]'
  • Add mysql path to the system
sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
  • Reboot!

  • Start mysql server

sudo /etc/init.d/mysql.server start
  • Stop mysql server
sudo /etc/init.d/mysql.server stop
  • Check status of mysql
sudo /etc/init.d/mysql.server status
  • 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
  • REBOOT!

  • Now login using below command, start mysql server if it's not running already

mysql -u root -p
@socheatkd
Copy link

thank you so much. this work for me

@anbuarivu
Copy link

Hi,

I could not able to start mysql in background with following command

sudo bin/mysqld_safe --user=mysql &

Output:
● mysql.server.service - LSB: start and stop MySQL
Loaded: loaded (/etc/init.d/mysql.server; generated)
Active: active (exited) since Wed 2022-06-01 17:51:40 IST; 1min 6s ago
Docs: man:systemd-sysv-generator(8)
Process: 968 ExecStart=/etc/init.d/mysql.server start (code=exited, status=0/SUCCESS)

Jun 01 17:51:40 portfolio systemd[1]: Starting LSB: start and stop MySQL...
Jun 01 17:51:40 portfolio mysql.server[994]: /etc/init.d/mysql.server: 1: my_print_defaults: …found
Jun 01 17:51:40 portfolio mysql.server[968]: Starting MySQL
Jun 01 17:51:40 portfolio mysql.server[968]: * Couldn't find MySQL server (/usr/local/mysql/…safe)
Jun 01 17:51:40 portfolio systemd[1]: Started LSB: start and stop MySQL.
Hint: Some lines were ellipsized, use -l to show in full.

username@server:~$ mysql -u root -p

Command 'mysql' not found, but can be installed with:

sudo apt install mysql-client-core-8.0 # version 8.0.29-0ubuntu0.20.04.3, or
sudo apt install mariadb-client-core-10.3 # version 1:10.3.34-0ubuntu0.20.04.1

username@server:~ $ sudo bin/mysqld_safe --user=mysql &
[1] 1734
username>@server:~ $ sudo: bin/mysqld_safe: command not found

Can someone help me to resolve this?

@Rod01Andres
Copy link

OMG I've been fighting with the last version of mysql for 4 hours!!! now I arrive here and everything is solved, Thanks!!

@wakko4
Copy link

wakko4 commented Oct 22, 2022

Hi,

I could not able to start mysql in background with following command

sudo bin/mysqld_safe --user=mysql &

Output: ● mysql.server.service - LSB: start and stop MySQL Loaded: loaded (/etc/init.d/mysql.server; generated) Active: active (exited) since Wed 2022-06-01 17:51:40 IST; 1min 6s ago Docs: man:systemd-sysv-generator(8) Process: 968 ExecStart=/etc/init.d/mysql.server start (code=exited, status=0/SUCCESS)

Jun 01 17:51:40 portfolio systemd[1]: Starting LSB: start and stop MySQL... Jun 01 17:51:40 portfolio mysql.server[994]: /etc/init.d/mysql.server: 1: my_print_defaults: …found Jun 01 17:51:40 portfolio mysql.server[968]: Starting MySQL Jun 01 17:51:40 portfolio mysql.server[968]: * Couldn't find MySQL server (/usr/local/mysql/…safe) Jun 01 17:51:40 portfolio systemd[1]: Started LSB: start and stop MySQL. Hint: Some lines were ellipsized, use -l to show in full.

username@server:~$ mysql -u root -p

Command 'mysql' not found, but can be installed with:

sudo apt install mysql-client-core-8.0 # version 8.0.29-0ubuntu0.20.04.3, or sudo apt install mariadb-client-core-10.3 # version 1:10.3.34-0ubuntu0.20.04.1

username@server:~ $ sudo bin/mysqld_safe --user=mysql & [1] 1734 username>@server:~ $ sudo: bin/mysqld_safe: command not found

Can someone help me to resolve this?

I got same issue. I have an app that vendor still using MySQL 5.6 Deprecated and it has been very difficult to install 5.6 on Debian 10 or Ubuntu 18. I made it work on Deb 9, but then php only gets to 7.0.

@jlurena
Copy link

jlurena commented Dec 11, 2022

Might have to also install libnuma-dev, libmysqlclient-dev and also this https://askubuntu.com/a/1337909/464278

@setaniel
Copy link

Thank you!

@Juanvcas
Copy link

Thank you!

@aboooud
Copy link

aboooud commented Mar 29, 2023

Thank you

@havanri
Copy link

havanri commented May 10, 2023

thank you very much much <3

@MartinGuerraGit
Copy link

Thank you!

@tbernacchi
Copy link

root@ubuntu:~# mysql -u root -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

@tbernacchi
Copy link

apt-get install libncurses5
ldconfig

Solved to me. Thanks for sharing!

@vijaymuddu
Copy link

vijaymuddu commented Sep 16, 2023

Worked for me on Ubuntu 20
Thank You

After installation data directory stays /usr/local/mysql/data
you can stop mysql and change location in my.cnf and copy the /usr/local/mysql/data to another location

@hemloeurt
Copy link

hemloeurt commented Sep 19, 2023 via email

@CNZedChou
Copy link

And you, my friend, are true hero.

@nVentis
Copy link

nVentis commented Jan 22, 2024

Worked nicely with adding apt-get install libnuma-dev also with MySQL 5.5. Many thanks!

@AdamMichaelArthur
Copy link

This was bleeping great. Thank-you!

@Jiculi
Copy link

Jiculi commented Mar 25, 2024

Muchas gracias, muy util

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