MySQL ERROR 1064 (42000):您的 SQL 语法有错误;想要将密码配置为 root 作为用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36099028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR 1064 (42000): You have an error in your SQL syntax; Want to configure a password as root being the user
提问by Syed Md Ismail
I have just downloaded WAMP. I want to configure a password for the MySQL root user using MySQL console. No password has been set previously.
我刚刚下载了 WAMP。我想使用 MySQL 控制台为 MySQL root 用户配置密码。之前没有设置密码。
The following is the input
以下是输入
mysql-> use mysql
Database changed
mysql-> UPDATE user
-> SET Password=PASSWORD<'elephant7'>
-> WHERE user='root';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user='root'' at line 3
ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 3 行的“WHERE user='root'”附近使用的正确语法
回答by Sahith Vibudhi
I was using MySQL 8 and non of the above worked for me.
我使用的是 MySQL 8,但以上都不适合我。
This is what I had to do:
这就是我必须做的:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
回答by White Feather
You can use:
您可以使用:
SET PASSWORD FOR 'root' = PASSWORD('elephant7');
or, in latest versions:
或者,在最新版本中:
SET PASSWORD FOR root = 'elephant7'
You can also use:
您还可以使用:
UPDATE user SET password=password('elephant7') WHERE user='root';
but in Mysql 5.7 the field password is no more there, and you have to use:
但是在 Mysql 5.7 中,字段密码不再存在,您必须使用:
UPDATE user SET authentication_string=password('elephant7') WHERE user='root';
Regards
问候
回答by Sergio Perez
If you have ERROR 1064 (42000) or ERROR 1046 (3D000): No database selected in Mysql 5.7, you must specify the location of the user table, the location is mysql.table_name Then the code will work.
如果你有ERROR 1064 (42000) or ERROR 1046 (3D000): No database selected in Mysql 5.7,你必须指定user表的位置,位置是mysql.table_name,那么代码就可以工作了。
sudo mysql -u root -p
UPDATE mysql.user SET authentication_string=password('elephant7') WHERE user='root';
回答by wajih
Try this:
尝试这个:
UPDATE mysql.user SET password=password("elephant7") where user="root"
回答by JYoThI
Try this one. It may be helpful:
试试这个。这可能会有所帮助:
mysql> UPDATE mysql.user SET Password = PASSWORD('pwd') WHERE User='root';
I hope it helps.
我希望它有帮助。
回答by Lucas Santos
This is the only command that worked for me. (I got it from M 8.0 documentation)
这是唯一对我有用的命令。(我从 M 8.0 文档中得到它)
ALTER USER 'root'@'*' IDENTIFIED WITH mysql_native_password BY 'YOURPASSWORD';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOURPASSWORD';
回答by hiclas
From the mysql documentation version: 8.0.18:
来自 mysql 文档版本:8.0.18:
A superuser account 'root'@'localhost'
is created. A password for the superuser is set and stored
in the error log file. To reveal it, use the following command:
shell> sudo grep 'temporary password' /var/log/mysqld.log
Change the root password as soon as possible by logging in with the generated, temporary password
and set a custom password for the superuser account:
'root'@'localhost'
创建了一个超级用户帐户。超级用户的密码已设置并存储在错误日志文件中。要显示它,请使用以下命令:
shell> sudo grep 'temporary password' /var/log/mysqld.log
通过使用生成的临时密码登录并为超级用户帐户设置自定义密码,尽快更改 root 密码:
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
回答by extraterrestrial martian
I have problems with set password too. And find answer at official site
设置密码也有问题。并在官方网站上找到答案
SET PASSWORD FOR 'root'@'localhost' = 'your_password';