I have the following lines of code:
sql = \"source C:\\\\My Dropbox\\\\workspace\\\\projects\\\\hosted_inv\\\\create_site_db.sql\"
cursor.execute (sql)
The source command is one of the built-in commands recognized only by the mysql command-line client. It is not supported as a statement you can execute via any API.
Some people think you can simply split an SQL script file on the ";" statement terminator and call execute() on each line you get. But there are numerous exception cases:
CONNECT, SOURCE, CHARSET, WARNINGS, QUIT, etc.; for example DELIMITER.; but not as a terminator, like CREATE TRIGGER.; inside string literals or comments or even quoted identifiers.To load an SQL script programmatically, you'd have to duplicate a fair amount of the functionality of the mysql client. So it's best if you just fork a process to actually execute that client program with the script as input.
See also: