CentOS8下通过YUM安装mysql8.0.18
用过rpm安装和yum安装,还是觉得yum安装最方便,下面是我的安装过程(在root下运行)
- 检测系统是否自带安装 MySQL,如:
rpm -qa | grep mysql
mysql80-community-release-el8-1.noarch
mysql-community-client-8.0.18-1.el8.x86_64
mysql-community-libs-8.0.18-1.el8.x86_64
mysql-community-server-8.0.18-1.el8.x86_64
mysql-community-common-8.0.18-1.el8.x86_64
- 依次卸载安装
rpm -e mysql// 普通删除
rpm -e --nodeps mysql// 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
Mariadb也是要按照同样的方法卸载,如:(注意,不要复制粘贴运行!要根据上一步得出的结果依次删除)
sudo rpm -e --nodeps mysql80-community-release-el8-1.noarch
sudo rpm -e --nodeps mysql-community-client-8.0.18-1.el8.x86_64
sudo rpm -e --nodeps mysql-community-libs-8.0.18-1.el8.x86_64
sudo rpm -e --nodeps mysql-community-server-8.0.18-1.el8.x86_64
sudo rpm -e --nodeps mysql-community-common-8.0.18-1.el8.x86_64
- 在安装前我们需要先去官网下载 Yum 资源包,下载地址为:mysql官网

rpm -ivh mysql-community-release-el8-1.noarch.rpm
yum update
yum install mysql-server - 设置权限:
chown mysql:mysql -R /var/lib/mysql - 初始化 MySQL:
mysqld --initialize - 启动 MySQL:
systemctl start mysqld - 查看 MySQL 运行状态:
systemctl status mysqld
至此,应该是已经安装成功了,我们来验证一下
- 使用 mysqladmin 工具来获取服务器状态:
mysqladmin --version
显示:
mysqladmin Ver 8.0.18 for Linux on x86_64 (MySQL Community Server - GPL)
如果以上命令执行后未输出任何信息,说明你的Mysql未安装成功。
- Mysql安装成功后,默认的root用户密码为空
mysql -u root -p
mysql> use mysql
mysql>update user set password=password(‘123456’) where user=‘root’;
mysql>flush privileges;
mysql>exit
这时就已经设置好新的root用户密码了
- 若是开启mysql服务成功但是登陆失败
vim /etc/my.cnf
[mysqld]下加入:skip-grant-tables
即可跳密码登陆
mysql>ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘root-password’;
如果出现
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘(‘root-password’) where user=‘root’’ at line 1
只需输入:
mysql> flush privileges;
再次
mysql>ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘root-password’;
就ok了
更改完密码记得
mysql> flush privileges;
使其生效
mysql>exit
退出后记得将/etc/my.cnf中的skip-grant-tables去掉
- 登陆后可以添加用户远程登陆:
mysq8中取消了创建并授权用户这种语法了
创造一个可以远程登陆的用户:
create user 'user'@'%' identified by 'password'
更新root用户使之能远程登陆:
update user set host='%' where user='root';
创造了用户后得授权:
grant all privileges on *.* to 'user'@'%';
修改root用户密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password'; - 一些注意事项:
vim /etc/my.cnf加入
default-authentication-plugin=mysql_native_password来更改身份验证插件
bind-address=0.0.0.0使mysql可以远程ip连接navicat
(远程连接还需要打开防火墙3306端口) - 若修改密码提示
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
这是密码强度规则问题
查看密码强度规则:
mysql>SHOW VARIABLES LIKE 'validate_password%';
mysql>set global validate_password.policy=0;
mysql>flush privileges; - 更改了/etc/my.cnf一定要重启mysql
systemctl restart mysqld - 其实还有一些配置,不过是定制的,不一定适合所有机器,就不说了。
另外说一下,若是这样安装,则默认数据存储在系统盘上,更改数据存储位置参考以下博文
更改mysql8数据存储位置
有问题欢迎评论。
—4.19更新—
在虚拟机上又按这个顺序安装了一个mysql
mysqladmin Ver 8.0.17 for Linux on x86_64 (Source distribution)
发现安装后的配置文件/etc/my.cnf默认为:
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
是说配置文件放在/etc/my.cnf.d这个dir(目录)了
cd /etc/my.cnf.d && ls
client.cnf mysql-default-authentication-plugin.cnf mysql-server.cnf
挨个查看,发现里面是客户端和服务端以及默认密码识别配置文件。也就是之前的my.cnf的作用,将其拆分成了这三个,可以选择在my.cnf中配置,也可以在这三个文件中分别配置。
本文提供了一种在CentOS8系统中使用YUM命令快速安装MySQL8.0.18的方法,并详细介绍了从检测系统自带MySQL版本、卸载旧版本、下载Yum资源包到最终配置MySQL服务的全过程。

321

被折叠的 条评论
为什么被折叠?



