title: Follow up: Execute .sql files from python
body: <p>Over a year ago someone asked this question: <a href="https://stackoverflow.com/questions/5174269/execute-sql-files-that-are-used-to-run-in-sql-management-studio-in-python">Execute .sql files that are used to run in SQL Management Studio in python</a>.</p>
  
  <p>I am writing a script in python that connects to a SQL server and creates and populates a database based on SQL commands in a large (several GBs) .sql file.</p>
  
  <p>It looks like SQLCMD requires a download and install of SQL Server Express. Are there other ways to execute a .sql file from python without requiring everyone who uses my script to download and install SQL Server? Does pyodbc have this capability?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here's another similar question:
  <a href="https://stackoverflow.com/questions/4408714/execute-sql-file-with-python-mysqldb">execute *.sql file with python MySQLdb</a></p>
  
  <p>Here, again, the solution is to call a utility from command (in this case, mysql.exe) with the file listed as an argument.</p>
  
  <p>It seems to me that there should be a way to do this using one of Python's DB API libraries, but I haven't found it so I'm looking for an *.exe like SQLCMD or MYSQL that I can use to run the file from command line.</p>
  
  <p>P.S. Please feel free to correct me if I'm not looking at this correctly. Maybe the code below is just as efficient as running from command line:</p>
  
  <pre><code>for line in open('query.sql','r'):
      cursor.execute(line)
  </code></pre>