下载mysql的yum源
1. 下载命令
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
2. 使用yum安装
yum -y install mysql80-community-release-el7-3.noarch.rpm
3.安装mysql gpg密匙
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
4.安装mysql server
yum -y install mysql-community-server
启动mysql
启动
systemctl start mysqld
查看状态
systemctl status mysqld
登录mysql
查看初始密码
grep "password" /var/log/mysqld.log
输出:
>> A temporary password is generated for root@localhost: kpPz&&-ew4Bq
登录命令
mysql -uroot -pkpPz&&-ew4Bq
修改密码
修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
修改简单密码(123456)
1.mysql> set global validate_password.policy=0;
#validate_password_length代表密码长度,最小值为4
2.mysql> set global validate_password.length=4;
3.mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
上面参数不同版本有所不同。我们可以使用命令查看本版本的参数:
mysql> SHOW VARIABLES LIKE 'validate_password%';
上述命令可能无效,出现下面情况:
mysql> show variables like 'validate_password%';
Empty set, 1 warning (0.00 sec)
处理:
出现这个问题是因为并没有安装 validate_password 插件
/** 安装插件 **/
mysql> INSTALL COMPONENT 'file://component_validate_password';
Query OK, 0 rows affected (0.10 sec)
mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| 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, 1 warning (0.00 sec)
然后修改密码策略
# 设置密码的验证强度等级
mysql> set global validate_password.policy =LOW; || set global validate_password.policy =0;
# 设置密码长度
mysql> set global validate_password.length=6;
设置远程连接权限
1.create user root@'%' identified by '123456';
2.grant all privileges on *.* to root@'%' with grant option;
#刷新权限
3.mysql: FLUSH PRIVILEGES;
only_full_group_by
1.找到 MySqL 配置文件my.cnf
2.增加一行 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
关闭yum自动更新MySQL
rpm -qa | grep mysql
卸载命令
yum -y remove mysql80-community-release-el7-3.noarch
mysql文件地址
1 /etc/my.cnf 这是mysql的主配置文件
2 /var/lib/mysql mysql数据库的数据库文件存放位置
3 /var/log mysql数据库的日志输出存放位置