- CentOS中默认安装MariaDB ,需要覆盖掉
- 下载官方Yum Reposiitory
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
- 安装(覆盖掉MariaDB 软件源)
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum update
yum -y install mysql-community-server
- 启动MySQL 并查看 MySQL 运行状态,首次启动速度会比较慢,耐心等待。
systemctl start mysqld.service
systemctl status mysqld.service
- 启动成功的标志
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2019-09-03 12:22:19 CST; 11s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 35345 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 35267 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 35348 (mysqld)
CGroup: /system.slice/mysqld.service
└─35348 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
- 查找root的密码
grep "password" /var/log/mysqld.log
- 进入MySQL 后修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
如果说 Your password does not satisfy the current policy requirements 说明当前的密码不符合密码策略。
Policy | TestsPerformed |
---|---|
0 | Length |
1 | Length; numeric, lowercase/uppercase, and special characters |
2 | Length; numeric, lowercase/uppercase, and special characters; dictionary file |
策略说明 0 最小长度为 8 可以通过(set global validate_password_length=1;)进行修改
执行下面
set global validate_password_policy=0;
- 设置MySQL 远程访问,这里是所有的ip开放,如果是指定ip则需要将%更换为ip地址
grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
flush privileges;
exit
- 防火墙关闭或者开放指定端口
# 查看防火墙状态
firewall-cmd --state
# 关闭防火墙
systemctl stop firewalld.service
# 禁止防火墙开机启动
systemctl disable firewalld.service
# 添加开放端口,需要重新载入
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
- MySQL 默认字符集修改,修改my.cnf文件
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[client]
default-character-set=utf8
[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
character-set-server=utf8
collation-server=utf8_general_ci
# 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
- 安装之后查看自启动状态
systemctl list-unit-files | grep mysql
如果不是enable 设置为 enable
systemctl enable mysqld.service
欢迎给位大佬关注小编微信公众号,一起学习,一起进步: