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

时间:2022-07-13 22:54:28

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:

我使用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 privileges, from Windows, to the mysql table users?

如何将所需的特权从Windows设置为mysql表用户?

3 个解决方案

#1


9  

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.

意味着您将使用默认的null用户登录到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. ODBC is not in the mysql.users table. It is the user that connects to MySQL when you don't specify a user.

    这个输出意味着您不是作为用户连接,而是作为某种非用户API连接器连接。ODBC不在mysql中。用户表。当您不指定用户时,它是连接到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.

    现在你是根,你可以看到一切。

  6. Look at the mysql.user table:

    看看mysql。用户表:

    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. 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:

    您不希望一直作为root用户登录。因此,创建一个新用户。进入phpmyadmin,登录到phpadmin作为根。单击“users”选项卡并创建一个新用户。一个新的对话框显示,填写用户名、密码和权限。然后你可以作为该用户登录:

    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中定义的权限中授予的所有操作。

#2


1  

The command mysql -u root -p is supposed to be run at the Windows command line. When you see the prompt

命令mysql -u root -p应该在Windows命令行运行。当你看到提示符

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客户端,但会提示您输入密码以作为用户根用户登录。

#3


1  

If you are a beginner, you might not have to type -p just type:

如果你是初学者,你可能不需要只输入-p:

    mysql -u root

#1


9  

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.

意味着您将使用默认的null用户登录到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. ODBC is not in the mysql.users table. It is the user that connects to MySQL when you don't specify a user.

    这个输出意味着您不是作为用户连接,而是作为某种非用户API连接器连接。ODBC不在mysql中。用户表。当您不指定用户时,它是连接到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.

    现在你是根,你可以看到一切。

  6. Look at the mysql.user table:

    看看mysql。用户表:

    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. 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:

    您不希望一直作为root用户登录。因此,创建一个新用户。进入phpmyadmin,登录到phpadmin作为根。单击“users”选项卡并创建一个新用户。一个新的对话框显示,填写用户名、密码和权限。然后你可以作为该用户登录:

    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中定义的权限中授予的所有操作。

#2


1  

The command mysql -u root -p is supposed to be run at the Windows command line. When you see the prompt

命令mysql -u root -p应该在Windows命令行运行。当你看到提示符

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客户端,但会提示您输入密码以作为用户根用户登录。

#3


1  

If you are a beginner, you might not have to type -p just type:

如果你是初学者,你可能不需要只输入-p:

    mysql -u root