简体   繁体   English

MySQL:错误1142(42000)和错误1064(42000)

[英]MySQL: ERROR 1142 (42000) and ERROR 1064 (42000)

I'm using windows 7. I've downloaded mysql-5.5.16-win32.zip and installed it. 我正在使用mysql-5.5.16-win32.zip 。我已经下载并安装了mysql-5.5.16-win32.zip I started MySQL server successfully, but I get this error: 我成功启动了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 privileges, from Windows, to the mysql table users? 如何从Windows向mysql表用户设置所需的特权?

The mysql commandline error message: mysql命令行错误消息:

ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user'

Means you are logged into mysql with a default null user with just about zero privileges. 意味着您使用具有大约零特权的默认空用户登录mysql。

  1. From the command line, run mysql as you did before: 从命令行像以前一样运行mysql:

     C:\\Users\\Charity>mysql 
  2. Which brings you to a mysql prompt, run the command select user(); 这将带您进入mysql提示符,运行命令select user();

     mysql> select user(); +----------------+ | user() | +----------------+ | ODBC@localhost | +----------------+ 1 row in set (0.00 sec) 

    That output means you are connecting not as a user, but as some kind of non-user API connector. 该输出表示您不是以用户身份而是以某种非用户API连接器的身份进行连接。 ODBC is not in the mysql.users table. ODBC不在mysql.users表中。 It is the user that connects to MySQL when you don't specify a user. 当您不指定用户时,就是连接到MySQL的用户。

  3. Run another command: 运行另一个命令:

     mysql> select user from mysql.user; ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user' mysql> 

    We didn't connect as any user so it's telling us access denied. 我们没有以任何用户身份连接,因此它告诉我们访问被拒绝。

  4. Run these commands: 运行以下命令:

     C:\\Users\\Charity>mysql -u this_is_not_a_user mysql> select user(); +------------------------------+ | user() | +------------------------------+ | this_is_not_a_user@localhost | +------------------------------+ 1 row in set (0.00 sec) mysql> 

    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. 没有。

  5. Stop fooling around and login as root: 停止鬼混并以root用户身份登录:

     C:\\Users\\Charity>mysql -u root -p Enter password: ********** mysql> select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec) mysql> 

    Now you are root, you can see everything. 现在您已经是root用户,您可以看到所有内容。

  6. Look at the mysql.user table: 查看mysql.user表:

     mysql> select user, host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | | linux | | root | linux | | | localhost | | pma | localhost | | root | localhost | +------+-----------+ 5 rows in set (0.00 sec) 

    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. 让野蛮人远离护城河。

  7. You don't want to be logging in as root all the time. 您不想一直以root用户身份登录。 So create a new user. 因此,创建一个新用户。 Go to phpmyadmin, login to phpadmin as root. 转到phpmyadmin,以root用户身份登录到phpadmin。 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: 然后,您可以以该用户身份登录:

     C:\\Users\\Charity>mysql -u el -p Enter password: ********** mysql> select user(); +----------------+ | user() | +----------------+ | el@localhost | +----------------+ 1 row in set (0.00 sec) mysql> 

    This user can do everything that you granted in the permissions defined in step 7. 该用户可以执行您在步骤7中定义的权限中授予的所有操作。

The command mysql -u root -p is supposed to be run at the Windows command line. mysql -u root -p命令应该在Windows命令行上运行。 When you see the prompt 当您看到提示时

mysql>

This 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). 这意味着您当前正在使用MySQL命令行客户端(在示例的第一行首次运行mysql时将其打开)。

What you need to do is run the command quit , so you're back at the Windows command prompt, and then run 您需要做的是运行命令quit ,这样您将返回Windows命令提示符, 然后运行

mysql -u root -p

This will start the MySQL client again, but will prompt you for your password to log you in as the user root . 这将再次启动MySQL客户端,但是会提示您输入密码,以root用户身份登录。

如果您是初学者,则不必键入-p,而只需键入:

    mysql -u root

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM