Python MySQL-本地加载数据
在Ubuntu(20.04)VPS上运行MySQL(8.0)数据库。我目前的目标是通过Python脚本将.CSV自动加载到表中。该脚本在理论上是正确的,应该可以工作,它能够将CSV中的数据处理到表中 dbupdate.py:Python MySQL-本地加载数据,python,mysql,linux,ubuntu,Python,Mysql,Linux,Ubuntu,在Ubuntu(20.04)VPS上运行MySQL(8.0)数据库。我目前的目标是通过Python脚本将.CSV自动加载到表中。该脚本在理论上是正确的,应该可以工作,它能够将CSV中的数据处理到表中 dbupdate.py: import mysql.connector import os import string db = mysql.connector.connect ( host="localhost", user="root"
import mysql.connector
import os
import string
db = 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")
我查阅了官方文档并在服务器和客户端上启用了本地加密,配置了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服务,但都没有用,服务器也没有用。不知该怎么办。任何帮助都将不胜感激。如果我没有弄错的话,php有自己的配置文件,您必须在其中启用加载数据本地填充我调查了php.ini文件并取消了加载数据行的注释,仍然没有任何内容 原来mysqld的变量secure_file_priv指向一个空/默认目录。我所要做的就是将目录更改为文件所在的位置。现在都在工作