安装环境:阿里云服务器 + CentOS7.3
测试工具:Navicat for MySQL
- 参考博客:https://blog.csdn.net/qq_38417808/article/details/81291588
1.更新 yum mysql5.7 源
- #wget http://repo.mysql.com/mysql57-community-release-el6-8.noarch.rpm
- #rpm -ivh mysql57-community-release-el6-8.noarch.rpm
2.yum mysql 源配置
- 禁用MySQL5.6的源:#yum-config-manager --disable mysql56-community
- 启用MySQL5.7的源:#
yum-config-manager --
enable
mysql57-community-dmr
3.查看 mysql install list
-
#yum repolist enabled |
grep
mysql
4.安装 mysql
- #yum install mysql-community-server
这里会报错:
,缺少libsasl2.so.2()(64bit)
解决办法:
- 修改 yum mysql 源:#vim /etc/yum.repos.d/mysql-community.repo
[mysql57-community]
name=MySQL 5.7 Community Server
## 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
- 再次安装 mysql: #yum install mysql-community-server
5.配置 mysql 字符集
- #vim /etc/my.cnf,在文件末尾加上:character-set-server=utf8
6.启动 mysql 服务
- #service mysqld start
- 停止 mysql 服务:#service mysqld stop
7.查询首次安装随机密码
- #grep 'password' /var/log/mysqld.log |head -n 1
8.登陆数据库
- #mysql –u root –p,输入上面查询的密码登陆
9.修改 root 密码
- 首次登陆进去会出现提示:
You must reset your password using ALTER USER statement before executing this statement.
(在执行此语句之前,必须使用ALTE USER语句重设密码。)
- 个人学习使用,所以密码设为:root,
alter user user() identified by "root";
但是会报 Your password does not satisfy the current policy requirements.(您的密码不符合当前的策略要求。)
- 首先,修改 mysql5.7 的默认密码策略:
1. set global validate_password_policy=0;(密码长度符合即可)
2. set global validate_password_length=1;(修改密码默认长度为最小值,即4位)
- 再次设置密码:alter user user() identified by "root";
- exit; 退出,使用新密码登陆 mysql
10.远程访问
- 防火墙设置 mysql 端口白名单:#vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
重启防火墙,#service iptables restart
- 登陆 mysql 创建远程访问用户’root',密码为’root’:create user 'root'@'%' identified by 'root';
查询 mysql 库的 user 表:select host, user from user;
- 授权:grant all privileges on *.* to 'root'@'%';
- 测试