天天看点

CentOS7下安装MySQL5.7安装与配置(YUM)

安装环境:CentOS7 64位,MySQL5.7

<code># 下载mysql源安装包</code>

<code>shell&gt; wget http:</code><code>//dev</code><code>.mysql.com</code><code>/get/mysql57-community-release-el7-8</code><code>.noarch.rpm  </code>

<code># 安装mysql源 </code>

<code>shell&gt; yum localinstall mysql57-community-release-el7-8.noarch.rpm</code>

检查mysql源是否安装成功

<code>shell&gt; yum repolist enabled | </code><code>grep</code> <code>"mysql.*-community.*"</code>

<code>shell&gt; yum </code><code>install</code> <code>mysql-community-server</code>

<code>shell&gt; systemctl start mysqld</code>

查看MySQL的启动状态

<code>shell&gt; systemctl status mysqld</code>

<code>shell&gt; systemctl </code><code>enable</code> <code>mysqld </code>

<code>shell&gt; systemctl daemon-reload</code>

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

<code>shell&gt; </code><code>grep</code> <code>'temporary password'</code> <code>/var/log/mysqld</code><code>.log</code>

<code>shell&gt; mysql -uroot -pmysql&gt; ALTER USER </code><code>'root'</code><code>@</code><code>'localhost'</code> <code>IDENTIFIED BY </code><code>'MyNewPass4!'</code><code>;</code>

或者

<code>mysql&gt; </code><code>set</code> <code>password </code><code>for</code> <code>'root'</code><code>@</code><code>'localhost'</code><code>=password(</code><code>'MyNewPass4!'</code><code>);</code>

注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示: 

通过msyql环境变量可以查看密码策略的相关信息:

<code>mysql&gt; show variables like </code><code>'%password%'</code><code>;</code>

  validate_password_policy:密码策略,默认为MEDIUM策略  validate_password_dictionary_file:密码策略文件,策略为STRONG才需要  validate_password_length:密码最少长度  validate_password_mixed_case_count:大小写字符长度,至少1个  validate_password_number_count :数字至少1个  validate_password_special_char_count:特殊字符至少1个  上述参数是默认策略MEDIUM的密码检查规则。

共有以下几种密码策略:

策略

检查规则

0 or LOW

Length

1 or MEDIUM

Length; numeric, lowercase/uppercase, and special characters

2 or STRONG

Length; numeric, lowercase/uppercase, and special characters; dictionary file

在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略

<code># 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件</code>

<code>validate_password_policy=0</code>

如果不需要密码策略,添加my.cnf文件中添加如下配置禁用即可:

<code>validate_password = off</code>

重新启动mysql服务使配置生效:

<code>systemctl restart mysqld</code>

默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:

<code>mysql&gt; GRANT ALL PRIVILEGES ON *.* TO </code><code>'USERNAME'</code><code>@</code><code>'%'</code> <code>IDENTIFIED BY </code><code>'PWD'</code> <code>WITH GRANT OPTION;</code>

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

<code>[client]</code>

<code>default-character-</code><code>set</code><code>=utf8</code>

然后重新启动mysql服务即可。

默认配置文件路径:

配置文件:/etc/my.cnf 

日志文件:/var/log//var/log/mysqld.log 

服务启动脚本:/usr/lib/systemd/system/mysqld.service 

socket文件:/var/run/mysqld/mysqld.pid

--------------------------------------------------------------------------------------------------------------------

原文链接:http://blog.csdn.net/xyang81/article/details/51759200

本文转自 羽丰1995 51CTO博客,原文链接:http://blog.51cto.com/13683137989/1932239

继续阅读