MySQL:错误 1142 (42000) 和错误 1064 (42000)
我使用的是 Windows 7。我已下载并安装了 mysql-5.5.16-win32.zip
。我成功启动了 MySQL 服务器,但出现此错误:
C:\Program Files\Mysql\bin>mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.16 MySQL Community Server (GPL)
mysql> select user, host, password from mysql.user;
ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user
'
mysql> mysql -u root -p
-> select user, host, password from mysql.user;
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 'mysql
-u root -p
select user, host, password from mysql.user' at line 1
mysql> mysql -u root -p root
-> select user, host, password from mysql.user;
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 'mysql
-u root -p root
select user, host, password from mysql.user' at line 1
mysql>
How can set the required privilege, from Windows, to the mysql table users?
I'm using windows 7. I've downloaded mysql-5.5.16-win32.zip
and installed it. I started MySQL server successfully, but I get this error:
C:\Program Files\Mysql\bin>mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.16 MySQL Community Server (GPL)
mysql> select user, host, password from mysql.user;
ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user
'
mysql> mysql -u root -p
-> select user, host, password from mysql.user;
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 'mysql
-u root -p
select user, host, password from mysql.user' at line 1
mysql> mysql -u root -p root
-> select user, host, password from mysql.user;
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 'mysql
-u root -p root
select user, host, password from mysql.user' at line 1
mysql>
How can set the required privileges, from Windows, to the mysql table users?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
mysql命令行错误消息:
意味着您使用默认的空用户登录mysql,权限几乎为零。
从命令行,像以前一样运行 mysql:
这将带您进入 mysql 提示符,运行命令
select user();
该输出意味着您不是作为用户进行连接,而是作为某种非用户 API 连接器进行连接。 ODBC 不在
mysql.users
表中。当不指定用户时,就是连接MySQL的用户。运行另一个命令:
我们没有以任何用户身份连接,因此它告诉我们访问被拒绝。
运行这些命令:
因此,我们已以我们定义的另一个非用户身份登录。您是否希望我们随机抽取的这个用户拥有任何特权?否。
别再胡闹了,以 root 身份登录:
现在你是 root,你可以看到一切。
查看mysql.user表:
您可能想要创建更多用户,以便让人们使用数据库,而无需授予他们对您的数据库执行任何操作的权限。将野蛮人挡在护城河之外。
您不想一直以 root 身份登录。所以创建一个新用户。转到 phpmyadmin,以 root 身份登录 phpadmin。单击“用户”选项卡并创建一个新用户。将显示一个新对话框,填写用户名、密码和权限。然后您可以以该用户身份登录:
此用户可以执行您在步骤 7 中定义的权限中授予的所有操作。
The mysql commandline error message:
Means you are logged into mysql with a default null user with just about zero privileges.
From the command line, run mysql as you did before:
Which brings you to a mysql prompt, run the command
select user();
That output means you are connecting not as a user, but as some kind of non-user API connector. ODBC is not in the
mysql.users
table. It is the user that connects to MySQL when you don't specify a user.Run another command:
We didn't connect as any user so it's telling us access denied.
Run these commands:
So we've logged in as another non-user of our definition. Would you expect this user we pulled out of a hat to have any privileges at all? No.
Stop fooling around and login as root:
Now you are root, you can see everything.
Look at the mysql.user table:
You might want to create more users so you can let people use the database without giving them the rights to do anything to your database. Keep the barbarians out at the moat.
You don't want to be logging in as root all the time. So create a new user. Go to phpmyadmin, login to phpadmin as root. Click the "users" tab and create a new user. A new dialog shows, fill in the username, password and permissions. Then you can login as that user:
This user can do everything that you granted in the permissions defined in step 7.
命令 mysql -u root -p 应该在 Windows 命令行中运行。当您看到提示时
这意味着您当前正在使用 MySQL 命令行客户端(当您首次在示例的第一行运行
mysql
时打开了它)。您需要做的是运行命令
quit
,这样您就回到了Windows命令提示符,然后然后运行这将再次启动MySQL客户端,但会提示您需要输入密码才能以
root
用户身份登录。The command
mysql -u root -p
is supposed to be run at the Windows command line. When you see the promptThis means you're currently using the MySQL command line client (you opened it when you first ran
mysql
on the first line of your sample).What you need to do is run the command
quit
, so you're back at the Windows command prompt, and then runThis will start the MySQL client again, but will prompt you for your password to log you in as the user
root
.如果您是初学者,您可能不必输入 -p
只需输入:
If you are a beginner, you might not have to type -p
just type: