php 在mysql中拒绝插入命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5698981/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:15:48  来源:igfitidea点击:

insert command denied in mysql

phpmysql

提问by souce code

I have a database table from which, when I select data with username and password, it works but when I insert some data in that table with same username and password it shows me the error

我有一个数据库表,当我使用用户名和密码选择数据时,它可以工作,但是当我使用相同的用户名和密码在该表中插入一些数据时,它会显示错误

INSERT command denied to user 'username'@'localhost' for table 'tablename'

I searched using Google and someone else had the same problem with db size. I checked my db and when I go directly to phpmyadmin to insert data into the table, it works, but when I call a query to the table from a PHP script, it gives me the error.

我使用谷歌搜索,其他人对数据库大小有同样的问题。我检查了我的数据库,当我直接转到 phpmyadmin 将数据插入表中时,它可以工作,但是当我从 PHP 脚本调用对表的查询时,它给了我错误。

采纳答案by Zach Rattner

This is a permissions problem. Log into a MySQL prompt with the user the app is running as, and enter this query:

这是一个权限问题。以运行应用程序的用户身份登录 MySQL 提示符,然后输入以下查询:

SHOW GRANTS;

This will show you the privileges (grantsin MySQL-speak) that the current user has. My guess is that you won't see INSERT privileges for the given table. You will need the root user to grant you permission by running this query:

这将向您显示当前用户拥有的权限(在 MySQL 中是授予权限)。我的猜测是您不会看到给定表的 INSERT 权限。您将需要 root 用户通过运行此查询来授予您权限:

GRANT INSERT ON 'db'.'tablename' TO 'username'@'localhost'

回答by Rafik Bari

I had a similar problem after moving my site from one hosting account to another. The problem was caused by a SQL query (INSERT) that referenced the old database. replacing the old db with the new db name (or just removing the db name altogether) solved the problem. But this mistake stumped the support people at my hosting company.

将我的网站从一个托管帐户移到另一个托管帐户后,我遇到了类似的问题。该问题是由INSERT引用旧数据库的 SQL 查询 ( )引起的。用新的 db 名称替换旧的 db(或完全删除 db 名称)解决了这个问题。但是这个错误难倒了我托管公司的支持人员。

Example:

例子:

INSERT INTO old_db_name.table_name ( ) VALUES ();

Changed to:

变成:

INSERT INTO new_db_name.table_name ( ) VALUES ( );

Hope this helps and makes sense.

希望这有帮助并且有意义。

回答by ozgrozer

Check your SQL code.

检查您的 SQL 代码。

And just delete dbName if you have.

如果有,只需删除 dbName。

Example:

例子:

insert into `dbName`.`tableName` ( columns ) values ( values );

Change to:

改成:

insert into `tableName` ( columns ) values ( values );

回答by PtF

This also happened to me and the problem is that when you call the command INSERTin your php file you must have specified another database.

这也发生在我身上,问题是当您INSERT在 php 文件中调用该命令时,您必须指定另一个数据库。

In short, find where your INSERT command is and check the part your_database_namebelow

简而言之,找到你的 INSERT 命令在哪里并检查your_database_name下面的部分

"INSERT INTO \`your_database_name\`.\`your_table_name\`

That might solve your problem. Of course, if all privileges are granted for you.

那可能会解决您的问题。当然,如果为您授予所有权限。

回答by Mudasser

In your query you might be using table name with database name "INSERT INTO DB_NAME.table_name ..." where you database user do not have insert permissions for DB_NAME. So this error is coming because query is pointing to the table of another database.

在您的查询中,您可能使用数据库名称为“INSERT INTO DB_NAME.table_name ...”的表名,其中您的数据库用户没有 DB_NAME 的插入权限。所以这个错误即将到来,因为查询指向另一个数据库的表。

You need to remove the database name or use correct database name either.

您需要删除数据库名称或使用正确的数据库名称。

回答by Daan

I just had the same issue.

我只是有同样的问题。

Our hosted mysql provider removed the insert permission when the max db volume was reached.

当达到最大数据库量时,我们托管的 mysql 提供程序删除了插入权限。

Using the

使用

SHOW GRANTS;

command (mentioned in answer above) in mysql helped me figure this out.

mysql 中的命令(在上面的回答中提到)帮助我解决了这个问题。

We used JAWS DB MYSQL, but other hosted mysql providers may use the same method.

我们使用了 JAWS DB MYSQL,但其他托管的 mysql 提供程序可能使用相同的方法。

回答by kkk

Make sure that you have an open connection to the database.

确保您有一个到数据库的打开连接。

If you have separate functions for database connection and for insert values check the database connection is open or not.

如果您有单独的数据库连接函数和插入值函数,请检查数据库连接是否打开。