Installing MySQL on Linux cloud server

Time:2021-3-3

MySQL is one of the mainstream databases, and it is free to use, so it is suitable for small and medium-sized enterprises or developers. This paper briefly introduces the installation methods under different Linux distributions.

 

Debian 9.0 (MariaDB is installed by default)

Apt (advanced packaging tool) is included in both Ubuntu and Debian systems, which is a tool for installing and uninstalling core library processing software in Debian GNU / Linux distribution and its variants.

1. Update apt get

# apt-get update

 

2. Install MySQL server

# apt-get install mysql-server

*If it is slow to download the dependency package, it can become a closer source. For domestic servers, you can use the source of alicloud or China University of science and technology. For specific source change, please refer to other articles.

 

3. After installation, MySQL service will start automatically to check whether it starts normally

# systemctl status mysql

 

4. After confirming that the MySQL service is running, you need to set the root password of the MySQL service, which can be done by running the built-in MySQL security script command

# mysql_secure_installation

For the first time, you need to be prompted to enter the password, which is blank by default. Just press enter.

 

Press the “Y” key and enter as prompted, enter the new password and confirm again.

 

Ask if you want to delete the default anonymous user, type “Y” and press enter.

 

Ask whether to prohibit remote root login. If you need to connect to the database remotely, you can select “n”, otherwise, type “Y”.

 

Ask if you want to delete the “test” database. Generally, you can delete it.

 

Ask if you want to refresh permissions, type “Y”.

 

Setup complete.

 

5. Test MySQL service by logging in as root

# mysql

 

6. Specific configuration information can be found in the configuration file“ my.cnf ”In practical application, please modify according to the hardware and load.

# vi /etc/mysql/my.cnf

 

Ubuntu 18.04

Similar to Debian, Ubuntu belongs to the Debian GNU / linux series. Here is a brief introduction.

1. Update apt package repository index

# sudo apt update

 

2. Install MySQL server

# sudo apt install mysql-server

 

3. After installation, MySQL service will start automatically to check whether it starts normally

# sudo systemctl status mysql

 

4. After confirming that the MySQL service is running, you need to set the root password of the MySQL service, which can be done by running the built-in MySQL security script command

# mysql_secure_installation

First operation meetingPrompt to configure validate password plug to test the strength of MySQL user password and improve the security. You canPress enter to skip this step.After that, you can refer to the aboveStep 4 in Debian installationFor security, it is recommended that you type “Y” for all users. The display of “all done!” indicates that the setting is complete.

 

5. Test MySQL service by logging in as root

# sudo mysql

The following output is displayed to confirm that the MySQL service has been successfully installed.

 

CentOS 8

To install mysql, CentOS needs to use rpm.

1. Download the required MySQL version RPM from the MySQL community Yum repository( https://dev.mysql.com/ )

Here, take version 8.0 as an example to install:

# rpm -ivh https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpmdev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

 

2. Use the following command to enable MySQL

# yum repolist all | grep mysql | grep enabled

 

3. Start installing MySQL

# yum --disablerepo=AppStream install -y mysql-community-server

When “complete!” appears, the installation is complete.

 

4. Start MySQL and verify that it is started

# systemctl start mysqld
# systemctl status mysqld

 

5. After confirming that MySQL service is running, clickroot passwordSet for MySQL service. This can be done using the built-in MySQL security script

First, get the default root password:

# grep 'temporary password' /var/log/mysqld.log

 

6. After obtaining the default password, run the MySQL security script

# mysql_secure_installation

The system will prompt you to enter the password. After entering, you need to enter a new password. There will be a series of security problems after modification. It is recommended to type “Y” to ensure the security of MySQL. “All done!” appears to indicate that the setting is complete.

 

7. Test MySQL service

# mysqladmin -u root -p version

 

CentOS 6/7

Similarly, by default, when using Yum to install, MariaDB will be installed by default. To install mysql, you will need to use the RPM installation method

1. Download the required MySQL version RPM from the MySQL community Yum repository( https://dev.mysql.com/ )

Take version 5.7 as an example

# wget  https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

 

2. Install RPM package

# rpm -ivh mysql57-community-release-el7-9.noarch.rpm

 

3. Start installing MySQL

# yum install mysql-server

When “complete!” appears, the installation is complete.

 

4. Start MySQL and verify that it is started

# systemctl start mysqld
# systemctl status mysqld

 

5. After confirming that MySQL service is running, clickroot passwordSet for MySQL service. This can be done using the built-in MySQL security script

First, get the default root password:

# grep 'temporary password' /var/log/mysqld.log

 

6. After obtaining the default password, run the MySQL security script

# mysql_secure_installation

The system will prompt you to enter the password. After entering, you need to enter a new password. There will be a series of security problems after modification. It is recommended to type “Y” to ensure the security of MySQL. “All done!” appears to indicate that the setting is complete.

 

7. Test MySQL service

# mysqladmin -u root -p version