在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB。
1 下载并安装MySQL官方的 Yum Repository
[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
[root@localhost ~]# yum -y install mysql-community-server #开始安装MySQL服务器。安装完成后就会覆盖掉之前的mariadb。
2 mysql数据库设置
启动mysql
[root@localhost ~]# systemctl start mysqld.service
查看mysql运行状态
[root@localhost ~]# systemctl status mysqld.service
进入myslq,进入mysql之前需要先找到mysql的密码 ```bash [root@localhost ~]# grep “password” /var/log/mysqld.log [root@localhost ~]# mysql -uroot -p
4. 输入初始密码,此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库
```bash
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
- 密码有复杂性校验,可以更改密码的校验规则
密码的长度是由validate_password_length决定的,而validate_password_length的计算公式是: ```bash validate_password_length = validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 4 |
| 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.01 sec)
初始情况下第一个的值是ON,validate_password_length是8。可以通过如下命令修改:
```bash
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
- 防止yum操作自动更新数据库,删除 Yum Repository ```bash [root@localhost ~]# yum -y remove mysql57-community-release-el7-10.noarch
```