在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB。

1 下载并安装MySQL官方的 Yum Repository

  1. [root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
  2. [root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
  3. [root@localhost ~]# yum -y install mysql-community-server #开始安装MySQL服务器。安装完成后就会覆盖掉之前的mariadb。

2 mysql数据库设置

  1. 启动mysql

    1. [root@localhost ~]# systemctl start mysqld.service
  2. 查看mysql运行状态

    1. [root@localhost ~]# systemctl status mysqld.service

    image.png

  3. 进入myslq,进入mysql之前需要先找到mysql的密码 ```bash [root@localhost ~]# grep “password” /var/log/mysqld.log [root@localhost ~]# mysql -uroot -p

  1. 4. 输入初始密码,此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库
  2. ```bash
  3. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
  1. 密码有复杂性校验,可以更改密码的校验规则
    1. mysql> SHOW VARIABLES LIKE 'validate_password%';
    2. +--------------------------------------+-------+
    3. | Variable_name | Value |
    4. +--------------------------------------+-------+
    5. | validate_password_check_user_name | OFF |
    6. | validate_password_dictionary_file | |
    7. | validate_password_length | 4 |
    8. | validate_password_mixed_case_count | 1 |
    9. | validate_password_number_count | 1 |
    10. | validate_password_policy | LOW |
    11. | validate_password_special_char_count | 1 |
    12. +--------------------------------------+-------+
    13. 7 rows in set (0.01 sec)
    密码的长度是由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)
  1. 初始情况下第一个的值是ONvalidate_password_length8。可以通过如下命令修改:
  2. ```bash
  3. mysql> set global validate_password_policy=0;
  4. mysql> set global validate_password_length=1;
  1. 防止yum操作自动更新数据库,删除 Yum Repository ```bash [root@localhost ~]# yum -y remove mysql57-community-release-el7-10.noarch

```