如何“将数据加载到文件中”在亚马逊 RDS 上?

发布于 2024-08-09 17:58:36 字数 1232 浏览 6 评论 0原文

不确定这是否是一个更适合服务器故障的问题,但我最近一直在搞乱亚马逊 RDS,并且在为我的网络主机 mysql 用户获取“文件”权限时遇到问题。

我假设一个简单的:

grant file on *.* to 'webuser@'%';

可以工作,但事实并非如此,而且我似乎也无法对我的“root”用户执行此操作。什么给?我们使用加载数据的原因是因为它一次执行数千个插入的速度非常快。

有人知道如何解决这个问题还是我需要找到不同的方法?

此页面 http://docs.amazonwebservices.com/ AmazonRDS/latest/DeveloperGuide/index.html?Concepts.DBInstance.html 似乎表明我需要找到一种不同的方法来解决这个问题。

帮助?

更新 我不想导入数据库——我只是想使用文件加载选项一次插入数十万行。

深入研究后,我们得到的是:

 mysql> grant file on *.* to 'devuser'@'%';
 ERROR 1045 (28000): Access denied for user 'root'@'%' (using password: YES)


 mysql> select User, File_priv, Grant_priv, Super_priv from mysql.user;
 +----------+-----------+------------+------------+
 | User     | File_priv | Grant_priv | Super_priv |
 +----------+-----------+------------+------------+
 | rdsadmin | Y         | Y          | Y          |
 | root     | N         | Y          | N          |
 | devuser  | N         | N          | N          |
 +----------+-----------+------------+------------+

not sure if this is a question better suited for serverfault but I've been messing with amazon RDS lately and was having trouble getting 'file' privileges to my web host mysql user.

I'd assume that a simple:

grant file on *.* to 'webuser@'%';

would work but it does not and I can't seem to do it with my 'root' user as well. What gives? The reason we use load data is because it is super super fast for doing thousands of inserts at once.

anyone know how to remedy this or do I need to find a different way?

This page, http://docs.amazonwebservices.com/AmazonRDS/latest/DeveloperGuide/index.html?Concepts.DBInstance.html seems to suggest that I need to find a different way around this.

Help?

UPDATE
I'm not trying to import a database -- I just want to use the file load option to insert several hundred-thousand rows at a time.

after digging around this is what we have:

 mysql> grant file on *.* to 'devuser'@'%';
 ERROR 1045 (28000): Access denied for user 'root'@'%' (using password: YES)


 mysql> select User, File_priv, Grant_priv, Super_priv from mysql.user;
 +----------+-----------+------------+------------+
 | User     | File_priv | Grant_priv | Super_priv |
 +----------+-----------+------------+------------+
 | rdsadmin | Y         | Y          | Y          |
 | root     | N         | Y          | N          |
 | devuser  | N         | N          | N          |
 +----------+-----------+------------+------------+

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

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

发布评论

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

