首先是 yum install mysql-community-server问题的解决,我采用的是卸载重装的办法,快速
卸载方法:
1.快速删除
yum remove mysql mysql-server mysql-libs mysql-server
2.查找残留文件
rpm -qa | grep -i mysql
将查询出来的文件逐个删除,如:
yum remove mysql-community-common-5.7.20-1.el6.x86_64
4.查找残留目录
whereis mysql
5.逐条删除目录,如:
rm –rf /usr/lib64/mysql
上述做完后,最好重新查询相关内容,防止漏删
重新安装,这里全都是复制原文内容,尊重作者,特此说明
一:去官网查看最新安装包
https://dev.mysql.com/downloads/repo/yum/
查看Linux系统版本,下载对应的安装包:
cat /var/issue
or
cat /etc/redhat-release
确定是Linux6、linux7、linux8
二:下载MySQL源安装包
wget http://dev.mysql.com/get/mysql57-community-release-XXXXX.noarch.rpm
根据系统版本下载对应的rpm文件。
安装MySql源
yum -y install mysql57-community-release-XXXXX.noarch.rpm
安装下载的源文件,注意名字与下载的文件名一致。
查看一下安装效果
yum repolist enabled | grep mysql.*
三:安装MySQL服务器
yum install mysql-community-server
中间会弹出是与否的选择,选择y即可,然后耐心等待吧。。。。。。。
四:启动MySQL服务
systemctl start mysqld.service
运行一下命令查看一下运行状态
systemctl status mysqld.service
========================================
安装错误解决:
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-client-5.7.39-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
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.
Failing package is: mysql-community-client-5.7.39-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
原因:官方 MySQL 存储库的 GPG 密钥已过期,无法安装或更新 MySQL 包。为 “MySQL 5.7 社区服务器” 存储库列出的 GPG 密钥已经安装,但它们对于这个包不正确
解决:可以在运行安装程序之前导入2022年的密钥:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
========================================
五:初始化数据库密码
查看一下初始密码
grep "password" /var/log/mysqld.log
默认登录密码:
2019-06-10T10:17:45.177897Z 1 [Note] A temporary password is generated for root@localhost: eyuE933f6t!Z
登录
mysql -uroot -p
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '****************';
mysql默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误
六:数据库授权
数据库没有授权,只支持localhost本地访问
mysql>GRANT ALL PRIVILEGES ON . TO ‘root’@‘%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;
//远程连接数据库的时候需要输入用户名和密码
用户名:root
密码:123456
指点ip:%代表所有Ip,此处也可以输入Ip来指定Ip
输入后使修改生效还需要下面的语句
mysql>FLUSH PRIVILEGES;
也可以通过修改表来实现远程:
mysql -u root -p
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> select host, user from user;
七:设置自动启动
systemctl enable mysqld
systemctl daemon-reload
8 防火墙设置
参考这个
https://blog.csdn.net/hantoy/article/details/107057691