Redirecting to /bin/systemctl start mysqld.service [root@localhost program]#
使用service mysqld status查看mysql启动状态,显示结果如下。
[root@localhost program]# service mysqld status Redirecting to /bin/systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2021-11-16 19:32:35 CST; 41s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 17884 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 17963 (mysqld) Status: "Server is operational" CGroup: /system.slice/mysqld.service └─17963 /usr/sbin/mysqld
Nov 16 19:32:29 localhost systemd[1]: Starting MySQL Server... Nov 16 19:32:35 localhost systemd[1]: Started MySQL Server.
[root@localhost program]# grep "A temporary password" /var/log/mysqld.log 2021-11-16T11:32:31.731757Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: HE)ZBV0.q:r0
[root@localhost program]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.27
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
修改密码
由于当前密码是Mysql自动生成的,所以在后续操作中,Mysql会提示让我们修改
执行修改命令时,会得到如下提示。
mysql> alter user 'root'@'localhost' IDENTIFIED BY '123456'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements mysql>
执行 show variables like 'validate_password.%';可以查看安全策略设置,但是由于使用初始密码,mysql会给出下面这个提示。
mysql> show variables like 'validate_password.%'; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql>
于是,我们只能先修改成一个稍微复杂一点的
mysql> alter user 'root'@'localhost' IDENTIFIED BY 'root@123456!Q@W'; Query OK, 0 rows affected (0.01 sec)
再次执行 show variables like 'validate_password.%';,得到如下信息
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 (0.01 sec)
validate_password.length 是密码的最小长度,默认是8,我们把它改成6 输入:set global validate_password.length=6;
validate_password.policy 验证密码的复杂程度,我们把它改成0 输入:set global validate_password.policy=0;
validate_password.check_user_name 用户名检查,用户名和密码不能相同,我们也把它关掉 输入:set global validate_password.check_user_name=off;
修改完成后,验证修改结果如下。
mysql> show variables like 'validate_password.%'; +--------------------------------------+-------+ | Variable_name | Value | +--------------------------------------+-------+ | validate_password.check_user_name | OFF | | validate_password.dictionary_file | | | validate_password.length | 6 | | 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)
再次执行修改密码的语句,就可以修改成功了!
mysql> alter user 'root'@'localhost' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.01 sec)