Centos8/linux download, install, configure, connect to MySQL5.7 (rpm mode)

Table of contents

Problem phenomenon:

problem analysis:

Solution:

download:

Install:

Configuration:

connect:

expand


Problem phenomenon:

        Today, when using Centos8 to install the rpm package of MySQL5.7, the following error occurred:

        The GPG public key for repository "MySQL 5.7 Community Server" is installed, but not available for this package.

        Finally, the problem is solved, but I still summarize the whole steps of Centos8/linux download, installation, configuration, startup, and connection to MySQL (rpm mode), hoping to help my friends.


problem analysis:

1. First, use the wget command to download the rpm package of the mysql service [here is the classic mysql5.7 version as an example]:

        wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

        At this point, the download of the mysql service is complete.

2. Then install the localhostinstall command locally:

        yum localinstall mysql57-community-release-el7-8.noarch.rpm

3. Query after installation:

        yum repolist enabled | grep "mysql.*-community.*"

 4. Then the mysql service failed to start:

        systemctl start mysqld

5. Then I read on the Internet that I need to install mysql-community-server:

         yum install mysql-community-server

 6. Unsuccessful, online information says to disable the mysql module first:

        sudo yum module disable mysql

7. Then install mysql-community-server again:

         sudo yum -y install mysql-community-server

8. A gpg public key error occurs [the GPG public key of the warehouse "MySQL 5.7 Community Server" has been installed, but it is not applicable to this software package]:

9. Query information and find that the public key url needs to be modified first:

        rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

10. Install mysql-community-server again successfully

        sudo yum -y install mysql-community-server

  11. Start the mysql service successfully:

        systemctl start mysqld

12. View the status of mysql service:

        systemctl status mysqld

        At this point, the installation of the mysql service is complete. The mysql service can be started normally.

13. View the mysql log to obtain the initial password of the root user:

        grep 'temporary password' /var/log/mysqld.log

 14. Log in to the account and change the account password (here I changed it to 123456):

        mysql -uroot -p

        Enter the initial password obtained in the previous step, and change the password after logging in:

        ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

        Error: The password does not conform to the current policy [must include letters, numbers, symbols]. This is because the installed mysql comes with a password verification plug-in; to solve this problem, you need to close the plug-in. Proceed as follows:

15. First find the path where the file my.cnf is located:
        find / -name 'my.cnf'


16. To close the password validation plug-in, there are the following two options for reference:
    16.1. Add the configuration to close the password validation at the end of the file my.cnf (here I choose this option):
        validate-password=OFF

        Save and exit.
    16.2. If you want to uninstall the built-in password verification plug-in, you can also execute:
        uninstall plugin validate_password;
17. Restart the mysql service
        systemctl restart mysqld
18. Change the account password again
        ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

19. However, some companies or projects stipulate that the operation and use of root accounts are not allowed, so here I will mention how to create users and authorize:

        19.1 Create a user:

        create user 'username'@'ip address' identified by 'password';  

        19.2 Full Authorization:

        grant all privileges on *.* to 'username'@'ip address';

         19.3: Refresh permissions:

        flush privileges; 

        19.4. Here is another sql for creating users and fully authorizing them:

        GRANT ALL PRIVILEGES ON *.* TO 'username'@'ip address' IDENTIFIED BY 'password' WITH GRANT OPTION;

        19.5. If you only want to authorize some functions (such as: INSERT, UPDATE, DELETE, SELECT, CREATE, EXECUTE ):

        GRANT INSERT,UPDATE,DELETE,SELECT,CREATE,EXECUTE ON *.* to 'username'@'ip address';

# 查看当前已有用户信息
select User,authentication_string,Host from user;

#查看用户权限信息
SHOW GRANTS FOR '用户名'@'ip地址';

        If the permission is configured and does not take effect, it is recommended to restart the mysql service:

        systemctl restart mysqld

        At this point, the configuration of the mysql service is complete. The mysql service can be used normally, but it cannot be accessed by external connections yet.

20. View the port of the mysql service:

        ps -ef|grep mysqld

        netstat -nap|grep the process number of the mysqld service

        You can see that the mysql service uses port 3306.

21. Check the firewall status:

        sudo firewall-cmd --state

22. If the firewall is running, you need to check whether port 3306 is open:

        sudo firewall-cmd --query-port=3306/tcp

23. If port 3306 is not open, you need to open the port and restart the firewall:

        sudo firewall-cmd --zone=public --add-port=port number/tcp --permanent 

        sudo firewall-cmd --reload

24. The outside world uses database tools such as Navicat or dbeaver to connect to the mysql database on the server:

         So far the mysql connection is complete.


Solution:

download:

1. First, use the wget command to download the rpm package:

        wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

Install:

2. Then install the localhostinstall command locally:

        yum localinstall mysql57-community-release-el7-8.noarch.rpm

3. Query after installation:

        yum repolist enabled | grep "mysql.*-community.*"

 4. Disable the mysql module:

        sudo yum module disable mysql

5. Modify the public key url:

        rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

6. Install mysql-community-server

        sudo yum -y install mysql-community-server

7. Start the mysql service successfully:

        systemctl start mysqld

8. View the status of the mysql service:

        systemctl status mysqld

Configuration:

9. Find the path where the file my.cnf is located:
        find / -name 'my.cnf'

10. Add the configuration to close the password verification at the end of the file my.cnf , save and exit:
        validate-password=OFF

11. Restart the mysql service
        systemctl restart mysqld

12. View the initial password according to the mysqld.log file:

        grep 'temporary password' /var/log/mysqld.log

 13. Log in to the account and change the account password (here I changed it to 123456):

        mysql -uroot -p

        Enter the initial password obtained in the previous step to log in.

14. Modify password:

        GRANT ALL PRIVILEGES ON *.* TO 'username'@'ip address' IDENTIFIED BY 'password' WITH GRANT OPTION;

15. Exit mysql and restart the mysql service

        exit

        systemctl restart mysqld

16. View the port of the mysql service:

        ps -ef|grep mysqld

        netstat -nap|grep the process number of the mysqld service

17. View the firewall status:

        sudo firewall-cmd --state

18. If the firewall is running, you need to check whether the port of the mysql service is open:

        sudo firewall-cmd --query-port=Mysql service port number/tcp

19. If the port of the mysql service is not open, you need to open the port and restart the firewall:

        sudo firewall-cmd --zone=public --add-port=port number/tcp --permanent 

        sudo firewall-cmd --reload

connect:

20. The outside world uses database tools such as Navicat or dbeaver to connect to the mysql database on the server:

        If you do not know the server ip, you can check the ip first, and then ping between the outside world and the server to ensure that the network can communicate:

        ifconfig

        Here I will directly ping the server outside to ensure that the network can communicate with each other, and basically there will be no problem with the database connection:


expand:

        Here are some basic commands for mysql service:

# 开机启动服务
systemctl enable mysqld
systemctl daemon-reload

#启动服务
systemctl start mysqld

# 重新启动服务
systemctl restart mysqld

# 查看服务当前状态
systemctl status mysqld

#停止服务
systemctl stop mysqld

# 永久性停止服务
systemctl disable mysqld

Guess you like

Origin blog.csdn.net/weixin_42585386/article/details/128560293