CentOS 7.2 配置 MySQL 5.7

下载安装

下载mysql源安装包

wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

安装

yum localinstall mysql57-community-release-el7-8.noarch.rpm

检查安装源

yum repolist enabled | grep "mysql.*-community.*"

安装

yum install mysql-community-server

启动

启动MySQL服务

systemctl start mysqld

查看MySQL的启动状态,active是running即可

systemctl status mysqld

设置开机启动

systemctl enable mysqld
systemctl daemon-reload

配置

修改密码

默认密码在/var/log/mysqld.log文件中

取得默认密码,最好复制

grep 'temporary password' /var/log/mysqld.log

然后登陆mysql修改密码

 mysql -uroot -p
 粘贴刚才取得的默认密码

现在应该进入mysql了

set password for 'root'@'localhost'=password('新密码'); 

Note: mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位

如果你不想设置复杂密码,可自行修改策略,不建议

查看目前策略

show variables like '%password%';

默认密码策略如下:

  • 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个

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

validate_password = off

如果修改了需要重启生效

systemctl restart mysqld

官网策略详细说明: https://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy

配置默认编码为utf8

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

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

然后重启即可完成

默认配置文件路径:

配置文件:/etc/my.cnf 日志文件:/var/log//var/log/mysqld.log 服务启动脚本:/usr/lib/systemd/system/mysqld.service socket文件:/var/run/mysqld/mysqld.pid


发表评论

评论列表,共 4 条评论

  • Olivermut

    Good man! Please note an important offers for you.

    http://bit.ly/2PGFnaL

  • GregoryCes

    Hello! Behold is
    a fine offers for you.

    https://llmad.lovenights.net/c/da57dc555e50572d?s1=13606&s2=78781&s3=1&j1=1&j3=1

  • Squatina

    Good day! There is an important news offering for you. Try and be our next winner. http://bit.ly/2J7Z20Q

  • ignazio

    Hello! Please note a good offers offering for you. http://bit.ly/2Ja4tMX

About This Page

Made with bootstrap and jquery by TaoYuan.

Contact Me

Click! If you are interested