MYSQL5.7详细安装步骤
准备阶段
更换yum源
1、打开 mirrors.aliyun.com,选择centos的系统,点击帮助
2、执行命令:yum install wget -y
3、改变某些文件的名称
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
4、执行更换yum源的命令
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.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 install wget -y
4、给CentOS添加rpm源,并且选择较新的源
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
如果提示无法建立SSL连接,追加命令
wget https://repo.mysql.com//mysql-community-release-el6-5.noarch.rpm --no-check-certificate
5、安装下载好的rpm文件
yum install mysql-community-release-el6-5.noarch.rpm -y
6、安装成功之后,会在/etc/yum.repos.d/文件夹下增加两个文件
7、修改mysql-community.repo文件
原文件:
修改之后:
如果报错 需要:libsasl2.so.2()(64bit),则继续修改 更换baseurl
[mysql57-community-dmr]
name=MySQL 5.7 Community Server Development Milestone Release
#baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
8、使用yum安装mysql
yum install mysql-community-server -y
9、启动mysql服务并设置开机启动
#启动之前需要生成临时密码,需要用到证书,可能证书过期,需要进行更新操作
yum update -y
#启动mysql服务
service mysqld start
#设置mysql开机启动
chkconfig mysqld on
10、获取mysql的临时密码
grep "password" /var/log/mysqld.log
nXirXd7g*XTV
11、使用临时密码登录
mysql -uroot -p
#输入密码
12、修改密码
set global validate_password_policy=0;
set global validate_password_length=1;
ALTER USER 'root'@'localhost' IDENTIFIED BY '123123123';
13、修改远程访问权限
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
flush privileges;
如果出现报错
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
设置密码等级为low,再次尝试
set global validate_password_policy=LOW;
14、设置字符集为utf-8
vi /etc/my.cnf
#在[mysqld]部分添加:
character-set-server=utf8
#在文件末尾新增[client]段,并在[client]段添加:
default-character-set=utf8
service mysql restart
service mysqld restart
15关闭防火墙
查看防火墙状态
firewall-cmd --state
停止firewall
systemctl stop firewalld.service
禁止firewall开机启动
systemctl disable firewalld.service