简体   繁体   English

使用Python和Odo模块在mysql上加载csv时出错

[英]Error when loading csv on mysql using Python and odo module

I decided to try odo for handling my csv data because it supposedly is way faster than doing it with pandas, but I can't make it work. 我决定尝试使用odo来处理我的csv数据,因为它据说比用熊猫来处理要快得多,但是我无法使其工作。

This is their documentation about migrating a 30gb csv file to a MySQL database: 这是他们关于将30gb csv文件迁移到MySQL数据库的文档:

In [1]: %time t = odo('all.csv', 'mysql+pymysql://localhost/test::nyc')
CPU times: user 1.32 s, sys: 304 ms, total: 1.63 s
Wall time: 20min 49s

I tried the same in my local MySQL instance on my OS X El Capitan but it gives me the following error: 我在OS X El Capitan的本地MySQL实例中尝试了相同的操作,但它给了我以下错误:

/Library/Python/2.7/site-packages/PyMySQL-0.7.1-py2.7.egg/pymysql/err.pyc in _check_mysql_exception(errinfo)
    113 
    114     # couldn't find the right error number
--> 115     raise InternalError(errno, errorvalue)
    116 
    117 

InternalError: (pymysql.err.InternalError) (13, u"Can't get stat of '/path/to/test.csv' (Errcode: 13 - Permission denied)") [SQL: u'LOAD DATA  INFILE %(path)s\n            INTO TABLE test_file2\n            CHARACTER SET %(encoding)s\n            FIELDS\n                TERMINATED BY %(delimiter)s\n                ENCLOSED BY %(quotechar)s\n                ESCAPED BY %(escapechar)s\n            LINES TERMINATED BY %(lineterminator)s\n            IGNORE %(skiprows)s LINES\n            '] [parameters: {'escapechar': '\\', 'encoding': 'utf8', 'skiprows': 1, 'delimiter': ',', 'lineterminator': u'\n', 'quotechar': '"', 'path': '/path/to/test.csv'}]

At first, I thought it was an error with file permissions, but then I discovered that the table is created successfully and with the right column names, so odo is able to access the file. 起初,我以为文件许可权是一个错误,但是后来我发现该表已成功创建并且具有正确的列名,因此odo能够访问该文件。 So, I don't really understand the error (13, u"Can't get stat of '/path/to/test.csv' (Errcode: 13 - Permission denied)") 因此,我不太了解该错误(13, u"Can't get stat of '/path/to/test.csv' (Errcode: 13 - Permission denied)")

What else can I check? 我还能检查什么?

Well, it was because MySQL couldn't access the file. 好吧,这是因为MySQL无法访问该文件。 It seems that it needs to be inside the mysql installation folder, which in my case was /usr/local/mysql-5.6.20-osx10.7-x86_64/ . 看来它应该在mysql安装文件夹中,在我的情况下是/usr/local/mysql-5.6.20-osx10.7-x86_64/

I tried to put it inside the data folder, /usr/local/mysql-5.6.20-osx10.7-x86_64/data/my_db and that didn't work out. 我试图将其放在数据文件夹/usr/local/mysql-5.6.20-osx10.7-x86_64/data/my_db ,但没有解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM