CentOS 7 下安装mysql

前端之家收集整理的这篇文章主要介绍了CentOS 7 下安装mysql前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、配置YUM源

MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/

# 下载MysqL源安装包
wget http://dev.MysqL.com/get/MysqL57-community-release-el7-8.noarch.rpm
# 安装MysqL源
yum localinstall MysqL57-community-release-el7-8.noarch.rpm

检查MysqL源是否安装成功

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


看到上图所示表示安装成功

2、安装MysqL

yum install MysqL-community-server

3、启动MysqL服务

systemctl start MysqLd

查看MysqL的启动状态

systemctl status MysqLd
● MysqLd.service - MysqL Server
   Loaded: loaded (/usr/lib/systemd/system/MysqLd.service; disabled; vendor preset: disabled)
   Active: active (running) since 五 2016-06-24 04:37:37 CST; 35min ago
 Main PID: 2888 (MysqLd)
   CGroup: /system.slice/MysqLd.service
           └─2888 /usr/sbin/MysqLd --daemonize --pid-file=/var/run/MysqLd/MysqLd.pid

6月 24 04:37:36 localhost.localdomain systemd[1]: Starting MysqL Server...
6月 24 04:37:37 localhost.localdomain systemd[1]: Started MysqL Server.

4、开机启动

systemctl enable MysqLd
systemctl daemon-reload

5、修改root默认密码

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

grep 'temporary password' /var/log/MysqLd.log
MysqL -u root -p
MysqL> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

或者

MysqL> set password for 'root'@'localhost'=password('MyNewPass4!');

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

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

MysqL> 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个上述参数是默认策略MEDIUM的密码检查规则。

共有以下几种密码策略:

策略 检查规则
0 or LOW Length
1 or MEDIUM Length; numeric,lowercase/uppercase,and special characters
2 or STRONG Length; numeric,and special characters; dictionary file

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

修改密码策略

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

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

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

validate_password = off

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

systemctl restart MysqLd

6、添加远程登录用户

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

MysqL> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;

7、配置默认编码为utf8

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

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

重新启动MysqL服务,查看数据库默认编码如下所示:

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

原文链接:https://www.f2er.com/centos/376696.html

猜你在找的CentOS相关文章