How to install MySQL on Ubuntu 20.04

Xuemeng Technology

This article was first published in:

https://www.itcoder.tech/posts/how-to-install-mysql-on-ubuntu-20-04/

MySQL is the most popular open source relational database management system. It is fast, easy to use, easy to expand, and part of the popular LAMP and LEMP.

This guide explains how to install and secure MySQL on Ubuntu 20.04.

1. Prerequisites##

Make sure you are logged in as a sudo user

2. Install MySQL on Ubuntu

At the time of writing this article, the latest MySQL version number in the Ubuntu source repository is MySQL 8.0. To install it, run the following command:

sudo apt update
sudo apt install mysql-server

Once the installation is complete, the MySQL service will start automatically. To verify that the MySQL server is running, enter:

sudo systemctl status mysql

The output should show that the service is enabled and running:

● mysql.service - MySQL Community Server
  Loaded:loaded(/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
  Active:active(running) since Tue 2020-04-2820:59:52 UTC; 10min ago
 Main PID:8617(mysqld)
  Status:"Server is operational"...

Three, protection and reinforcement of MySQL

The MySQL installation file comes with a script called mysql_secure_installation, which allows you to easily improve the security of the database server.

Run this script without parameters:

sudo mysql_secure_installation

You will be asked to configure VALIDATE PASSWORD PLUGIN, which is used to test the strength of MySQL user passwords and improve security:

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

There are three levels of password verification strategies, low-level, intermediate, and high-level. If you want to set up a verification password plugin, press y or any other button to move to the next step:

There are three levels of password validation policy:

LOW    Length >=8
MEDIUM Length >=8, numeric, mixed case, and special characters
STRONG Length >=8, numeric, mixed case, special characters and dictionary                  file

Please enter 0= LOW,1= MEDIUM and 2= STRONG:2

The next time you are prompted, you will be asked to set a password for the MySQL root user:

Please set the password for root here.

New password: 

Re-enter newpassword:

If you have set up a password verification plugin, this script will display the strength of your new password. Enter y to confirm the password:

Estimated strength of the password:50 
Do you wish to continuewith the password provided?(Press y|Y for Yes, any other key for No): y

Next, you will be asked to remove any anonymous users, restrict root user access to the local machine, remove the test database and reload the permissions table. You should answer y to all questions.

Fourth, log in as the root user##

Use the MySQl client tool to interact with the MySQL server on the command line. This MySQL client has been installed as a dependent package of the MySQL server installation package.

On MySQL 8.0, the root user is authorized by the auth_socket plugin by default.

The auth_socket plugin authenticates all users connected to localhost through the Unix socket file. This means that you cannot authenticate as root by providing a password.

Log in to the MySQL server as the root user and enter;

sudo mysql

You will be shown the MySQL shell as follows:

Welcome to the MySQL monitor.  Commands end with; or \g.
Your MySQL connection id is 12
Server version:8.0.19-0ubuntu5(Ubuntu)Copyright(c)2000,2020, 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>

If you want to log in to the MySQL server as root and use other programs, such as phpMyAdmin, you have two options.

The first is to change the authentication method from auth_socket to mysql_native_password. You can do it by running the following command:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_password';
FLUSH PRIVILEGES;

The second option, the recommended option, is to create a new independent management user with access rights to all databases:

GRANT ALL PRIVILEGES ON *.* TO 'administrator'@'localhost' IDENTIFIED BY 'very_strong_password';

Five, summary##

We have shown you how to install MySQL on Ubuntu 20.04. Now that your database is online and running, your next step is to learn How to manage MySQL users and databases.


If you have any questions, please contact us in the following ways:

WeChat: sn0wdr1am86

WeChat group: add the above WeChat, remark the WeChat group

QQ: 3217680847

QQ Group: 82695646

Recommended Posts

How to install MySQL on Ubuntu 20.04
How to install MySQL on Ubuntu 14.04
How to install MySQL on Ubuntu 18.04 (linux)
How to install the latest MySQL on Ubuntu 18.04
How to install Ruby on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install mysql in Ubuntu 14.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to install mysql in Ubuntu 14.04
How to install Nginx on Ubuntu 16.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
How to install and use MySQL Workbench on Ubuntu 18.04
Install mysql on Ubuntu 14.04
How to install Docker Compose on Ubuntu 18.04
How to install Ubuntu on Raspberry Pi
How to install Bacula Server on Ubuntu 14.04