CentOS6.8 yum 安装MySQL5.7.16

技术杂谈 266 2017-09-28 13:56

CentOS6.8 yum 安装MySQL5.7.16

 

Allen Lee

1、下载mysqlrepo

wget http://repo.mysql.com//mysql57-community-release-el6-9.noarch.rpm

2、安装mysql57-community-release-el6-9.noarch.rpm

rpm -ivh mysql57-community-release-el6-9.noarch.rpm

安装这个包后,会获得两个mysqlyum repo源:

/etc/yum.repos.d/mysql-community.repo

/etc/yum.repos.d/mysql-community-source.repo

 

3. 安装mysql

yum install mysql-community-server

根据步骤安装就可以了,不过安装完成后,密码动态生成,需要重置密码。

查看my.cnf 文件的log日志

查看/var/log/mysqld.log文件搜索:temporary password 找到初始密码

4. 重置密码

 

重置密码前,首先要登录

mysql -uroot -p

输入初始密码dtZzoq_:t7wN登陆

登录时有可能报这样的错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:

chown -R allen:allen /var/lib/mysql

然后,重启服务:

$ service mysqld restart 或者 /etc/init.d/mysqld restart

接下来登录重置密码:

mysql > set password = password('!QAZ2wsx?');

 

MySQL5.7.16以后登陆成功后首先要设置新密码否则无法进行任何操作,而且密码的强度也做了设定如果密码强度不够数据库会报错

这里引用官方文档说明:

If the validate_password plugin is not installed, the validate_password_xxx system variables are not available, passwords in statements are not checked, and the VALIDATE_PASSWORD_STRENGTH() function always returns 0. For example, without the plugin installed, accounts can be assigned passwords shorter than 8 characters.

Assuming that the validate_password plugin is installed, it implements three levels of password checking: LOW, MEDIUM, and STRONG. The default is MEDIUM; to change this, modify the value of validate_password_policy. The policies implement increasingly strict password tests. The following descriptions refer to default parameter values, which can be modified by changing the appropriate system variables.

LOW policy tests password length only. Passwords must be at least 8 characters long.

MEDIUM policy adds the conditions that passwords must contain at least 1 numeric character, 1 lowercase character, 1 uppercase character, and 1 special (nonalphanumeric) character.

STRONG policy adds the condition that password substrings of length 4 or longer must not match words in the dictionary file, if one has been specified.

In addition, as of MySQL 5.7.15, the validate_password plugin supports the capability of rejecting passwords that match the user name part of the effective user account for the current session, either forward or in reverse. To enable control over this capability, the plugin exposes a validate_password_check_user_name system variable. By default, this variable is disabled.

 

文档所说MySQL5.7.15后数据库安装了validate_password插件如果插件没有启用则可以设置低于8位数的密码启用之后密码长度不得低于8位数。

密码强度分为3个等级(默认中等):

1、低级 只是测试密码长度必须至少有8个字符长。

2、中等 在低等的基础上密码必须至少包含1个数字字符的情况下,1个小写字母,大写字      母和1个特殊字符(非字母数字)。

3、在中等之上长度增加4位,并且不能为字典中存在的密码或操作系统用户的密码

除此之外validate_password插件支持拒绝为当前会话的有效用户帐户的用户名称匹配密码的能力,无论是正向或反向。为了方便设置,插件绑定变量为validate_password_check_user_name系统变量。默认情况下,这个变量是禁用的。

 

 

5. 开放3306端口

vim /etc/sysconfig/iptables

添加以下内容:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

保存后重启防火墙:

service iptables restart

6. 创建普通用户并授权

 

示例(使用root用户登录,创建 allen数据库):

CREATE DATABASE allen DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

 

mysql > use mysql;

#创建allen用户与密码并设置为从安装mysql服务的机器本地访问

mysql > grant all on allen.* to 'allen'@'localhost'

            identified by '!QAZ2wsx?';

#设置allen用户与密码,并从任何机器都可以访问mysql

mysql > grant all on allen.* to 'allen'@'%' identified by '!QAZ2wsx?';

mysql > flush privileges;            #刷新才会生效

现在就可以从客户机连接mysql服务器了

 

修改MySQL 默认数据库字符编码

mysql > show variables like 'char%';

这里已经改过具体方式为在my.cnf文件的[mysqld]之下添加如下内容

character_set_server=utf8

init_connect='SET NAMES utf8'

OK 大功告成 !!!!

 

文章评论