How to install MySQL on Debian 10 Linux

MySQL is the world's most popular open source relational database management system, database system and MariaDB is the default in Debian 10, Mysql is not included in the default software repositories of Debian.

This tutorial shows how from over 10 Debian MySQL Apt repositories to install and configure MySQL.

Configure MySQL repository

To MySQL APT repository added to the system, go to the repository download page and use the following wget command to download the latest release package:

wget http://repo.mysql.com/mysql-apt-config_0.8.13-1_all.deb

After the download is complete, a user with sudo privileges to install distributions:

sudo apt install ./mysql-apt-config_0.8.13-1_all.deb

You will see the configuration menu, you can select the version you want to install MySQL.

MySQL 8.0 is pre-selected, if you want to install MySQL 5.7, select the MySQL Server & Cluster (Currently selected: mysql-8.0) and choose your favorite MySQL version .

We want to install the MySQL 8.0 version. Press Tab and select OK final press Enter (shown above).

If you are not sure which version to select, see the documentation for the application you want to deploy on the server.

Installing MySQL

By running the following command to update the package list and install the MySQL server package:

sudo apt update
sudo apt install mysql-server

The installer will ask you to set the MySQL root password. Now do not set a password (blank), we will be set in the next section.

Next, you'll see a message telling you to verify information about the identity of the new MySQL 8. Before selecting the default MySQL 8 authentication plug-in, make sure that your application supports it.

After installation is complete, MySQL service will start automatically, you can verify it by typing the following:

sudo systemctl status mysql
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
   Active: active (running) since Fri 2019-07-26 13:23:25 PDT; 37s ago
   ...

MySQL protection

Run the command mysql_secure_installation set the root password and security in the MySQL installation:

sudo mysql_secure_installation
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:

You will be asked to configure VALIDATE PASSWORD PLUGIN for the contents of the user's password strength test MySQL. Password authentication policy has three levels: low, medium and strong. If you do not want to set a password validation plug-ins press ENTER.

Please set the password for root here.

New password:

Re-enter new password:

In the next prompt, you will be asked for the MySQL root user password.

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

After setting the root password, the script will ask you to remove anonymous users, restrict the root user to access the local computer and delete the test database. You should answer all questions "Yes."

Connect to the MySQL server

To interact with MySQL through the terminal, use mysql as the MySQL server package dependencies installed client.

If you select the default login authentication method MySQL server as root:

sudo mysql

Otherwise, if you choose the old method of authentication to log type:

mysql -u root -p

You will be prompted previously set the root password when you enter mysql_secure_installation script. After entering your password, you will see My SQL shell, as shown below:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.17 MySQL Community Server - GPL
...

in conclusion

In this tutorial, you've learned how to install and protect the MySQL server on Debian 10 servers. We also show you how to connect to the MySQL shell.

Finally, say, if your application does not have any specific requirements, you should stick with the default database system 10 Debian MariaDB.

If you have any questions, please leave a message below.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159844.htm