本文将记录一下 centos8 下载 mysql8 的安装命令,防止下一次安装的时候还需要查询相关资料。🤣
下载 mysql
# 查看是否有 mysql,如果有则需要卸载
yum list installed mysql |grep mysql
# or
rpm -qa |grep mysql# 查看是否有 mysql 残余文件
find / -name mysql# 如果有可能会出现
/var/lib/selinux/targeted/active/modules/100/mysql
/usr/share/bash-completion/completions/mysql
/usr/share/selinux/targeted/default/active/modules/100/mysql# 如果有残余文件需要使用 rm -rf 删除
rm -rf xxx# 下载 mysql 安装包
wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpmyum install mysql80-community-release-el8-1.noarch.rpm -y# 查看是否安装成功--数据源
yum repolist enabled | grep "mysql.*-community.*"# 将出现
mysql-connectors-community MySQL Connectors Community
mysql-tools-community MySQL Tools Community
mysql80-community MySQL 8.0 Community Server# 禁用 centos8 自带的 mysql 模块
yum module disable mysql -y# 安装 mysql
yum install mysql-community-server -y --nogpgcheck# 启动 mysql
/bin/systemctl start mysqld.service# 查看是否启动成功
service msyqld status# 启动成功将出现---active 就是启动成功了!
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: active (running) since Tue 2023-11-28 16:12:42 CST; 11min agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlProcess: 3468 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)Main PID: 3539 (mysqld)Status: "Server is operational"Tasks: 38 (limit: 4636)Memory: 370.5MCGroup: /system.slice/mysqld.service└─3539 /usr/sbin/mysqld11月 28 16:12:34 yuanxin.linux.com systemd[1]: Starting MySQL Server...
11月 28 16:12:42 yuanxin.linux.com systemd[1]: Started MySQL Server.
mysql 操作
# 查看随机密码
grep 'temporary password' /var/log/mysqld.log
# 密码为 host 后面的字符串
2023-11-28T08:12:38.557060Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ex-k1issXX%L# 登录 mysql
mysql -u root -p# 先修改一个满足 mysql 策略的密码
alter user 'root'@'localhost' identified by 'Root_21root';# 查看密码策略
show variables like 'validate_password%';# 设置
set global validate_password.length=1;# 设置
set global validate_password.policy=0;# 修改密码--- 123456 是自己想要设置的登录密码
alter user 'root'@'localhost' identified by '123456';
开启远程 mysql 服务
# 创建权限记录
create user 'root'@'%' identified by '123456';# 授权
grant all privileges on *.* to 'root'@'%' with grant option;
开启以后,可以使用 Navicat 创建一个 MySQL 连接,输入虚拟机 ip 地址和刚才设置的密码应该就可以访问了。在这里如果发生报错的话就关闭本机的防火墙大概率就好了。