【问题标题】:Why my mysqldb code is not working? No error message, no data为什么我的 mysqldb 代码不起作用?没有错误信息,没有数据
【发布时间】:2018-02-23 10:56:44
【问题描述】:

我编写了一个网页抓取脚本,将其保存到一个 excel 文件中,然后将此 excel 文件上传到我的 MySQL 数据库服务器。我没有收到任何错误消息,但 MySQL 中的表是空的。为什么?我怎么了?

这里是mysqldb部分:

    connection = MySQLdb.connect(host='localhost',
        user='root',
        passwd='',
        db='database1')
    cursor = connection.cursor()
    query = """ load data local infile '/usr/src/Python-2.7.13/output.csv' 
    into table ARRIVALS
    character set latin1
    fields terminated by ';'
    enclosed by '"'
    lines terminated by '\r\n'
    ignore 1 lines;
    """
    cursor.execute(query)
    connection.commit()
    cursor.close()

    time.sleep(30) 

【问题讨论】:

    标签: python linux web-scraping debian mysql-python


    【解决方案1】:

    如果您在 linux 中工作,并且文件是在 linux 中编写的,则换行符应该是 \n 而不是 \r\n。这可能会导致您的文件被读取为单行,这将被忽略,如您的查询中指定的那样

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-08
      • 2018-12-22
      • 2016-04-18
      • 2020-07-23
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 2016-09-18
      相关资源
      最近更新 更多