CentOS6.5安装MySQL5.7详细教程

Posted 叫我星宇

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS6.5安装MySQL5.7详细教程相关的知识,希望对你有一定的参考价值。

https://www.cnblogs.com/lzj0218/p/5724446.html

1.检测系统是否已经安装过mysql或其依赖,若已装过要先将其删除,否则第4步使用yum安装时会报错:

yum list installed | grep mysql
mysql-libs.i686         5.1.71-1.el6      @anaconda-CentOS-201311271240.i386/6.5
yum -y remove mysql-libs.i686

2.从mysql的官网下载mysql57-community-release-el6-5.noarch.rpm(注意这里的el6-5即适配RHEL6.5的版本,如果下载了其它版本后面的安装过程中可能会报错):

wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm

3.安装第一步下载的rpm文件:

yum install mysql-community-release-el6-5.noarch.rpm
安装成功后,我们可以看到/etc/yum.repos.d/目录下增加了以下两个文件

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

查看mysql57的安装源是否可用,如不可用请自行修改配置文件(/etc/yum.repos.d/mysql-community.repo)使mysql57下面的enable=1

若有mysql其它版本的安装源可用,也请自行修改配置文件使其enable=0

# yum repolist enabled | grep mysql
mysql-connectors-community MySQL Connectors Community                        13
mysql-tools-community      MySQL Tools Community                             18
mysql57-community-dmr      MySQL 5.7 Community Server Development Milesto    65

4.使用yum安装mysql:

 yum install mysql-community-server    

5.启动mysql服务:

service mysqld start

查看root密码:

1 # grep "password" /var/log/mysqld.log
2 2016-08-10T15:03:02.210317Z 1 [Note] A temporary password is generated for root@localhost: AYB(&-3Cz-rW

现在必须立刻修改密码,不然会报错:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

修改密码(如果在此步报错ERROR 1819,请向下翻查看原因及解决方法):

mysql> SET PASSWORD FOR \'root\'@\'localhost\' = PASSWORD(\'newpass\');
  1. mysql> SET PASSWORD = PASSWORD(\'123456\');
  2. ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
  3. mysql> SET PASSWORD = PASSWORD("root");
  4. ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    所以你更改密码必须满足:数字、小写字母、大写字母 、特殊字符、长度至少8位
    如此你便成功修改了密码,最后你还要设置一下过期时间,以防止密码失效。
    /etc/my.cnf配置文件中增加
    1. [mysqld]
    2.  default_password_lifetime=0       或者直接通过命令设置  ALTER USER \'script\'@\'localhost\' PASSWORD EXPIRE NEVER

6.查看mysqld是否开机自启动,并设置为开机自启动:

1 chkconfig --list | grep mysqld
2 chkconfig mysqld on

 

7.修改字符集为UTF-8:

vim /etc/my.cnf

在[mysqld]部分添加:

character-set-server=utf8

在文件末尾新增[client]段,并在[client]段添加:

default-character-set=utf8

修改好之后重启mysqld服务:

service mysqld restart

查看修改结果:

复制代码
mysql> show variables like "%character%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
复制代码

 

注:在修改密码步骤,若设置的密码为简单密码,可能会出现如下错误:

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

这一错误其实与validate_password_policy值的设置有关:

validate_password_policy值默认为1,即MEDIUM,所以刚开始设置的密码必须符合长度要求,且必须含有数字,小写或大写字母,特殊字符

如果我们只是做为测试用而不需要如此复杂的密码,可使用如下方式修改validate_password_policy值

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

这样,对密码要求就只有长度了,而密码的最小长度由validate_password_length值决定

validate_password_length参数默认为8,它有最小值的限制,最小值为:

validate_password_number_count+ validate_password_special_char_count+ (2 * validate_password_mixed_case_count)

其中,validate_password_number_count指定了密码中数字的长度,validate_password_special_char_count指定了密码中特殊字符的长度,validate_password_mixed_case_count指定了密码中大小字母的长度。这些参数的默认值均为1,所以validate_password_length最小值为4,如果显性指定validate_password_length的值小于4,尽管不会报错,但validate_password_length的值将设为4

设置validate_password_length的值:

mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)

如果修改了validate_password_number_count,validate_password_special_char_count,validate_password_mixed_case_count中任何一个值,则validate_password_length将进行动态修改。

 

以上是关于CentOS6.5安装MySQL5.7详细教程的主要内容,如果未能解决你的问题,请参考以下文章

RedHat6.5/CentOS6.5安装Mysql5.7.20的教程详解

centos7和centos6.5环境rpm方式安装mysql5.7和mysql5.6详解

CentOS6.5安装MySQL5.7

centos6.5安装mysql5.7

centos6.5编译安装mysql5.7.11

CentOS6.5安装MySQL5.7(也适合其他版本安装)