先下载 因为下载太慢,用国内华为云镜像(我腾讯云机器centos7.9用华为云镜像挺快)
因为安装容易报错,所以先确保防火墙关着,卸载旧mysql和自带的mariadb
查看防火墙
systemctl status firewalld
重启防火墙
systemctl start firewalld
首先关闭防火墙
systemctl stop firewalld
先查是否安装mysql
rpm -pa | grep mysql
如果有就卸载mysql
yum remove mysqlxxxxxx
先查是否安装mariadb
rpm -pa | grep mariadb
如果有就卸载
rpm -e mariadb-xxxxxx
不行就强制卸载
rpm -e --nodeps mariadb-xxxxxx
查一下是否还有msql配置文件
find / -name mysql
有就删
rm -rf /xxxxxx/xxxxxx
必须安装这四个common-libs-client-server所以分别执行如下四条命令 (我先cd /usr/local目录下了)
wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-common-8.0.26-1.el7.x86_64.rpm
wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-libs-8.0.26-1.el7.x86_64.rpm
wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-client-8.0.26-1.el7.x86_64.rpm
wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-server-8.0.26-1.el7.x86_64.rpm
下载mysql8.0.26这四个rpm文件后,rpm命令分别依次安装
rpm -ivh mysql-community-common*
rpm -ivh mysql-community-libs*
rpm -ivh mysql-community-client*
rpm -ivh mysql-community-server*
wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm
yum -y install numactl
仨依赖报错:https://blog.csdn.net/yoon0205/article/details/50605584
修改目录权限(可选操作我没用到)
chmod -R 777 /var/lib/mysql
启动服务
systemctl start mysqld
停止
systemctl stop mysqld.service
重启
service mysqld restart
查看MySQL运行状态,其中Active后面代表状态启功服务后为active (running),停止后为inactive (dead)
systemctl status mysqld.service
查看随机密码
cat /var/log/mysqld.log
命令行方式登录:输入命令,回车,输入那个随机密码
mysql -u root -p
set global validate_password.policy=0;
set global validate_password.length=4;
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'you@Pwd';
方式一:授权远程连接(我用的是方式二)
use mysql ;
select host, user, authentication_string, plugin from user;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'you@Pwd' PASSWORD EXPIRE NEVER;
方式一:将 MySQL 用户登录的加密规则修改为 mysql_native_password(我用的是方式二)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'you@Pwd';
FLUSH PRIVILEGES;
-- 切换mysql系统库
use mysql;
-- 查看指定ip登录方式host和密码加密限制使用的插件方式plugin
select user,host,plugin from user;
-- 方式二:修改%代表所有Ip(授权远程连接)
update user set host = '%' where user = 'root';
-- 方式二:默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位
update user set plugin='mysql_native_password' where user ='root';
-- 刷新生效
FLUSH PRIVILEGES;
-- 退出mysql命令行
exit;
设置自动启动(好像已经开机自启了,这俩命令可以不执行)
systemctl enable mysqld
systemctl daemon-reload
这五个安装包rpm文件我也删了
====================已经装完了,下边自己留个记录=============
-- yum查看已安装
yum list installed
yum clean all
-- 其他文章
https://www.cnblogs.com/lzc55555/p/11832562.html
https://blog.csdn.net/xinsiyu2008/article/details/110767499
https://www.cnblogs.com/zipxzf/p/10718544.html
https://www.jianshu.com/u/2e60ad18a7c1
-- 开机自启相关
systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
以firewalld.service为例
启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看开机启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed