Centos7.9系统yum安装mysql5.7版本

本文档介绍了在CentOS7.9系统中如何安装MySQL,解决安装过程中遇到的GPG验证错误,以及配置MySQL的用户权限。包括通过--nogpgcheck参数跳过验证,启动服务,查看版本,设置临时密码,修改root密码,授权新用户以及调整密码策略。此外,还展示了如何允许远程访问以及设置字符集。
摘要由CSDN通过智能技术生成

CentOS中默认安装有MariaDB,安装mysql会覆盖掉MariaDB;

环境说明:

centos7.9 64位系统

下载mysql社区版本源并安装

wget https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum install -y mysql57-community-release-el7-10.noarch.rpm

安装之后 #yum repolist 会更新mysql repo源

yum安装mysql server

yum install -y mysql-community-server

出现如下错误

Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


The GPG keys listed for the "MySQL 5.7 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.

GPG对于包的源key的验证没有通过

解决办法

在yum install 版本后面加上 --nogpgcheck,即可绕过GPG验证成功安装。

yum install mysql-community-server --nogpgcheck

启动mysql服务

systemctl start mysqld

查看版本

mysql --version

mysql  Ver 14.14 Distrib 5.7.38, for Linux (x86_64) using  EditLine wrapper

Mysql的使用和授权

查找mysql的登陆临时密码

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

使用临时密码登陆mysql,登陆后第一件事需要修改密码,必须符合密码复杂度 大小写字母数字加特殊字符组合;

mysql -uroot -p
mysql> alter user root@'localhost' identified by '密码';

测试1:创建一个新用户,只能从本地访问mysql,只授权mysql数据库下的所有表的select权限;

mysql> grant select on mysql.* to guo@localhost identified by '密码';

使用新用户登陆并测试删除表,提示没有权限;

mysql -u guo -h localhost -p
mysql> use mysql;
mysql> drop table user;
ERROR 1142 (42000): DROP command denied to user 'guo'@'localhost' for table 'user'

测试2:

授权star用户限制只能从172.16.0.21 地址访问,拥有最高权限,可以访问所有库所有表;

mysql> grant all privileges on *.* to 'star'@'172.16.0.21' identified by '密码';
mysql> flush privileges;
mysql> select user,host from mysql.user;
+---------------+--------------+
| user          | host         |
+---------------+--------------+
| star          | 172.16.0.21 |
| mysql.session | localhost    |
| mysql.sys     | localhost    |
| root          | localhost    |
| guo           | localhost    |
+---------------+--------------+

使用新用户star本地登陆,提示访问拒绝,使用密码正确;

mysql -ustar -p
Enter password:
ERROR 1045 (28000): Access denied for user 'star'@'localhost' (using password: YES)

登陆172.16.0.21 服务器指定 -h mysql服务器IP访问成功(只安装mysql client客户端即可)

wget https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum install -y mysql57-community-release-el7-10.noarch.rpm
yum install -y mysql-community-client
mysql -ustar -p -h 172.16.0.22

密码策略

在命令行模式使用-e  参数,查看密码执行策略:

修改密码策略级别:

mysql -uroot -p -e "set global validate_password_policy=LOW;"

修改密码策略长度:

mysql -uroot -p -e "set global validate_password_length=6;"

编辑mysql配置文件,添加以下代码,设置字符集为utf8

vi /etc/my.cnf
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci

重启mysql生效

systemctl restart mysqld

再次登录数据库查看status状态,已更改为utf8

mysql -uroot -p

设置root远程访问,生产环境请不要这样使用,非常危险

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

花开花落的个人博客

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值