centos 7.6 install mysql 8 or above, enable mysql service and enable mysql remote access

1. Install mysql

1. Install wget

Check wget version

wget -V

Install wget if wget is not found

yum -y install wget

2. Download and install the yum source of mysql

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm

https://dev.mysql.com/downloads/repo/yum/ can view all yum sources

3. Install mysql-server

yum -y install mysql-server

4. Restart the mysql service

systemctl restart mysqld



Second, modify the mysql password

1. Modify the configuration file to log in to mysql without password

Find /etc/my.cnf.d/mysql-server.cnf(the installed version may have a small difference in the location of the configuration file, the approximate location will not change, all etcare below )
open the file for editing, [mysqld]add belowskip-grant-tables

2. Restart the mysql service

systemctl restart mysqld

3. Login to mysql without password

(1) Login: mysql -u root -p
(2) Prompt to enter the password and press Enter to enter
(3) Enter the database, enter: use mysql;
(4) Update the root user information and set the password to an empty string:update user set authentication_string='' where user='root';

4. Exit mysql, open the password to log in to mysql

quit;Exit mysql
and open the configuration file, comment out [mysqld]the following skip-grant-tables.
And restart the mysql service.

5. Reset password

Since the root user is set to empty in step 3, mysql -uroot -p + Enter + Enter can be used to log in directly.
change Password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

After exiting mysql, you can log in with your password.



3. Enable remote access to mysql on centos

CREATE USER 'root'@'%' IDENTIFIED BY '你的密码'; 
GRANT ALL ON *.* TO 'root'@'%'; 
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';

Refresh permissions

FLUSH PRIVILEGES;

At this point, you can access the database service anywhere with a network_^



Guess you like

Origin blog.csdn.net/qq_41231694/article/details/123800517