Linux learning: Alibaba Cloud Server CentOS install MySQL

CentOS 8 install MySQL 8.0 and configure remote login
1. Install MySQL Install MySQL
using the latest package manager

 sudo dnf install @mysql

Startup#After the
installation is complete, run the following command to start the MySQL service and make it start automatically at startup:

sudo systemctl enable --now mysqld

To check whether the MySQL server is running, enter:

sudo systemctl status mysqld

Add password and security settings#
Run the mysql_secure_installation script, which performs some security-related operations and sets the MySQL root password:

sudo mysql_secure_installation

Proceed as follows:

  1. You are required to configure the VALIDATE PASSWORD component: Enter y and press Enter to enter the configuration
  2. Select the password verification strategy level, I choose 0 (low) here, press Enter to enter the new password twice
  3. Confirm whether to continue using the provided password? Type y and press enter
  4. Remove anonymous users? Type y and press enter
  5. Do not allow root remote login? I need to log in remotely, so enter n and press Enter
    Insert picture description here
  6. Remove the test database? Type y and press enter
  7. Reload the permission table? Enter y and press Enter to
    Insert picture description here
    configure remote login#
    If you need to set up root account remote login, in the previous step, root remote login is not allowed? This step needs to be set to n.
    Next, log in to MySQL locally, and set the host field of the root user to'%', which means to accept login requests from all IP addresses of root:
    Log in to MySQL locally:
mysql -uroot -p上面步骤中设置的密码

After you press Enter, you can log in, and then the terminal becomes mysql> beginning:
Insert picture description here
Then continue to execute the mysql statement, and set the host field of the root user to'%':

use mysql;
update user set host='%' where user='root';
flush privileges;

After the setting is complete, enter exit to exit mysql and return to the terminal shell interface.
Then open the 3306 port of the system firewall, which can be configured in the Alibaba Cloud server security group:
Network Security-"Security Group" Configuration Rules-"Add Security Group
Insert picture description here
Restart Service#

sudo systemctl restart mysqld

Next you can test the connection:

Insert picture description here
Succeeded!

Guess you like

Origin blog.csdn.net/weixin_41812784/article/details/105080215