在 Ubuntu (20.04) VPS 上运行 MySQL (8.0) 数据库。我当前的目标是尝试通过 Python 脚本将 .CSV 文件自动加载到表格中。该脚本在理论上是正确的并且应该可以工作,它能够将数据从 CSV 处理到表中。dbupdate.py:import mysql.connectorimport osimport stringdb = mysql.connector.connect ( host="localhost", user="root", passwd="********", db="Rack_Info")sqlLoadData = "LOAD DATA LOCAL INFILE '/home/OSA_ADVA_Dashboard/Processed_CSV/DownloadedCSV.csv' INTO TABLE BerT FIELDS TERMINATED BY ',' ENCLOSED BY '*' IGNORE 1 LINES;"try: curs = db.cursor() curs.execute(sqlLoadData) db.commit() print ("SQL execution complete") resultSet = curs.fetchall()except IOError: print ("Error incurred: ") db.rollback() db.close()print ("Data loading complete.\n")我查阅了官方文档并在服务器和客户端上启用了 local_infile,配置了 my.cnf 和 SQL。my.cnf 文件:## The MySQL database server configuration file.## You can copy this to one of:# - "/etc/mysql/my.cnf" to set global options,# - "~/.my.cnf" to set user-specific options.## One can use all long options that the program supports.# Run program with --help to get a list of available options and with# --print-defaults to see which it would actually understand and use.## For explanations see# http://dev.mysql.com/doc/mysql/en/server-system-variables.html## * IMPORTANT: Additional settings that can override those from this file!# The files must end with '.cnf', otherwise they'll be ignored.#!includedir /etc/mysql/conf.d/!includedir /etc/mysql/mysql.conf.d/[client]local_infile=1[mysql]local_infile=1[mysqld]local_infile=1我已经重新启动了 php 和 MySQL 服务,但都无济于事,服务器也是如此。不知所措。任何帮助将非常感激。
2 回答
幕布斯6054654
TA贡献1876条经验 获得超7个赞
我调查了 php.ini 文件并取消了加载数据行的注释,但仍然没有。
结果是 mysqld 的变量之一 secure_file_priv 指向一个空/默认目录。我所要做的就是将目录更改为我的文件所在的位置。现在都在工作。
添加回答
举报
0/150
提交
取消
