为什么我的 mysqldb 代码不工作?没有错误信息,没有数据

Why my mysqldb code is not working? No error message, no data

我编写了一个网络抓取脚本,将其保存到 excel 文件中,然后将此 excel 文件上传到我的 MySQL 数据库服务器。我没有收到任何错误消息,但是 table 在 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) 

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