目录
1、配置yum源
2、安装MySQL
3、启动MySQL服务
4、开启启动
5、修改 MySQL 中 root 本地登录密码
6、允许远程登录
7、设置MySQL默认编码为utf8
8、MySQL忘记root用户密码,解决方案
https://dev.mysql.com/downloads/repo/yum/
sudo wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
sudo yum localinstall mysql57-community-release-el7-8.noarch.rpm
sudo yum repolist enabled | grep "mysql.*-community.*"
出现上图红色字体部分表示安装成功
sudo yum install mysql-community-server
sudo systemctl start mysqld
sudo systemctl status mysqld
# 或者使用
sudo ps -le | grep mysqld
sudo systemctl enable mysqld
sudo systemctl daemon-reload
sudo grep 'temporary password' /var/log/mysqld.log
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
set password for 'root'@'localhost'=password('MyNewPass4!');
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示:
show variables like '%password%';
--下面参数是默认策略MEDIUM的密码检查规则:
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个
MySQL官网密码策略详细说明
-- 在/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
MySQL默认只允许root帐户在本地登录,想要远程连接MySQL,必须开启root用户允许远程连接,或者添加一个允许远程连接的帐户。
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root用户的密码' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.0.33' IDENTIFIED BY 'root用户的密码' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'dadeity'@'%' IDENTIFIED BY '[email protected]' WITH GRANT OPTION;
flush privileges;
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
systemctl restart mysqld
配置文件: /etc/my.cnf
日志文件: /var/log//var/log/mysqld.log
服务启动脚本: /usr/lib/systemd/system/mysqld.service
socket文件: /var/run/mysqld/mysqld.pid
[mysqld]
skip-grant-tables
mysql -u root
update mysql.user set authentication_string=password('newPass') where user='root' and Host = 'localhost';
flush privileges