Install MySQL 8 on Ubuntu 20.04

By CodersDrive
30-Jun-2020
MySQL

In this post you can get step by step procedure of installing MySQL 8 on Ubuntu 20.04 systems and also do Secure server configuration.

Install MySQL 8 DB on Ubuntu 20.04
Step-1 Install MySQL server

In order to install the MySQL server open the Ubuntu terminal and enter the following commands one after another

sudo apt update
sudo apt install mysql-server

First command will update Ubuntu reporsitories with latest version. Second command will install the MySQL server on your Ubuntu machine. Before using this you need to secure your Server access.

Step-2 Configure MySQL server

This step is very important to secure your MySQL server. It will ask for many configuration options to be included or not also sets Root password. To do this run the following command on your terminal

sudo mysql_secure_installation

At first it will ask for setup of Validate Password Plugin to make passwords more secure, either you can opt 'Yes' or 'No' depending on your project requirement. In the next prompt it will ask for root password to set for you to login into server.

From here it will ask for several default features that are either to be included with this server or not like keep anonymous users, test database, remote database access. You can select Y and proceed on every step.

Step-3 Adjust Root user authentication to native menthod (optional)

In newer versions of MySQL by default the authentication method of root user will be auth_socket or sha2. We cannot access this Server from other applications like phpMyadmin. You can view this by entering following commands.

sudo mysql

Now the mysql prompt will appear. Here enter the following command as shown below. (If you have configured root password in the previous step you have to use sudo mysql -uroot -p command and then enter set passord to get mysql prompt.)

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
+------------------+-------------------------------------------+-----------------------+-----------+
| user             | authentication_string                     | plugin                | host      |
+------------------+-------------------------------------------+-----------------------+-----------+
| root             |                                           | auth_socket           | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *821D889CD6F35E658D2C81920DEDDF9A6AAC84C0 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.03 sec)

You can see in the above output, for root user the plugin is auth_socket. To make the root user accessible with native authentication type use the following command at mysql> prompt.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
mysql> FLUSH PRIVILEGES;

This will change the root user to native authentication type and also login password will be password. FLUSH PRIVILEGES; command will reload the grant tables and reloads new data. Now again check the user details.

+------------------+-------------------------------------------+-----------------------+-----------+
| user             | authentication_string                     | plugin                | host      |
+------------------+-------------------------------------------+-----------------------+-----------+
| root             | *ADE9057591DA7FC1D9C0010A6A4D1DFBFC9A0550 | mysql_native_password | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *821D889CD6F35E658D2C81920DEDDF9A6AAC84C0 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.03 sec)

The root user is now enabled with native authentication type and with new password set.

mysql> exit

Use following commands to start, stop, restart and know status of your MySQL server.

Start MySQL
sudo service mysql start
Stop MySQL
sudo service mysql stop
Restart MySQL
sudo service mysql restart
Status of MySQL
sudo service mysql status

Thank you for reading this post.


MySQL Php Ubuntu

Search blog..!

Connect with us