0


MySQL常见问题解决和自动化安装脚本

在这里插入图片描述
在这里插入图片描述

常见问题

MySQL密码正确但无法登录的情况

这种情况一般都是因为缓存,使用

mysql -u root -p123456

直到成功登陆为止,并且进入之后重新修改密码,多次重复修改密码的命令并且再一次清除缓存后退出。

ALTERUSER'root'@'localhost' IDENTIFIED WITH mysql_native_password BY'123456';
flush privileges;

MySQL安装的GPG密钥问题

前言

在MySQL安装的过程中,我们出现了不能通过YUM安装的MySQL的问题,YUM工具警告说安装包的GPG密钥无效或未安装,这意味着不能验证该包的真实性和完整性。系统尝试从指定的本地路径检索密钥,但没有找到有效的密钥与包匹配。

具体错误
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-8.0.36-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

The GPG keys listed for the "MySQL 8.0 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.

 Failing package is: mysql-community-client-8.0.36-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
解决方式
yum install net-tools -y# 检查和安装网络工具包
yum list installed |grep mysql # 检查已安装的MySQL安装包rpm-e--nodeps mysql80-community-release-el7-8.noarch # 强制删除指定的MySQL仓库包,不检查依赖。rm-rf /etc/my.cnf # 删除MySQL的主配置文件。rpm--import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 # 导入MySQL的GPG公钥,用于验证软件包。rpm-Uvh https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm# 安装新的MySQL仓库配置包。
yum -yinstall mysql-community-server# 安装MySQL服务器及其依赖。

此处出现了GPG的错误,我们需要通过绕过GPG的检查来实现安装

yum -yinstall mysql-community-server  --nogpgcheck# 忽略GPG密钥检查,重新安装
systemctl start mysqld && systemctl enable mysqld # 启动MySQL服务并设置为开机启动。
systemctl status mysqld # 检查MySQL服务状态,确认服务已经运行grep'temporary password' /var/log/mysqld.log # 获取随机密码并登录
ALTERUSER'root'@'localhost' IDENTIFIED WITH mysql_native_password BY'123456';setglobal validate_password.policy=0;ALTERUSERUSER() IDENTIFIED BY'wingkin45@A.';setglobal validate_password.policy=0;setglobal validate_password.length=4;ALTERUSER'root'@'%' IDENTIFIED WITH mysql_native_password BY'123456';
flush privileges;

MySQL自动化安装脚本

echo"INFO : BEGIN INSTALLING MYSQL8 ..."#检查mysql服务版本,若存在Mysql8,直接退出me=`ps -ef|grep mysqld|wc-l`if[$me-eq2];thenme=`systemctl status mysqld|grep Docs|awk -F: '{print $NF}'`if[$?-eq0-a"$me"=="mysql(8)"];thenecho"INFO : MYSQL8 FOUND "exit0fi#若存在旧版本的mysql,且服务处于启动状态
        systemctl status mysqld|grep"active (running)"if[$?-eq0];then
                systemctl stop mysqld
                echo"INFO : OLD MYSQL SERVICE FOUND BUT STOPPED"fifi#若存在旧版本的残留,则直接卸载names=`rpm -qa|grep mysql`fornamein$names;do
        yum -y remove $name1>/dev/null 2>&1echo"INFO : OLD MYSQL RESOURCE [ $name ] FOUND AND REMOVED"done#rpm 安装mysql8src=$1if[[!-e$src||!-f$src]];thenecho"ERROR : PLEASE PROVIDE MYSQL8 RPM FILE "exit1fiif[[!"$src"=~ mysql8.*\.rpm$ ]];thenecho"ERROR : RPM PACKAGE OR NOT MYSQL8"exit1firpm-ivh$src1>/dev/null 2>&1if[$?-eq0];thenecho"INFO : SUCCESS TO RPM INSTALL MYSQL8"elseecho"ERROR : FAIL TO RPM INSTALL MYSQL8"exit2fi# yum 安装mysql8服务
yum -yinstall mysql-community-server --nogpgcheck1>/dev/null 2>&1if[$?-eq0];thenecho"INFO : SUCCESS TO YUM MYSQL8 SERVICE"elseecho"ERROR : FAIL TO YUM MYSQL8 SERVICE"exit3fi#检查服务是否已启动,若未启动则启动me=`systemctl status mysqld|grep"active (running)"`if[$?-ne0];then
        systemctl start mysqld
fiecho"INFO : MYSQL8 SERVICE STARTED"echo"INFO : FINISH INSTALL MYSQL8"unset me
unset names
unset src
标签: MySQL MySQL安装

本文转载自: https://blog.csdn.net/m0_74120525/article/details/138317910
版权归原作者 Byyyi耀 所有, 如有侵权,请联系我们删除。

“MySQL常见问题解决和自动化安装脚本”的评论:

还没有评论