This topic describes how to install and configure a MySQL database in a Linux operating system.
Procedure
- Log on to the Linux server.Note In this topic, the image Ubuntu 18.04 is used. You can replace it with your Linux distribution.
- Update the software repository and install wget.sudo apt update
sudo apt install wget
- Download the MySQL installation package.wget https://dev.mysql.com/get/mysql-apt-config_0.8.16-1_all.deb -yNote If wget is not installed, run the apt install wget command to install wget.
- Update the software repository by using the .deb package.sudo dpkg -i mysql-apt-config_0.8.16-1_all.deb
In the dialog box that appears, select MySQL Server & Cluster (Currently selected: mysql-5.7). Then, select Ok.
- Query all versions of the software package that can be installed.sudo apt update
sudo apt-cache policy mysql-server
mysql-server: Installed: (none) Candidate: 5.7.32-1ubuntu18.04 Version table: ...
5.7.32-1ubuntu18.04 indicates the MySQL database version that can be installed.
- Install MySQL 5.7 based on the obtained version. During installation, you must set
the password for the root user and keep the password confidential.sudo apt install -f mysql-client=5.7.32-1ubuntu18.04 mysql-community-server=5.7.32-1ubuntu18.04 mysql-server=5.7.32-1ubuntu18.04
- Configure the MySQL database.
- Configure the general database security.sudo mysql_secure_installation
Configure the general database security as prompted.
Enter current password for root (enter for none): <Enter password> VALIDATE PASSWORD PLUGIN 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 plugin? Press y|Y for Yes, any other key for No: Y 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 Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 Using existing password for root. Estimated strength of the password: 25 Change the password for root ? ((Press y|Y for Yes, any other key for No) : d Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y
- Enable the remote access feature.
- Edit the profile of the MySQL database.
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
- Press the I key and change the value of the bind-address parameter to 0.0.0.0.
- Press the Esc key and enter :wq! to save the profile and exit.
- Edit the profile of the MySQL database.
- Restart the MySQL database to make the configuration take effect.sudo systemctl restart mysql
- Configure the general database security.
- Check whether the MySQL database works as expected.
- Log on to the MySQL database as the root user.mysql -u root -p
- Query the existing database in the MySQL database console.show databases;
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec)
The preceding query result indicates that the existing MySQL database works as expected.
- Log on to the MySQL database as the root user.