Resolved: The GPG key for the source "MySQL 5.7 Community Server" is installed, but does not apply to this package. Please check whether the source public key URL is configured correctly and error: `ERROR 1045 (28000

Article directory

Problem Description

  1. An error occurred when installing mysql on the server. Simply record the solution.

    "MySQL 5.7 Community Server" 的 GPG 密钥已安装,但是不适用于此软件包。请检查源的公钥 URL 是否配置正确。
    
    
     失败的软件包是:mysql-community-client-5.7.40-1.el7.x86_64
     GPG  密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
  2. implement:rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

    [root@localhost mysql]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
    [root@localhost mysql]# yum install mysql-server
    已加载插件:fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
    正在解决依赖关系
    --> 正在检查事务
    ---> 软件包 mysql-community-server.x86_64.0.5.7.40-1.el7 将被 安装
    --> 正在处理依赖关系 mysql-community-common(x86-64) = 5.7.40-1.el7,它被软件包 mysql-community-server-5.7.40-1.el7.x86_64 需要
    --> 正在处理依赖关系 mysql-community-client(x86-64) >= 5.7.9,它被软件包 mysql-community-server-5.7.40-1.el7.x86_64 需要
    --> 正在检查事务
    ---> 软件包 mysql-community-client.x86_64.0.5.7.40-1.el7 将被 安装
    --> 正在处理依赖关系 mysql-community-libs(x86-64) >= 5.7.9,它被软件包 mysql-community-client-5.7.40-1.el7.x86_64 需要
    ---> 软件包 mysql-community-common.x86_64.0.5.7.40-1.el7 将被 安装
    --> 正在检查事务
    ---> 软件包 mariadb-libs.x86_64.1.5.5.60-1.el7_5 将被 取代
    --> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-7.el7.x86_64 需要
    --> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-7.el7.x86_64 需要
    ---> 软件包 mysql-community-libs.x86_64.0.5.7.40-1.el7 将被 舍弃
    --> 正在检查事务
    ---> 软件包 mysql-community-libs-compat.x86_64.0.5.7.40-1.el7 将被 舍弃
    --> 解决依赖关系完成
    
    依赖关系解决
    
  3. Start the mysql service and check the running status

    [root@localhost mysql]# service mysqld start
    Redirecting to /bin/systemctl start mysqld.service
    [root@localhost mysql]# systemctl status mysqld
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: active (running) since 四 2022-10-13 05:42:37 UTC; 7s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
      Process: 10239 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
      Process: 10181 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
     Main PID: 10242 (mysqld)
        Tasks: 27
       CGroup: /system.slice/mysqld.service
               └─10242 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
    
    1013 05:42:26 localhost.localdomain systemd[1]: Starting MySQL Server...
    1013 05:42:37 localhost.localdomain systemd[1]: Started MySQL Server.
    
  4. View mysql initial password:grep 'A temporary password' /var/log/mysqld.log

    [root@localhost mysql]# grep 'A temporary password' /var/log/mysqld.log
    2022-10-13T05:42:35.302480Z 1 [Note] A temporary password is generated for root@localhost: !oCdG%3prdP1
    
    1. Use the initial password to log in and get an error:ERROR 1045 (28000): Access denied for user 'root'@'localhost'
    2. Modify /etc/my.cnfthe file and add it at the endskip-grant-tables
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    
    [mysqld]
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    skip-grant-tables
    
  5. Then restart the database: systemctl restart mysqld

    [root@localhost mysql]# systemctl restart mysqld
    
  6. You can log in directly without password:

    [root@localhost mysql]# mysql -uroot -p 
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.7.40 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2022, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> 
    
  7. Before changing the root password, refresh the permissions first, and then change the root password.

    mysql> flush privileges;
    Query OK, 0 rows affected (0.01 sec)
    mysql> alter user 'root'@'localhost' identified by '123456';
    Query OK, 0 rows affected (0.00 sec)
    

Guess you like

Origin blog.csdn.net/qq_43408367/article/details/127299840
Recommended