Install YUM Repo

Yum repo configuration file is not available on CentOS.

Download command:

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

2. Install the REPO:

rpm -ivh mysql57-community-release-el7-9.noarch.rpm
Copy the code

Repo mysql-community-source.repo two repo files are generated in the /etc/ym.repos. d/ directory

Yum yum yum yum yum yum yum yum yum

Note: you must go to the /etc/yum.repos.d/ directory before executing the following script

1, installation command:

yum install mysql-server
Copy the code

Start mSYQL:

Systemctl start mysqldCopy the code

3, obtain the temporary password at the time of installation (used for the first login) :

grep 'temporary password' /var/log/mysqld.log
Copy the code

4. If you have not obtained a temporary password

4.1. Delete residual mysql data

rm -rf /var/lib/mysql
Copy the code

4.2. Start mysql again

Systemctl start mysqldCopy the code

3. Login and Password change:

1. Log in using the account and password

mysql -u root -p
Copy the code

Then enter the password (the temporary password you just obtained). If the login succeeds, you can directly change the password

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mynew_pw1'; 
Copy the code

If not, go to step 2

2. Change password:

Modify the my.cnf file

vim /etc/my.cnf
Copy the code

Add “skip-grant-tables” on any line after [mysqld] to skip password verification, as shown in the following figure

skip-grant-tables skip-networking

Restart the mysql

systemctl restart mysqld 
Copy the code

Reconnect database execution

#Connecting to a Database
mysql -u root -p
#Set a temporary password
update mysql.user set authentication_string=password("mynew_password") where user="root" and host="localhost"
Copy the code

Remove the skip – grant – tables skip – networking

#Connecting to a Database
mysql -u root -p 
#Enter temporary password
#Changing a password Note The default password length is 8 uppercase case + special characters + digits
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mynew_pw1';
Copy the code

4. Enable remote control

By default, remote control is disabled for MySQL. You must add a remote access user. That is, you can only access MySQL by yourself by default.

#Connect to server: 
mysql -u root -p
#Look at all current databases:
show databases;
#Mysql > select * from mysql;
use mysql;
#Mysql > select * from 'mysql';
show tables;
#Select * from user;
select Host, User,Password from user;
#Modify Host: % in the user table to represent any client and replace it with a specific IP address.
update user set Host='%' where User='root';  
#Finally refresh:
flush privileges;
Copy the code

5. Modify ports

Open the my.cnf file and add port=2020

vim /etc/my.cnf

port=2020

Other operations

#Set security options:
mysql_secure_installation

#Close the MySQL
systemctl stop mysqld 

#Restart the MySQL
systemctl restart mysqld 

#Check the MySQL running status
systemctl status mysqld 

#Setting boot
systemctl enable mysqld 

#Turn off start up
systemctl disable mysqld 

#Set the default encoding to UTf8:Vi /etc/my.cnf # add [mysqld] character_set_server=utf8 init_connect='SET NAMES utf8'Copy the code

Reference: blog.csdn.net/wohiusdashi…

** mysql data backup: ** juejin.cn/post/685811…

** Centos scheduled tasks: ** juejin.cn/post/685811…