mysqlimport:错误:1045,访问被拒绝
有谁知道为什么我在运行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以通过使用 mysqlimport 的 --local 参数来避免需要额外的权限:
You can avoid the need for the extra privileges by using the --local parameter to mysqlimport:
好吧,事实证明 FILE 权限是一个“全局”权限,这显然意味着你不能有选择地在某些数据库、表上启用它。这就是为什么我之前对 bar.* 的授予语句没有效果:
您需要授予
*.*
上的 FILE 权限:希望这对某人有帮助。
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:
You need to grant FILE privileges on
*.*
:Hope this helps someone.
有些人会选择此命令,跳过额外的 FILE 授予。
mysql -u 用户名 -p; <你的文件.sql
Some would instead opt for this command, skipping the extra FILE grant.
mysql -u username -p <yourdbname> < yourfile.sql
mysqlimport 是 LOAD DATA INFILE 语句的命令行接口,为此您需要“FILE”权限(服务器级别)。
来自 LOAD DATA INFILE 语法:
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:
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 singleCREATE TABLE
statement, and see if it runs.If it runs, then these are things that you want to remove from your SQL import file:
@@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.