title: Create MySQLdb database using Python script
body: <p>I'm having troubles with creating a database and tables. The database needs to be created within a Python script. </p>
  
  <pre><code>#connect method has 4 parameters:
  #localhost (where mysql db is located), 
  #database user name, 
  #account password, 
  #database name    
  db1 = MS.connect(host="localhost",user="root",passwd="****",db="test")
  </code></pre>
  
  <p>returns </p>
  
  <pre><code>_mysql_exceptions.OperationalError: (1049, "Unknown database 'test'")
  </code></pre>
  
  <p>So clearly, the db1 needs to be created first, but how? I've tried CREATE before the connect() statement but get errors.</p>
  
  <p>Once the database is created, how do I create tables? 
  Thanks,
  Tom</p>
  
  <p>Here is the syntax, this works, at least the first time around. The second time naturally returns that the db already exists. Now to figure out how to use the drop command properly.</p>
  
  <pre><code>   db = MS.connect(host="localhost",user="root",passwd="****")
     db1 = db.cursor()
     db1.execute('CREATE DATABASE test1')
  </code></pre>
  
  <p>So this works great the first time through. The second time through provides a warning "db already exists". How to deal with this? The following is how I think it should work, but doesn't. OR should it be an if statement, looking for if it already exists, do not populate?</p>
  
  <pre><code>import warnings
  warnings.filterwarnings("ignore", "test1")
  </code></pre>