mysqlimport:错误:1045,访问被拒绝

发布于 2024-11-26 23:54:49 字数 1203 浏览 0 评论 0原文

有谁知道为什么我在运行 mysqlimport 时收到此错误?

mysqlimport -u someone -pwhatever --columns=a,b,c,d,e bar /var/tmp/baz.sql
mysqlimport: Error: 1045, Access denied for user 'someone'@'%' (using password: YES), when using table: baz

然而...

mysql -u someone -pwhatever
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 199
Server version: 5.1.41-3ubuntu12.10 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show grants;
+------------------------------------------------------------------------------------------------------------+
| Grants for someone@%                                                                                   |
+------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'someone'@'%' IDENTIFIED BY PASSWORD '*BLAHBLAHBLAH' |
| GRANT ALL PRIVILEGES ON `bar`.* TO 'someone'@'%'                                          |
+------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql>

Does anyone know why I get this error when running mysqlimport?

mysqlimport -u someone -pwhatever --columns=a,b,c,d,e bar /var/tmp/baz.sql
mysqlimport: Error: 1045, Access denied for user 'someone'@'%' (using password: YES), when using table: baz

However...

mysql -u someone -pwhatever
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 199
Server version: 5.1.41-3ubuntu12.10 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show grants;
+------------------------------------------------------------------------------------------------------------+
| Grants for someone@%                                                                                   |
+------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'someone'@'%' IDENTIFIED BY PASSWORD '*BLAHBLAHBLAH' |
| GRANT ALL PRIVILEGES ON `bar`.* TO 'someone'@'%'                                          |
+------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦毁影碎の 2024-12-03 23:54:49

您可以通过使用 mysqlimport 的 --local 参数来避免需要额外的权限:

--local, -L

           Read input files locally from the client host.

You can avoid the need for the extra privileges by using the --local parameter to mysqlimport:

--local, -L

           Read input files locally from the client host.
人生戏 2024-12-03 23:54:49

好吧,事实证明 FILE 权限是一个“全局”权限,这显然意味着你不能有选择地在某些数据库、表上启用它。这就是为什么我之前对 bar.* 的授予语句没有效果:

GRANT ALL PRIVILEGES ON `bar`.* TO 'someone'@'%' 

您需要授予 *.* 上的 FILE 权限:

GRANT FILE ON *.* to 'someone'@'%';

希望这对某人有帮助。

OK, it turns out that the FILE privilege is a "global" privilege, which apparently means you can't selectively enable it on certain databases, tables. etc. That's why my previous grant statement on bar.* had no effect:

GRANT ALL PRIVILEGES ON `bar`.* TO 'someone'@'%' 

You need to grant FILE privileges on *.*:

GRANT FILE ON *.* to 'someone'@'%';

Hope this helps someone.

公布 2024-12-03 23:54:49

有些人会选择此命令,跳过额外的 FILE 授予。

mysql -u 用户名 -p; <你的文件.sql

Some would instead opt for this command, skipping the extra FILE grant.

mysql -u username -p <yourdbname> < yourfile.sql

随遇而安 2024-12-03 23:54:49

mysqlimport 是 LOAD DATA INFILE 语句的命令行接口,为此您需要“FILE”权限(服务器级别)。

来自 LOAD DATA INFILE 语法

Also, to use LOAD DATA INFILE on server files, you must have the FILE privilege.

mysqlimport is a command-line interface to the LOAD DATA INFILE statement, for which you need the 'FILE' privilege (server level).

From LOAD DATA INFILE syntax:

Also, to use LOAD DATA INFILE on server files, you must have the FILE privilege.
失退 2024-12-03 23:54:49

TLDR:在 MySQLDump 中使用 `--set-gtid-purged=OFF` 参数

当执行 mysqldump -u username -p 创建要在其他地方导入的文件时,放入以下参数--set-gtid-purged=OFF

复制需要 GTID,如果您只想将 DB 1 复制/粘贴到 DB 2,则可能不适用于您正在做的事情

。一般调试帮助

我这里的调试过程与其他人所做的有点不同。我建议这样进行调试:将 .sql 更改为最简单的内容,也许只是一个 CREATE TABLE 语句,然后查看它是否运行。

如果它运行,那么您需要从 SQL 导入文件中删除以下内容:

  • 任何行设置 @@GLOBAL.GTID
  • SET @@MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN;
  • SET @@SESSION.SQL_LOG_BIN= 0;
  • SET @@SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN;

正如你所看到的,有很多 GTID 内容,这是用于的事务 ID 信息进行复制。因此,这些在进行服务器复制时很重要,但在基本上将一个数据库复制粘贴到另一个数据库时并不重要,在这种情况下我们可以删除它们。

TLDR: Use the `--set-gtid-purged=OFF` Arg in MySQLDump

When doing mysqldump -u username -p to create the file you're going to import elsewhere, throw in the argument of --set-gtid-purged=OFF.

GTIDs are needed for replication, and probably don't apply to what you're doing if you just want to copy/paste DB 1 to DB 2.

General Debugging Help

My debugging process here was a little bit different than what others have done. I suggest this to debug: Change your .sql to the simplest possible thing, maybe just one single CREATE TABLE statement, and see if it runs.

If it runs, then these are things that you want to remove from your SQL import file:

  • Any line setting @@GLOBAL.GTID.
  • SET @MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN;
  • SET @@SESSION.SQL_LOG_BIN= 0;
  • SET @@SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN;

As you can see, it's a lot of GTID stuff, which is transaction ID info used for doing replication. So, these are important when doing server replication, but not when doing basically a copy-paste of one DB to another DB, and in that case we can drop them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文