How To Install MySQL 5.7/8.0 on Ubuntu 16.04/14.04 & Debian 9/8

0

MySQL is an open source relational database management system, commonly used in web applications to store and retrieve records and information.

MySQL was first developed by MYSQL AB, now owned by Oracle Corporation. It was the primary database application for Linux operating system until MariaDB, a fork of MySQL, came into the picture.

In this article, we will work on the task of how to Install MySQL 5.7 on Ubuntu 16.04 / Ubuntu 14. 04 & Debian 9 / Debian 8.

Add MySQL Repository

MySQL server is no longer distributed through base operating system image or OS repositories due to software licensing. So, you would need to add its official repository to install MySQL community server.

wget https://dev.mysql.com/get/mysql-apt-config_0.8.9-1_all.deb

Install the repository package using the dpkg command.

sudo dpkg -i mysql-apt-config_0.8.9-1_all.deb

The package installer will prompt you to select the MySQL repository. Based on your selection, the installer will configure repositories to receive the appropriate version of MySQL.

Here, I will choose the MySQL 5.7 which is the default one. Then select OK and then press enter.

If you want to install MySQL 8.0, then go to install MySQL 8.0 RC section to know more about selecting MySQL 8.0 preview repository.
Install MySQL 5.7 on Ubuntu 16.04 - Configure MySQL 5.7 repository
Install MySQL 5.7 on Ubuntu 16.04 – Configure MySQL 5.7 repository

Install MySQL Community Server

Oracle currently offers both stable version and beta versions of MySQL server. You can choose the one you want to install it on your machine.

Install MySQL 5.7

Update the repository index using the apt-get update command.

sudo apt-get update

Use the apt command to install the latest stable version of MySQL.

sudo apt-get -y install mysql-community-server

The package installer will prompt you to set the MySQL root password.

Instaall MySQL 5.7 on Ubuntu 16.04 - Set MySQL root Password
Install MySQL 5.7 on Ubuntu 16.04 – Set MySQL root Password

Re-enter the password.

Install MySQL 5.7 on Ubuntu 16.04 - Re-enter MySQL root Password
Install MySQL 5.7 on Ubuntu 16.04 – Re-enter MySQL root Password

Install MySQL 8.0 RC

MySQL 8.0 is currently an RC (release candidate). It should only be installed to preview upcoming features of MySQL and is not recommended for use in production environments.

Run the dpkg-reconfigure command to update the MySQL repository configuration.

sudo dpkg-reconfigure mysql-apt-config

Press enter to change the MySQL version on this page.

Install MySQL 5.7 on Ubuntu 16.04 - Change MySQL repository
Install MySQL 5.7 on Ubuntu 16.04 – Change MySQL repository

Choose the mysql-8.0 preview and then press enter.

Install MySQL 5.78.0 on Ubuntu 16.04 - Select MySQL 8.0 Preview
Install MySQL 5.78.0 on Ubuntu 16.04 – Select MySQL 8.0 Preview

Press enter to accept the warning message.

Install MySQL 5.7 on Ubuntu 16.04 - Accept MySQL 8.0 Warning
Install MySQL 5.7 on Ubuntu 16.04 – Accept MySQL 8.0 Warning

Choose the OK and then press enter.

Install MySQL 5.7 on Ubuntu 16.04 - Configure MySQL 8.0 Repository
Install MySQL 5.7 on Ubuntu 16.04 – Configure MySQL 8.0 Repository

Update the repository index using the apt command.

sudo apt-get update

Run the following command to install MySQL 8.0 RC on your machine.

sudo apt-get -y install mysql-community-server

The package installer will prompt you to set the MySQL root password.

Instaall MySQL 8.0 on Ubuntu 16.04 - Set MySQL root Password
Install MySQL 8.0 on Ubuntu 16.04 – Set MySQL root Password

Re-enter the password.

Install MySQL 8.0 on Ubuntu 16.04 - Re-enter MySQL root Password
Install MySQL 8.0 on Ubuntu 16.04 – Re-enter MySQL root Password

Start MySQL server

After the installation of MySQL, you can start MySQL server using the following command.

### Ubuntu 16.04 / Debian 9/8 ###

sudo systemctl start mysql

### Ubuntu 14.04 ###

sudo service mysql start

Enable MySQL server at system startup.

### Ubuntu 16.04 / Debian 9/8 ###

sudo systemctl enable mysql

### Ubuntu 14.04 ###

sudo update-rc.d mysql defaults

Verify that MySQL server service is started using the following command.

### Ubuntu 16.04 / Debian 9/8 ###

sudo systemctl status mysql

### Ubuntu 14.04 ###

sudo service mysql status

Output

Ubuntu 16.04 / Debian 9/8:

mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-03-05 11:43:12 UTC; 7min ago
 Main PID: 13623 (mysqld)
   CGroup: /system.slice/mysql.service
           └─13623 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Mar 05 11:43:11 mysqub systemd[1]: Starting MySQL Community Server...
Mar 05 11:43:12 mysqub systemd[1]: Started MySQL Community Server.
Mar 05 11:49:13 mysqub systemd[1]: Started MySQL Community Server.

Ubuntu 14.04:

* MySQL Community Server 8.0.3-rc-log is running

Work with MySQL Server

Login to MySQL with the root user and the password you set during the installation.

mysql -u root -p

Output

MySQL 5.7:

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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>

MySQL 8.0:

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.3-rc-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

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>

Install phpMyAdmin

phpMyAdmin is an open source web-based management interface to manage MySQL and MariaDB database servers.

phpMyAdmin doesn’t seem working with MySQL 8.0 RC.

Install phpMyAdmin using the apt command.

sudo apt-get install -y phpmyadmin

Follow the on-screen prompt to configure phpMyAdmin.

Select the web server.

Install phpMyAdmin on Ubuntu 16.04 - Select Web Server
Install phpMyAdmin on Ubuntu 16.04 – Select Web Server

Set the phpMyAdmin application password.

Install phpMyAdmin on Ubuntu 16.04 - Set phpMyAdmin Application Password
Install phpMyAdmin on Ubuntu 16.04 – Set phpMyAdmin Application Password

Re-enter the phpMyAdmin application password.

Install phpMyAdmin on Ubuntu 16.04 - Re-enter Application Password
Install phpMyAdmin on Ubuntu 16.04 – Re-enter Application Password

Enter the MySQL root password you set during the installation of MySQL community server.

Install phpMyAdmin on Ubuntu 16.04 - Enter root Password
Install phpMyAdmin on Ubuntu 16.04 – Enter root Password

Access phpMyAdmin web interface

Open up your web browser and enter the following URL.

http://your.ip.add.ress/phpmyadmin

Log in as a MySQL root user.

Install phpMyAdmin on Ubuntu 16.04 - phpMyAdmini Login Screen
Install phpMyAdmin on Ubuntu 16.04 – phpMyAdmini Login Screen

phpMyAdmin home page:

Install phpMyAdmin on Ubuntu 16.04 - phpMyAdmin Home Page
Install phpMyAdmin on Ubuntu 16.04 – phpMyAdmin Home Page

That’s All.

Further Reading

You might also like
Shares