load CSV

can i load csv file into mysql db?

Yes. and

How can i do this within a python script rather than a Bash console? I have csv files in /home/user/dir and i want to load them into MySQL in an automated way each day.

@enderwigg I'm sure you can schedule a task. :]

Create a bash file somewhere and put your commands into the file. Then visit the schedule tab and point the location to your file.

Just to expand on what @EndenDragon (correctly!) said -- you can do this from a bash script (don't forget to use chmod +x to make it executable before scheduling it) or, if you prefer, you can write a Python script using the Python csv module to read the file, and the MySQL module of your choice to write to the database. Either of those can be scheduled on the "Schedule" tab -- it's not only Python scripts that can be scheduled.


I want to load data unto the web application for the user to read. I had used this code to do so: csv_file = csv.reader(open('')) next(csv_file). However, as I run this code it gives me a syntax error. How can I solve the problem?

Regards Josiah Gumede

what version of python are you running it with? and also is next(csv_file) in the same line as the previous code?

I am running with version 3.6.

can you show the full error stack trace?

Here is the full error stack trace: File "/home/JosiahVS/mysite/", line 5 upsets = 0 non_upset = 0 ^ SyntaxError: invalid syntax

I don't understand this error: File "/home/JosiahVS/mysite/", line 37 export APP_CONFIG_FILE=/var/www/yourapp/config/ ^ SyntaxError: invalid syntax

Should I get rid of the underscore so to combine the code or just change the Python I am using?

That looks like you have non-Python code inside a Python file. The line

 export APP_CONFIG_FILE=/var/www/yourapp/config/ in the Bash shell script syntax, so Python can't understand it.

Similarly, if you have a line in your file that goes like this:

upsets = 0 non_upset = 0

...then that isn't valid Python -- it looks like it's two lines run together.