MySQL installation and use tutorial on Linux

This article mainly explains the steps of installing, configuring and using MySQL on Linux. The Linux system used in this article is CentOS7.6 version

1. MySQL installation based on Linux system

1.1 Use the wget command to download the rpm package of MySQL

Create and enter the specified directory in the Linux system, the following is the /usr/local directory, use the pwd command to view the path of the current directory, and then use the wget command to present the rpm package of mysql, the version of mysql downloaded here is 5.7

image.png

1.2 Install MySQL via rpm

Install the downloaded rpm package through the rpm command

image.png

1.3 Install mysql service through yum

MySQL runs as a service in the system. After installing the rpm package, install the MySQL service through the yum command.

image.png

During the installation of mysql service, you may encounter the following error:

image.png

If the above installation error occurs, it means that the GPG verification during the installation process fails. You can add  --nogpgcheck options after the yum command to re-execute the installation:

image.png

2. MySQL service management

2.1 Add the MySQL service to boot

After adding it as a startup, the MySQL service will start with the system startup

image.png

2.2 Start the MySQL service

In CentOS7, systemctl can be used for service management. If the Linux system version you use does not support systemctl , you can also use it service mysqld start to start the MySQL service

image.png

2.3 Stop the MySQL service

image.png

or use:

image.png

3. Basic use of MySQL

3.1 Find the MySQL initial password

After the MySQL service is started, you can start the MySQL client to connect to the MySQL database through the mysql command. The root account password is required for the connection. During the installation of MySQL, the initial password of the root account is generated by default and recorded in the file. You can query the initial password through the cat command  /var/log/mysqld.log . The execution command is as follows:

image.png

The empty color box in the execution result as shown in the figure below is the first-acquaintance password

image.png

3.2 Log in to MySQL with the initial password

Execute the mysql command, -u the root after the option means the user name, -p press Enter directly without adding parameters after the option, and then enter the initial password (there is no feedback in the input box when entering the password, just press Enter after the input is complete), and an execution prompt appears, mysql> indicating login successful.

image.png

3.3 Modify the initial MySQL password

The initial password is only used for login, and the initial password must be changed after login to perform database operations; since MySQL has password security verification, you can first set the password verification policy to LOW, and then set the password, as follows:

image.png

3.4 Authorize root user to allow remote login

After the password modification is complete, execute the exit command to exit the mysql client, and then log in again with the modified password

image.png

After logging in, the root user does not support remote connection by default. If you want to use the root account of a remote client (Navicat, SQLYog, etc.) to connect to the MySQL database for authorization, you can specify the password for the remote connection of the root account when authorizing (the password for the following command is admin123)

image.png

After the above two instructions are completed, you can try to use navicat to connect to the MySQL database!
PS: If you use the Linux system of the cloud server, you should also pay attention to the security group configuration to allow port 3306~

Guess you like

Origin blog.csdn.net/GUDUzhongliang/article/details/131823973