Centos8 install MySQL (valid for pro-test)

1. Download the compressed package: https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar

2. Upload to the server

Command: rz

3. Unzip

tar -xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar 

4. Install in order

rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm

If this error occurs during the installation process, add --force --nodeps at the end, which may be caused by the installation of an old version of GPG keys by yum

 5. Configuration·MySQL

vim /etc/my.cnf

Add these three lines

skip-grant-tables
character_set_server=utf8
init_connect='SET NAMES utf8'

skip-grant-tables: skip login verification

character_set_server=utf8: Set the default character set UTF-8

init_connect='SET NAMES utf8': Set the default character set UTF-8

6. Set boot up

systemctl start mysqld.service

Start mysql

mysql

 set password

update mysql.user set authentication_string=password('123456') where user='root';

 Effective immediately

flush privileges;

Exit mysql

exit

Stop mysql service

systemctl stop mysqld.service

Restart mysql service

systemctl start mysqld.service

View mysql running status

systemctl status mysqld.service

If you make a mistake in entering other commands, reset the password

set password=password('123456');

View password policy

SHOW VARIABLES LIKE 'validate_password%'; 

1), validate_password_length, the total length of the fixed password;
2), validate_password_dictionary_file specifies the file path for password verification;
3), validate_password_mixed_case_count, the entire password must contain at least the total number of upper/lowercase letters;
4), validate_password_number_count, the entire password must contain at least The number of Arabic numerals;
5), validate_password_policy specifies the password strength verification level, the default is MEDIUM;

Set the password verification strength level, set the global parameter of validate_password_policy to LOW 

set global validate_password_policy=LOW;

 Password length changed to 6 digits

set global validate_password_length=6;

View port number

show global variables like 'port';

Open port number

firewall-cmd --zone=public --add-port=3306/tcp --permanent

Restart firewall

firewall-cmd --reload

 Enable remote access to mysql

mysql> grant all privileges on *.* to 'root'@'%' identified by '你的密码' with grant option;

Then enter the following command to refresh the authorization

mysql> flush privileges;

You can also exit mysql at this step.

 

If you cannot connect to the MySQL database remotely, there are three possible causes:

1. The firewall on this machine does not open port 3306, you need to configure the inbound rules yourself

  • Open port: firewall-cmd --zone=public --add-port=3306/tcp --permanent

       Then restart the firewall: firewall-cmd --reload

  • Or turn off the local firewall

       Turn off the firewall command: systemctl stop firewalld

2. The iptables firewall on the linux server does not open port 3306, or close the firewall on the server.

Open /etc/sysconfig/iptables

Under "-A INPUT –m state --state NEW –m tcp –p –dport 22 –j ACCEPT", add:

 -A INPUT -m state --state NEW -m tcp -p -dport 3306 -j ACCEPT

3. There is no remote permission to the mysql user,

  • mysql> USE mysql; - switch to mysql DB

       Database changed

  • mysql> SELECT User, Password, Host FROM user; - View existing users, passwords and hosts allowed to connect

       +------+----------+-----------+
       | User | Password | Host      |
       +------+----------+-----------+
       | root |          | localhost |
       +------+----------+-----------+
       1 row in set (0.00 sec)

 

  • mysql> grant all privileges on *.* to 'root'@'%' identified by '123123' with grant option;
  • mysql> - There is only one default root user, the password is empty, and only localhost connections are allowed
  • mysql> - Let's add a new root user, the password is 123123, only 192.168.1.100 is allowed to connect
  • mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100' IDENTIFIED BY '123123' WITH GRANT OPTION;
  • mysql> - @'192.168.1.100' can be replaced with @'%' for any ip access, of course, we can also directly update the root user Host with UPDATE, but it is not recommended. The SQL is as follows:
  • mysql> -- UPDATE user SET Host='192.168.1.100' WHERE User='root' AND Host='localhost' LIMIT 1;
  • mysql> flush privileges;

      Query OK, 0 rows affected (0.00 sec)

If the first three cannot be solved, and you are an Alibaba Cloud server, then look here↓↓↓

Enter the cloud server management console--"Network and Security--"Security Group--"

Create a security group--"Add access rules

At this time you connect to the database again, the connection is successful~~~

 

Guess you like

Origin blog.csdn.net/qq_43037478/article/details/114761104