centos7使用yum方式安装MySQL5.7

yum -y localinstall http://mirrors.ustc.edu.cn/mysql-repo/mysql57-community-release-el7.rpm

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

yum install -y mysql-community-server

# 未执行这个命令,启动MySQL表示会自动生成一个临时root密码使用
if [ ! "$(cat /usr/bin/mysqld_pre_systemd | grep -v ^\# | grep initialize-insecure )" ]; then
    sed -i "s@--initialize @--initialize-insecure @g" /usr/bin/mysqld_pre_systemd
fi


# 查看生成的临时root密码
# grep 'password' /var/log/mysqld.log |head -n 1
2021-12-10T02:42:42.582937Z 1 [Note] A temporary password is generated for root@localhost: e?qh1g<!MaW1

# 使用临时密码登录后需要修改这个密码才能进行操作
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

# 修改root密码 (没有关闭密码安全性校验规则)
alter user 'root'@'localhost' identified by 'D6WrGAiOl7*6SU0b!';


systemctl enable mysqld
systemctl start mysqld

mysql -uroot

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

# 设置root密码,关闭密码复杂度策略
mysql>  set global validate_password_policy=0;
mysql>  set global validate_password_length=1;
mysql> use mysql;
mysql> update user set authentication_string=password('123456') where user='root';
mysql> flush privileges;

mysql> create database jumpserver default charset 'utf8';
Query OK, 1 row affected (0.00 sec)

mysql> set global validate_password_policy=LOW;
Query OK, 0 rows affected (0.00 sec)

mysql> create user 'jumpserver'@'%' identified by 'weakPassword';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on jumpserver.* to 'jumpserver'@'%';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye



posted @ 2021-06-07 18:22  哈喽哈喽111111  阅读(94)  评论(0编辑  收藏  举报