I'm having troubles with creating a database and tables. The database needs to be created within a Python script.
#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")
_mysql_exceptions.OperationalError: (1049, "Unknown database 'test'")
So clearly, the db1 needs to be created first, but how? I've tried CREATE before the connect() statement but get errors.
Once the database is created, how do I create tables?
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.
db = MS.connect(host="localhost",user="root",passwd="****") db1 = db.cursor() db1.execute('CREATE DATABASE test1')
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?
import warnings warnings.filterwarnings("ignore", "test1")