我尝试过多次卸载 MySQL,但每次它都会跳过设置主机密码。我需要密码,因为我需要它将其连接到 Python。
这是运行后的输出sudo mysql_secure_installation
:
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information.
答案1
我认为这可能是一个错误。在之前,如果我们在使用之前将其更改auth_socket
为,则允许我们更改root的密码。mysql_native_password
root
mysql_secure_installation
mysql_secure_installation
但是现在,我必须改为auth_socket
并mysql_native_password
使用ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxx'
来设置密码root
,然后我才能用mysql_native_password
它来更改 root 的密码。
为了复制,
安装后
mysql-server
,运行sudo mysql -u root mysql
执行以下 SQL 语句:
UPDATE user SET plugin='mysql_native_password' WHERE User='root'; FLUSH PRIVILEGES;
并且(但这不是必要的)
ALTER USER root@localhost IDENTIFIED BY 'password';
运行
sudo mysql_secure_installation
,然后设置root的密码。
答案2
您可以在物理机上(或通过 ssh)登录 mysql。然后在数据库内部使用 ALTER USER 命令启用密码验证并设置密码。
例子:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password'