淡定哥头像

技术文档

Linux CentOS7 MySQL5安装与配置

Linux CentOS7 MySQL5安装与配置

1、配置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
systemctl restart mysqld

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 -uroot -p

ALTER USER 'root'@'localhost' IDENTIFIED BY 'freecto.com'; 
或者
set password for 'root'@'localhost'=password('freecto.com'); 

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

show variables like '%password%';

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

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

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

systemctl restart mysqld

7. 创建数据库脚本

mysql -u root -p111111
create user `freecto_com` identified by '111111';
Create DATABASE IF NOT EXISTS `freecto_com` default charset utf8 COLLATE utf8_general_ci;
grant all privileges on `freecto_com`.* to `freecto_com`@localhost identified by '111111';
quit


分享到: 

* 发表评论:
Top