How would I do the following?
conn = MySQLdb.connect (
host = settings.DATABASES['default']['HOST'],
port = 3306,
user = settings.DATABASES['default']['USER'],
passwd = settings.DATABASES['default']['PASSWORD'],
db = settings.DATABASES['default']['NAME'],
cursor = conn.cursor()
cursor.execute('SELECT COUNT(*) FROM auth_user')
print cursor.fetchall() # this prints, so I know the connection is correct
LOAD DATA INFILE 'a_short.csv' INTO TABLE export
FIELDS TERMINATED BY '|' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;
In order for
load file to work your database user account needs MySQL's
file_priv. The database also needs to have read permissions on the file in question.
In this query the database is instructed to look for
a_short.csv on the database's filsystem, which will probably produce a path like:
/var/mysql/a_short.csv. If this csv file is on the python side of the system, then python needs to open the file and populate the MySQL database.