评论(6

追星践月 2024-08-16 17:58:36

您需要使用 LOAD DATA LOCAL INFILE ,因为该文件不在 MySQL 服务器上,而是在您运行命令的计算机上。

根据下面的评论,您可能还需要包含该标志:

--local-infile=1

You need to use LOAD DATA LOCAL INFILE as the file is not on the MySQL server, but is on the machine you are running the command from.

As per comment below you may also need to include the flag:

--local-infile=1
魔法唧唧 2024-08-16 17:58:36

也遇到了这个问题,尝试在 Windows 上使用 MySQL Workbench 将 .csv 数据从我的本地计算机上传到 AWS RDS 实例。

我需要的添加是在以下位置添加 OPT_LOCAL_INFILE=1:Connection >高级>其他的。注意需要使用 CAPS。

我在 AWS 开发者论坛中找到了 PeterMag 的答案


更多信息:

SHOW VARIABLES LIKE 'local_infile'; 已返回 ON
查询是:

LOAD DATA LOCAL INFILE 'filepath/file.csv' 
    INTO TABLE `table_name`
    FIELDS TERMINATED BY ',' 
    ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
    IGNORE 1 ROWS;

从上面引用的答案源复制:

显然这是 MYSQL Workbench V8.X 中的一个错误。除了
本线程前面显示的配置,您还需要更改
Workbench中的MYSQL连接如下:

  1. 转到 MYSQL 的欢迎页面,其中显示了您的所有连接
  2. 选择“管理服务器连接”(小扳手图标)
  3. 选择您的连接
  4. 选择“高级”选项卡
  5. 在“其他”框中,添加 OPT_LOCAL_INFILE=1

现在我可以在 MYSQL RDS 上使用 LOAD DATA LOCAL INFILE 查询。它似乎
不需要 File_priv 权限。*

Also struggled with this issue, trying to upload .csv data into AWS RDS instance from my local machine using MySQL Workbench on Windows.

The addition I needed was adding OPT_LOCAL_INFILE=1 in: Connection > Advanced > Others. Note CAPS was required.

I found this answer by PeterMag in AWS Developer Forums.


For further info:

SHOW VARIABLES LIKE 'local_infile'; already returned ON
and the query was:

LOAD DATA LOCAL INFILE 'filepath/file.csv' 
    INTO TABLE `table_name`
    FIELDS TERMINATED BY ',' 
    ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
    IGNORE 1 ROWS;

Copying from the answer source referenced above:

Apparently this is a bug in MYSQL Workbench V8.X. In addition to the
configurations shown earlier in this thread, you also need to change
the MYSQL Connection in Workbench as follows:

  1. Go to the Welcome page of MYSQL which displays all your connections
  2. Select Manage Server Connections (the little spanner icon)
  3. Select your connection
  4. Select Advanced tab
  5. In the Others box, add OPT_LOCAL_INFILE=1

Now I can use the LOAD DATA LOCAL INFILE query on MYSQL RDS. It seems
that the File_priv permission is not required.*

眼中杀气 2024-08-16 17:58:36

无论它的价值如何......您可以将 LOCAL 操作数添加到 LOAD DATA INFILE 而不是使用 mysqlimport 来解决此问题。

LOAD DATA LOCAL INFILE ...

这无需授予 FILE 权限即可工作。

For whatever it's worth... You can add the LOCAL operand to the LOAD DATA INFILE instead of using mysqlimport to get around this problem.

LOAD DATA LOCAL INFILE ...

This will work without granting FILE permissions.

旧话新听 2024-08-16 17:58:36

很确定您还不能做到这一点,因为您没有 RDS 的最高级别 MySQL 权限。我们只做了一些测试,但导入数据库的最简单方法似乎是从源框中通过管道传输它,例如

mysqldump MYDB | mysql -h rds-amazon-blah.com --user=youruser --pass=thepass

Pretty sure you can't do it yet, as you don't have the highest level MySQL privileges with RDS. We've only done a little testing, but the easiest way to import a database seems to be to pipe it from the source box, e.g.

mysqldump MYDB | mysql -h rds-amazon-blah.com --user=youruser --pass=thepass
纸伞微斜 2024-08-16 17:58:36

有两种方法可以将批量数据导入 Amazon MySQL RDS。您可以根据您的方便选择以下任何一个。

  1. 使用导入实用程序。

    mysqlimport --local --compress -u <用户名>; -p<密码> -h <主机地址> <数据库名称> --fields-termminated-by=',' TEST_TABLE.csv
    --确保实用程序仅将数据插入到 TEST_TABLE 中。
    
  2. 通过管道进入 mysql 命令发送批量插入 SQL。

    mysql -u <用户名>; -p<密码> -h <主机地址> <数据库名称> <测试表插入.SQL
    --这里文件 TEST_TABLE_INSERT.SQL 将具有批量导入 sql 语句,如下所示
    --插入 TEST_TABLE 值('1','test1','2017-09-08'),('2','test2','2017-09-08'),('3','test3' ,'2017-09-08'),('3','test3','2017-09-08');
    

Importing bulk data into Amazon MySQL RDS is possible two ways. You could choose anyone of below as per your convenience.

  1. Using Import utility.

    mysqlimport --local --compress  -u <user-name> -p<password> -h <host-address> <database-name> --fields-terminated-by=',' TEST_TABLE.csv
    --Make sure, here the utility will be inserting the data into TEST_TABLE only.
    
  2. Sending a bulk insert SQL by piping into into mysql command.

    mysql -u <user-name> -p<password> -h <host-address> <database-name> < TEST_TABLE_INSERT.SQL
    --Here file TEST_TABLE_INSERT.SQL will have bulk import sql statement like below
    --insert into TEST_TABLE values('1','test1','2017-09-08'),('2','test2','2017-09-08'),('3','test3','2017-09-08'),('3','test3','2017-09-08');
    
陈年往事 2024-08-16 17:58:36

我遇到了类似的问题。事实上,我试图导入数据库,但条件应该是相同的 - 由于某些表的大小、不稳定的连接以及对适度恢复功能的渴望,我需要使用加载数据。

我同意 chris finne 的观点,即不指定本地选项可能会导致该错误。经过多次调整和启动后,我发现 Maatkit 提供了 mk-parallel-restore 工具我需要一些优秀的附加功能。它可能非常适合您的用例。

I ran into similar issues. I was in fact trying to import a database but the conditions should be the same - I needed to use load data due to the size of some tables, a spotty connection, and the desire for a modest resume functionality.

I agree with chris finne that not specifying the local option can lead to that error. After many fits and starts I found that the mk-parallel-restore tool from Maatkit provided what I needed with some excellent extra features. It might be a great match for your use case.

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