CentOS 6.x 安装MySQL5.7
说明:实验环境实在CentOS 6.5 mini下完成的。
1、如果使用yum/apt-get 安装binary package,必须保证本地原有的旧版本MySQL被卸载0,
需要检查的地方有如下:
# rpm -qa | grep mysql*
下面两个位置也要检查,如果有,删除
/var/lib/mysql
/etc/my.cnf
2、去oracle下载 5.7yum源仓库地址rpm包并设置(这个操作不会影响使用安装国内的阿里/网易yum源)
地址:https://dev.mysql.com/downloads/repo/yum/
# rpm -ivh mysql57-community-release-el6-11.noarch.rpm
# vim mysql57-community.repo
激活mysql57-Community Server enable=1
# yum clean all
# yum makecache
# yum repolist enabled | grep "mysql.*-community.*"
会看到如下信息:
mysql-connectors-community MySQL Connectors Community 42
mysql-tools-community MySQL Tools Community 53
mysql57-community MySQL 5.7 Community Server 219
3、安装MySQL5.7
# yum install mysql-community-server
4、启动MySQL
# service mysqld start
# chkconfig mysqld on
5、修改密码
# grep 'temporary password' /var/log/mysqld.log 找出临时密码
2017-12-10T14:28:49.980116Z 1 [Note] A temporary password is generated for root@localhost: Oe4jkHHr#hMj
# mysql -uroot -p"Oe4jkHHr#hMj" 登录数据库
修改密码:
mysql> set password for 'root'@'localhost' = password('newpwd');
如果发现报错,因为密码过于简单,可以这样做绕过去:
1、临时去掉这个策略:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=4;
重启数据库后会重新恢复
mysql> show variables like "%validate_password%";
validate_password_policy:密码策略,默认为MEDIUM策略, 0代表LOW,1代表MEDIUM, 2代表STRONG
validate_password_dictionary_file:密码策略文件,策略为STRONG才需要
validate_password_length:密码最少长度,至少4个
validate_password_mixed_case_count:大小写字符长度,至少1个
validate_password_number_count :数字至少1个
validate_password_special_char_count:特殊字符至少1个
2、永久修改密码策略:
在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略
# 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
validate_password_policy=0
如果不需要密码策略,添加my.cnf文件中添加如下配置禁用即可:
validate_password = off
重新启动mysql服务使配置生效:
service mysqld restart
6、添加远程登录用户,或根据业务来修改
mysql> select host, user from mysql.user;
mysql> grant all privileges on *.* to 'root'@'%' identified by '密码' with grant option;
7、修改MySQL编码
# vim /etc/my.cnf
[mysqld]
character_set_server=utf8
[client]
default-character-set=utf8
# service mysqld restart
mysql> show variables like "%character%";