Marko Zivkovic
MySQL 8 installation - authentication plugin configuration information

How to install MySQL on Ubuntu

March 10, 2020 by

In this article, it will be shown how to install MySQL 5.7 and 8.0.19 versions on an Ubuntu 18.04 machine.

MySQL is one of the most popular open-source relational database management systems and can be run on almost all platforms such as MS Windows, Linux, UNIX.

Prerequisite

To follow this article, Linux Ubuntu 18.04 must be installed on the machine.

By default, the latest MySQL version is included in the APT package repository. At the time of writing this article, it is MySQL 5.7 version. To install MySQL 8 version, you must manually add MySQL’s repository.

Install MySQL 5.7 server

The first command that needs to be executed via the terminal is:

Linux Ubuntu 18.4 terminal - apt get update command

This command will update the local repository index.

To install MySQL from the APT repository, run the following command:

Linux Ubuntu 18.4  terminal - installation of the MySQL server

During the process of the installation, the [Y/n] question to continue with the installation may appear, press the Y key from the keyboard, and hit Enter. This will install MySQL on the system.

To verify the version of installed MySQL, execute the following command:

See the version of installed MySQL

After the installation, the MySQL server should start automatically. To check if it’s running, execute the following command:

See the status of installed MySQL

If, for some reasons, MySQL server is not running, execute the following command to start the MySQL server:

Configure MySQL server

To improve the security of MySQL installation, use the mysql_secure_installation command:

After you press the Enter key, the first thing that will appear is the VALIDATE PASSWORD plugin prompt window:

Validate password plugin setup

This step is to set up a secure password for the root user, depending on which type of password is chosen. Type the Y and press Enter. Enter the number for the password strength and press the Enter key:

Chose the password strength

On the next screen, enter and re-enter the password:

Enter and re-enter password

On the next step, the strength of the entered password will be shown and also will be prompted with the question to continue with the provided password. Chose Y and press the Enter key:

Estimation strength of the entered password

In the next couple of steps, you will be prompted with the questions and, depending on the answers you provide, the security on your system will be set.

The first question is about removing anonymous test users. Press Y and hit the Enter key:

Removing anonymous test users

The next question is about forbidding root login from remote systems. It is recommended for a root user to allow the connection from the local system and deny it from the remote connections. Chose Y and hit the Enter key:

Disabling root login from remote systems

The next question will be to remove the ‘test’ database. If you want to remove it, press Y and hit the Enter key:

Remove ‘test’ database prompt window

In the last step, you will be asked to reload privilege tables in order for the above-mentioned changes to take effect. Press Y and hit Enter and all security settings will be committed:

Reload privilege tables prompt window

After the privilege tables are reloaded, the “All done!” message should appear:

"All done" message

Now, when all is set, let’s login to MySQL with the root user. In the terminal, type the following command:

Insert a password for the root user and hit Enter. Instead of login to the MySQL instance, you will get the following message:

zivko@Zivko2:~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user ‘root’@’localhost’

Access denied for user 'root'@'localhost' message

By default, the root user is to use the auth_socket plugin authentication method rather than the password. To set the root user to use a password to connect to MySQL instance, the authentication method needs to be changed from the auth_socket to the mysql_native_password method.

To do this, firstly, connect to the MySQL instance using the sudo command in front of the MySQL user:

sudo command in front of the MySQL user

To check which authentication method each MySQL user uses, type the following command:

See which authentication method each MySQL user use

As can be seen from the image above, the root user uses the auth_socket plugin. To set to root user authenticate with a password, execute the following command:

After executing the ALTER USER command, run the following command:

This command will reload the grant tables and make the changes take effect. When checking which authentication method is used by the root user, you’ll get this:

Set mysql_native_password  authentication method to root user

Now, when trying to login to MySQL using the root user, you’ll be logged without any problems:

Login in MySQL using root user with mysql_native_password plugin

Install MySQL 8 server

If you want to install the latest MySQL version, in this case, MySQL 8 version, the first thing that needs to be done is to download the latest release package using the wget command from the MySQL APT Repository:

To install MySQL package, execute the command below:

In the first window that will be shown, select the first line and hit the Enter key:

MySQL 8 installation - First window

In the second window, the MySQL version can be selected. Here, you can choose between MySQL 8.0 or 5.7 version. Choose MySQL 8.0 version and press the Enter key to proceed:

MySQL 8 installation - Choose MySQL version window

Now, select the last line with the Ok text and press the Enter key to continue:

MySQL 8 installation - Select the Ok text to proceed with installation

Now, in terminal to download the latest package information from all repositories including the recently added MySQL repository, execute the following command:

To install MySQL 8, execute again the command that we used to install MySQL 5.7 version:

In the beginning, it will be prompted to insert a password for the root user. Enter the password and press Enter:

MySQL 8 installation - Enter a password for the root user

In the next window, insert the password again for the root user and hit Enter:

MySQL 8 installation - Re-enter a password for the root user

Next, some information about the new authentication system based on SHA256-based password methods will be shown, use the right arrow to select the Ok button and hit Enter to proceed:

MySQL 8 installation - authentication plugin configuration information

In the next window, you will be asked to choose the authentication plugin, select the first one, and hit Enter:

MySQL 8 installation - choose the authentication plugin method

After this step, the installation of MySQL 8 will proceed, and the server will be installed in your system. To check the installed MySQL version, use the following command:

MySQL 8 installation - see the installed MySQL version

To see more information about MySQL server, execute the following command:

MySQL 8 installation - see the installed MySQL version with more details

Uninstall MySQL server

To remove MySQL from Ubuntu 18.04, firstly, MySQL server needs to be stopped from services by executing the command below:

Then, use the purge command to uninstall:

In the prompted window, select the Yes button and press Enter:

Uninstall MySQL

Then type and execute these two commands:

Marko Zivkovic
Installation, setup and configuration, MySQL, Ubuntu

About Marko Zivkovic

Marko aka “Zivko” is a senior software analyst from Nis, Serbia focusing on SQL Server and MySQL as well as client technologies like SSMS, Visual Studio, and VSCode. He has extensive experience with quality assurance, issue escalation/resolution, and product evangelism. He is a prolific author of authoritative content related to SQL Server including a number of “platinum” articles (top 1% in terms of popularity and engagement). His writing covers a range of topics on MySQL and SQL Server including remote/linked servers, import/export, LocalDB, SSMS, and more. In his part-time, Zivko likes basketball, foosball (table-soccer), and rock music. See more about Marko at LinkedIn View all posts by Marko Zivkovic

168 Views