- 下载并安装MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
使用上面的命令就直接下载了安装用的Yum Repository,大概25KB的样子,然后就可以直接yum安装了。
yum -y install mysql57-community-release-el7-10.noarch.rpm
- 安装 MySQL 服务
yum -y install mysql-community-server
这个过程比较漫长.....
- MySQL 配置
- 启动 MySQL
systemctl start mysqld.service
- 修改
/etc/my.cnf
,增加bind-address=0.0.0.0
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# 绑定 ip
bind-address=0.0.0.0
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
重启mysql服务使配置生效
systemctl restart mysqld
- 查看 MySQL 运行状态,运行状态如图:
systemctl status mysqld
- 查看
root@localhost
密码,grep "password" /var/log/mysqld.log
进入数据库
mysql -u root -p
,输入初始密码lGbaxrzas9.E
修改
root@localhost
密码,ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
其中‘new password’替换成你要设置的密码,注意:密码设置必须要大小写字母数字和特殊符号(,/';:等),不然不能配置成功,如果要修改为root这样的弱密码,需要进行以下配置:查看当前密码策略
show variables like '%password%';
策略说明
validate_password.length 是密码的最小长度,默认是8,我们把它改成6
输入:set global validate_password.length=6;
validate_password.policy 验证密码的复杂程度,我们把它改成0
输入:set global validate_password.policy=0;
validate_password.check_user_name 用户名检查,用户名和密码不能相同,我们也把它关掉
输入:set global validate_password.check_user_name=off;
- 修改密码策略
添加validate_password_policy配置
选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
[root@slave1 ~]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# 绑定 ip
bind-address=0.0.0.0
# 添加validate_password_policy配置
validate_password_policy=0
# 关闭密码策略
validate_password = off
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
重启mysql服务使配置生效
systemctl restart mysqld
- 开启mysql的远程访问
执行以下命令开启远程访问限制(注意:下面命令开启的IP是 192.168.0.1,如要开启所有的,用%代替IP):
grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
然后再输入下面两行命令
flush privileges;
exit;
- 为 firewalld 添加开放端口
添加mysql端口3306
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 重新加载
firewall-cmd --reload
- 修改mysql的字符编码(不修改会产生中文乱码问题)
显示原来编码:
show variables like '%character%';
修改/etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重启mysql服务使配置生效
systemctl restart mysqld