0、更换yum源
1、打开mirror.aliyun.com,选择centos系统,点击帮助
2、执行命令:yum -y install wget
3、备份原yum文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
4、执行更换yum源的命令
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
5、更新本地缓存
yum clean all
yum makecache
1、查看系统是否自带MySQL
yum list installed | grep mysql
2、删除系统自带的MySQL及其依赖(防止冲突)
yum -y remove mysql-libs.x86_64
3、安装wget命令
yum -y install wget
4、下载MySQL的rpm源
wget -i -c https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
5、安装rpm文件
yum install mysql80-community-release-el7-3.noarch.rpm -y
6、使用yum安装MySQL
yum -y install mysql-community-server
安装遇到的错误
mysql-community-libs-8.0.32-1.el7.x86_64.rpm 的公钥尚未安装
失败的软件包是:mysql-community-libs-8.0.32-1.el7.x86_64
GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
解决办法:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023
7、启动MySQL服务,查看启动状态及是否开机启动
systemctl start mysqld.service
systemctl status mysqld.service
systemctl list-unit-files | grep enabled
8、获取mysql的临时密码
grep 'password' | /var/log/mysqld.log
9、使用临时密码登录
mysql -uroot -p
#输入密码
10、修改密码
#密码要符合mysql安全规则,否则修改不成功
ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
11、修改远程访问权限
create user 'temp_root'@'%' identified by '123456';
grant all privileges on *.* to 'temp_root'@'%' with grant option;
flush privileges;
或者修改root用户远程登陆
use mysql;
update user set host='%' where user='root';
flush privileges;
select user,host from user; #查看一下
12、设置字符集为utf-8
#在[mysqld]部分添加:
character-set-server=utf8
#在文件末尾新增[client]段,并在[client]段添加:
default-character-set=utf8