在 Ubuntu (20.04) VPS 上運(yùn)行 MySQL (8.0) 數(shù)據(jù)庫。我當(dāng)前的目標(biāo)是嘗試通過 Python 腳本將 .CSV 文件自動(dòng)加載到表格中。該腳本在理論上是正確的并且應(yīng)該可以工作,它能夠?qū)?shù)據(jù)從 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")我查閱了官方文檔并在服務(wù)器和客戶端上啟用了 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我已經(jīng)重新啟動(dòng)了 php 和 MySQL 服務(wù),但都無濟(jì)于事,服務(wù)器也是如此。不知所措。任何幫助將非常感激。
2 回答

幕布斯6054654
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超7個(gè)贊
我調(diào)查了 php.ini 文件并取消了加載數(shù)據(jù)行的注釋,但仍然沒有。
結(jié)果是 mysqld 的變量之一 secure_file_priv 指向一個(gè)空/默認(rèn)目錄。我所要做的就是將目錄更改為我的文件所在的位置。現(xiàn)在都在工作。

慕婉清6462132
TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超2個(gè)贊
如果我沒記錯(cuò)的話,php 有自己的配置文件,你必須在其中啟用加載數(shù)據(jù)本地 infile
添加回答
舉報(bào)
0/150
提交
取消