ShardingSphere-环境准备

Linux安装Mysql5.7

配置mysql扩展源

[root@localhost ~]# rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm

yum安装mysql

yum install mysql-community-server -y

启动Mysql,并加入开机自启

systemctl start mysqld    // 启动mysql
systemctl status mysqld   // 查看mysql状态
systemctl stop mysqld    // 停止mysql
systemctl enable mysqld  // 加入开机自启

使用mysql初始密码登录数据库

-- 查找初始密码
> grep "password" /var/log/mysqld.log
> mysql -uroot -ph+AC*U:cj5bm

-- 或者一步到位
>mysql -uroot -p$(awk '/temporary password/{print $NF}' /var/log/mysqld.log)


[root@localhost ~]# grep "password" /var/log/mysqld.log
2021-03-22T01:44:41.807618Z 1 [Note] A temporary password is generated for root@localhost: h+AC*U:cj5bm
2021-03-22T01:52:07.570508Z 2 [Note] Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost ~]# 

降低数据库密码级别

mysql> SHOW VARIABLES LIKE 'validate_password%';  // 查看 mysql 初始的密码策略
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | OFF    |
| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | MEDIUM |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.01 sec)

mysql> set global validate_password_policy=LOW;  // 降低密码策略级别
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_check_user_name    | OFF   |
| validate_password_dictionary_file    |       |
| validate_password_length             | 8     |
| validate_password_mixed_case_count   | 1     |
| validate_password_number_count       | 1     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)

// 设置密码
> set password for root@localhost = password('admin123');

开启远程连接

> mysql> grant all on *.* to root@'%' identified by 'admin123';  // 开启允许远程连接
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;   // 刷新权限
Query OK, 0 rows affected (0.00 sec)

配置主从复制

Mysql的主从复制直接参考该篇文章进行环境搭建:Mysql主从复制

Last Updated 2024/5/24 16:21:58