文章目录
问题描述
-
服务器上安装mysql时出现了报错,简单记录下解决方案
源 "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
-
执行:
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, langpacksLoading 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 将被 舍弃--> 解决依赖关系完成依赖关系解决
-
启动mysql服务并查看运行状态
[root@localhost mysql]# service mysqld startRedirecting 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.pid10月 13 05:42:26 localhost.localdomain systemd[1]: Starting MySQL Server...10月 13 05:42:37 localhost.localdomain systemd[1]: Started MySQL Server.
-
查看mysql初始密码:
grep 'A temporary password' /var/log/mysqld.log
[root@localhost mysql]# grep 'A temporary password' /var/log/mysqld.log2022-10-13T05:42:35.302480Z 1 [Note] A temporary password is generated for root@localhost: !oCdG%3prdP1
- 使用初始密码进行登录,报错:
ERROR 1045 (28000): Access denied for user 'root'@'localhost'
- 修改
/etc/my.cnf
文件,在最后加入skip-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 = 2Mdatadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pidskip-grant-tables
- 使用初始密码进行登录,报错:
-
然后重启数据库:systemctl restart mysqld
[root@localhost mysql]# systemctl restart mysqld
-
可以使用无密码直接登录:
[root@localhost mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
-
修改root 密码前,先刷新一下权限,然后再修改root密码
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)
来源地址:https://blog.csdn.net/qq_43408367/article/details/127299840