[root@python ~]# mysql -V
mysql Ver 8.0.11 for Linux on x86_64 (MySQL Community Server - GPL)
[root@python ~]# ll /etc/init.d/mysqld
-rwxr-xr-x 1 root root 7166 Apr 8 16:21 /etc/init.d/mysqld
[root@python ~]# ll /etc/my.cnf --配置文件位置
-rw-r--r-- 1 root root 1188 Apr 8 16:21 /etc/my.cnf
默认的datadir是在/var/lib/mysql/,可以通过修改my.cnf修改,启动命令如下:
[root@python ~]# service mysqld start
Initializing MySQL database: [ OK ]
Starting mysqld: [ OK ]
四、发现没密码不能登录,于是添加skip-grant-tables到my.cnf,重启进去重置密码
mysql> alter user root@'localhost' identified by 'mysql';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> exit
Bye
居然不能改。。。于是:
mysql> delete from mysql.user where user='root';
Query OK, 1 row affected (0.10 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> create user root@'localhost' identified by 'mysql';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
还是不能改,查看密码复杂度要求:
mysql> show variables like '%pass%';
+----------------------------------------------+-----------------+
| Variable_name | Value |
+----------------------------------------------+-----------------+
| caching_sha2_password_auto_generate_rsa_keys | ON |
| caching_sha2_password_private_key_path | private_key.pem |
| caching_sha2_password_public_key_path | public_key.pem |
| default_password_lifetime | 0 |
| disconnect_on_expired_password | ON |
| mysql_native_password_proxy_users | OFF |
| password_history | 0 |
| password_reuse_interval | 0 |
| report_password | |
| sha256_password_auto_generate_rsa_keys | ON |
| sha256_password_private_key_path | private_key.pem |
| sha256_password_proxy_users | OFF |
| sha256_password_public_key_path | public_key.pem |
| 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 |
+----------------------------------------------+-----------------+
查看官网https://dev.mysql.com/doc/refman/8.0/en/validate-password-options-variables.html#sysvar_validate_password.policy
发现此值有3个,如下所示:
于是设置为0,然后将validate_password.length设置为4,表示最少需要4字符。之所以设置为4是因为这个参数的值不能小于如下公式的计算结果:
validate_password.number_count
+ validate_password.special_char_count
+ (2 * validate_password.mixed_case_count)
于是继续创建用户,MySQL8.0取消了直接grant创建用户的语法,只能先create user再grant,因此创建root如下: