赞
踩
主要参考链接 教程
su root
mariadb是CentOS自带的数据库,装MySQL前要先卸载,
但不一定每一个CentOS镜像都有自带mariadb数据库,如果查到没有则直接跳过此步
#查询mariadb数据库软件包
rpm -qa|grep mari
#删除软件包
rpm -e --nodeps marisa-0.2.4-4.el7.x86_64 #包名用你自己查询到的
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64 #包名用你自己查询到的
#CentOS8 mysql8 rpm源
wget -c https://dev.mysql.com/get/mysql80-community-release-el8-5.noarch.rpm
#CentOS7 mysql8 rpm源
wget -c https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
#CentOS6 mysql8 rpm源
wget -c https://dev.mysql.com/get/mysql80-community-release-el6-7.noarch.rpm
#如果wget命令无效,先执行下面这个命令安装wget
yum -y install wget
#CentOS8 安装mysql8
rpm -ivh mysql80-community-release-el8-5.noarch.rpm
#CentOS7 安装mysql8
rpm -ivh mysql80-community-release-el7-7.noarch.rpm
#CentOS6 安装mysql8
rpm -ivh mysql80-community-release-el6-7.noarch.rpm
#安装mysql服务
yum -y install mysql-server
yum -y install mysql-server
问题一:比如说我今天出现这个错误:
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022 检索密钥
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥
源 "MySQL 8.0 Community Server" 的 GPG 密钥已安装,但是不适用于此软件包。请检查源的公钥 URL 是否配置正确。
失败的软件包是:mysql-community-client-8.0.36-1.el7.x86_64
GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022, file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
怎么解决了?
#执行下面的代码就行了,把 mysql80-community-release-el7-7.noarch.rpm 换成自己的继续了
[root@Hadoop100 software]# rpm --checksig mysql80-community-release-el7-7.noarch.rpm
mysql80-community-release-el7-7.noarch.rpm: rsa sha1 (md5) pgp md5 确定
要是上面还不能解决的话
[root@Hadoop100 software]# gpg --export -a 3a79bd29 > 3a79bd29.asc
[root@Hadoop100 software]# rpm --import 3a79bd29.asc
[root@Hadoop100 software]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
[root@Hadoop100 software]# rpm --checksig mysql80-community-release-el7-7.noarch.rpm
#只要出现下面这一行结果就行
mysql80-community-release-el7-7.noarch.rpm: rsa sha1 (md5) pgp md5 确定
#最后在执行安装msyql服务操作操作
[root@Hadoop100 software]# yum -y install mysql-server
问题二:安装有出现了问题
警告:/var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022 检索密钥
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥
源 "MySQL 8.0 Community Server" 的 GPG 密钥已安装,但是不适用于此软件包。请检查源的公钥 URL 是否配置正确。
失败的软件包是:mysql-community-client-8.0.36-1.el7.x86_64
GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022, file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
解决办法
[root@Hadoop100 software]# sudo yum install mysql-server --nogpgcheck
#查看mysql运行状态
systemctl status mysqld
#启动mysql
systemctl start mysqld
#停止mysql
systemctl stop mysqld
#重启mysql
systemctl restart mysqld
#开启mysql开机自启动
systemctl enable mysqld
#关闭mysql开机自启动
systemctl disable mysqld
//获取MySQL临时密码
grep 'temporary password' /var/log/mysqld.log
2.4.2 执行命令mysql -uroot -p登录MySQL(密码是上面获取的临时密码)
//登录mysql
mysql -uroot -p
例如:下面的截图,其中 -uroot是要连在一块的
你要是下面的(1)(2)(3)(4)操作失败,直接试试我这个里面的
#先随意更改一个数据库密码,后再改简单的密码,不然不能下一步操作 mysql> alter user root@localhost identified by 'Y1h2e3d4u5!'; Query OK, 0 rows affected (0.00 sec) #设置密码策略,简单的 mysql> set global validate_password.policy=LOW; Query OK, 0 rows affected (0.00 sec) #设置密码长度 mysql> set global validate_password.length=4; Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password.mixed_case_count=0; Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password.number_count=0; Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password.special_char_count=0; Query OK, 0 rows affected (0.00 sec) #重新修改root密码 mysql> alter user root@localhost identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> create user 'root'@'%' identified by '123456'; Query OK, 0 rows affected (0.00 sec) #刷新缓存 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) #设置远程登录链接,任何用户度可以连接该数据库服务器 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; Query OK, 0 rows affected (0.01 sec) #设置远程服务器连接密码 mysql> ALTER USER 'root'@'%' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.00 sec) #最后重启数据库服务器 systemctl restart mysqld
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
#注意 此处BY 后面的root是修改后的密码
mysql> flush privileges;
mysql> grant all privileges on *.* to root@'%' identified by 'root';
mysql> flush privileges;
systemctl restart mysqld
解决办法:
运行命令
[root@localhost ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
重新安装
[root@localhost ~]# yum -y install mysql-server
E45:已设定选项 'readonly' (请加 ! 强制执行)
原因分析: 这是因为当前的用户的权限不够
解决办法:执行代码的命令前面加上 sudo
或者切换当前系统的用户 直接 su root
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。