Centos安装mysql

1. 安装YUM Repo

# 下载yum repo
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

# 安装repo
rpm -ivh mysql57-community-release-el7-9.noarch.rpm

2. 安装mysql-server

# 安装mysql-server可能会很慢,有解决方案
yum install mysql-server

# 启动mysql
systemctl start mysqld

3. 获取临时密码

# 获取密码
grep 'temporary password' /var/log/mysqld.log

# 没有数据删除重来
rm -rf /var/lib/mysql
grep 'temporary password' /var/log/mysqld.log
systemctl start mysqld 

4. 登录mysql

# 登录mysql 密码为刚才获取的临密码
mysql -u root -p

5. 重置密码

# 重置密码,要先有密码强度下面再改
alter user user() identified by "Mysqlclient.";

6. 配置简单密码

# 查看所有数据库
show databases;
# 使用数据库mysql
use mysql
# 查看mysql 初始的密码策略
SHOW VARIABLES LIKE 'validate_password%'; 
# 设置密码强度为LOW
set global validate_password_policy=LOW;
# 设置密码长度5位数
set global validate_password_length=6;
# 修改为简单密码
alter user user() identified by "mysql";

你可能感兴趣的:(MySQL,linux,centos)