mysql案例
# 安装指定Mysql 版本
## 需要的文件
[RPM-GPG-KEY-mysql-2022](RPM-GPG-KEY-mysql-2022)
[mysql80-community-release-el7-6.noarch.rpm](mysql80-community-release-el7-6.noarch.rpm)
## 上传到centos服务器
```bash
scp D:\ResilioSync\文档\MYSQL\mysql80-community-release-el7-6.noarch.rpm D:\ResilioSync\文档\MYSQL\RPM-GPG-KEY-mysql-2022 root@116.63.51.40:~
```
![image-20220705112707846](images/image-20220705112707846.png)
## 安装 rmp 和 GpG密钥
```bash
ls
yum install mysql80-community-release-el7-6.noarch.rpm -y
rpm --import RPM-GPG-KEY-mysql-2022
```
![image-20220705112914097](images/image-20220705112914097.png)
![image-20220705113003151](images/image-20220705113003151.png)
## 使用 yum-utils 管理扩展包
```bash
yum install yum-utils -y
```
![image-20220705113228853](images/image-20220705113228853.png)
## 修改MySQL默认安装版本
```bash
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
```
![image-20220705113535353](images/image-20220705113535353.png)
![image-20220705113557704](images/image-20220705113557704.png)
## 安装mysql 5.7
```bash
yum install mysql-community-server -y
```
![image-20220705113835308](images/image-20220705113835308.png)
# 启动&&配置
## 启动
```bash
systemctl start mysqld
systemctl enable mysqld
```
![image-20220705123750193](images/image-20220705123750193.png)
## 查看默认密码
```
grep 'temporary password' /var/log/mysqld.log
```
![image-20220705123825689](images/image-20220705123825689.png)
## 修改默认密码
```bash
mysql -uroot -p
```
```sql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
FLUSH PRIVILEGES;
```
![image-20220705124005174](images/image-20220705124005174.png)
## 创建远程连接用户
```sql
CREATE USER 'username'@'%' IDENTIFIED BY 'Password1!';
FLUSH PRIVILEGES;
```
![image-20220705124246630](images/image-20220705124246630.png)
## 用户授权所有数据库所有权限
```sql
GRANT ALL ON *.* TO 'username'@'%';
FLUSH PRIVILEGES;
```
![image-20220705124623982](images/image-20220705124623982.png)
## 修改用户密码
```sql
SET PASSWORD FOR 'username'@'%' = PASSWORD('newpassword');
FLUSH PRIVILEGES;
```
## 修改密码策略
### 查看当前策略
```sql
show VARIABLES like "%password%";
```
![image-20220705124845076](images/image-20220705124845076.png)
![img](images/webp.webp)
### 修改策略和密码长度
```sql
set global validate_password_policy=0;
set global validate_password_length=5;
FLUSH PRIVILEGES;
```
![image-20220705125122416](images/image-20220705125122416.png)
- 点赞
- 收藏
- 关注作者
评论(0)