1. If wGET is not installed, install it first

yum -y install wget
Copy the code

2, download the MySQL official Yum Repository

wget http://repo.mysql.com/mysql57-community-release-el7- 10.noarch.rpm
Copy the code

# Yum Repository # Yum Repository # Yum Repository # Yum Repository

yum -y install mysql57-community-release-el7- 10.noarch.rpm
Copy the code

4. Install the mysql server

yum -y install mysql-community-server
Copy the code

5, to start the mysql

systemctl start mysqld.service
Copy the code

6. Check the mysql running status

systemctl status mysqld.service
Copy the code

7. Check the database password

grep "passsword" /var/log/mysqld.log
Copy the code

Access denied for user ‘root’@’localhost’ (using password: YES)

  • 1. Edit /etc/my.cnf and add a line at the end of the [mysqld] section
skip-grant-tables 
Copy the code
  • 2. Save the Settings and restart mysql
service mysqld restart 
Copy the code
  • 3. Run the following command, press Enter, enter the password, and press Enter to log in to Mysql
mysql -uroot -p mysql 
Copy the code
  • 4. Reset your password to the part your_pwd that you want
update user set authentication_string= password ('lvdaqiang123') where user = 'root';
Copy the code

The reason to use authentication_string here: the mysql database does not have the password field, the password field has been changed to authentication_string

  • 5. Refresh permissions
flush privileges; 
Copy the code
  • 6, change MySQL login Settings back
vim /etc/my.cnf 
Copy the code

Save and exit vim with the skip-grant-tables comment you just added to the [mysqld] segment

  • 7. Restart mysql
systemctl restart mysqld
Copy the code

Centos6 is the service mysqld restart.

Mysql -uroot -p run the show databases; Errors will be reported, and the following modifications are needed

  • 1. Change the password. The password can be the same as the previous step
ALTER USER USER() IDENTIFIED BY 'lvdaqiang123';
Copy the code

MySQL 5.7.6 Earlier users can run the following command:

SET PASSWORD = PASSWORD('Xiaoming250');
Copy the code
  • 2. If an error occurs (statement execution fails), run the following command:
set global validate_password_policy=0;
set global validate_password_length=1;
Copy the code

Version 8.0 solution

set global validate_password.policy=0;
set global validate_password.length=1;
Copy the code

Run the command in Step 1 again

  • 3. Add a remote user
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'lvdaqiang123' WITH GRANT OPTION;
Copy the code

Grant all PRIVILEGES on the database name. @”%” identified by “%”; Database name. Table name if written as. % means that any host can access the server. If you want a specific IP address, change the % sign to a specific IP address

flush privileges; # refresh the previous content
Copy the code
  • Yum Repository: Yum Repository: Yum Repository: Yum Repository: Yum Repository: Yum Repository: Yum Repository: Yum Repository
yum -y remove mysql80-community-release-el7- 1.noarch
Copy the code
  • 5. Set the two startup commands
systemctl enable mysqld
systemctl daemon-reload
Copy the code
  • 6. Set the default encoding to UTf8, change the /etc/my. CNF configuration file, and add the encoding configuration under [mysqld]
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
Copy the code
  • 7. Restart
systemctl restart mysqld
Copy the code