By 大伟哥 |
安装 MariaDB 10.3 以后,默认是使用 root 用户直接通过Unix Socket 登录而不使用密码的。要切换成使用密码登录的话,需要把 默认的plugin 从 unix_socket 切换为 mysql_native_password, 并且给用户设置密码。
正确的命令是:
UPDATE mysql.user SET authentication_string = PASSWORD('mypassword'), plugin = 'mysql_native_password' WHERE User = 'root' AND Host = 'localhost';
之前在MySQL 5.7上可行的一个命令是不行的:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypassword';
另外,MariaDB官网文档里的这个命令也不行(20220328更新:Mariadb 10.5以下命令可用):
ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD("verysecret");
这两个命令都会报错:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'mysql.USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '...' at line 1
- 1281 阅读
添加新评论