MySQL 创建用户时更正mysql语法错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14394005/
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
Correct mysql syntax error when creating a user
提问by dodgerogers747
So im getting the very common ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
mysql error. I have tried all of the typical fixes on the forums, logging in via the mysql_safe method and then trying to reset my root password. However when doing so it returns with;
所以我得到了非常常见的ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
mysql 错误。我已经尝试了论坛上的所有典型修复,通过 mysql_safe 方法登录,然后尝试重置我的 root 密码。但是,这样做时它会返回;
UPDATE user SET password=PASSWORD("PASSWORD")WHERE user="root";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
So as no rows were affected I assumed there was no user to actually change. I tried to create a user:
因此,由于没有行受到影响,我认为没有用户可以实际更改。我试图创建一个用户:
CREATE USER 'root'@'localhost' IDENTIFIED BY 'root'
-> GRANT ALL ON *.* TO 'root'@'localhost'
-> flush privileges;
However this returns with 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 'GRANT ALL ON *.* TO 'root'@'localhost'
Seeing what the current user is:
查看当前用户是什么:
mysql> SELECT user();
+--------+
| user() |
+--------+
| root@ |
+--------+
I assume the syntax error is the fact that nothing comes after the @ after "root". How can i edit this information to be root@localhost and correct the issue?
我认为语法错误是在“root”之后的@ 之后没有任何内容。如何将此信息编辑为 root@localhost 并更正问题?
UPDATE
更新
after carefully reading the mysqld docs i got to this section which worked perfectly.
在仔细阅读了 mysqld 文档后,我进入了这个完美运行的部分。
Stop mysqld and restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.
停止 mysqld 并使用 --skip-grant-tables 选项重新启动它。这使任何人都可以在没有密码的情况下使用所有权限进行连接。由于这是不安全的,您可能希望将 --skip-grant-tables 与 --skip-networking 结合使用以防止远程客户端连接。
Connect to the mysqld server with this command:
使用以下命令连接到 mysqld 服务器:
shell> mysql
Issue the following statements in the mysql client. Replace the password with the password that you want to use.
在 mysql 客户端中发出以下语句。将密码替换为您要使用的密码。
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
-> WHERE User='root';
mysql> FLUSH PRIVILEGES;
The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
FLUSH 语句告诉服务器将授权表重新加载到内存中,以便它注意到密码更改。
回答by John Woo
it should be three sql statements,
应该是三个sql语句,
CREATE USER 'root'@'localhost' IDENTIFIED BY PASSWORD 'root';
GRANT ALL ON *.* TO 'root'@'localhost';
FLUSH PRIVILEGES;
回答by yanstp
i've got that same error message (Access denied for user 'root'@'localhost' (using password: YES)) when i've tried to login in my freshly new installed mysql server.
当我尝试登录新安装的 mysql 服务器时,我收到了同样的错误消息(用户“root”@“localhost”的访问被拒绝(使用密码:YES))。
I didn't know that when installing mysql-community-server (rpm) on redhat6.5, A superuser account 'root'@'localhost' is created and a password for the superuser is set and stored in the error log file and that to reveal it, i should use the :
我不知道在 redhat6.5 上安装 mysql-community-server (rpm) 时,会创建超级用户帐户 'root'@'localhost' 并设置超级用户的密码并将其存储在错误日志文件中,然后为了揭示它,我应该使用:
- shell > grep 'temporary password' /var/log/mysqld.log
- shell > grep '临时密码' /var/log/mysqld.log
I just check the password in the "mysqld.log" file and use it to login. Once in, i've changed that default password.
我只是检查“mysqld.log”文件中的密码并使用它登录。进入后,我更改了默认密码。