在 MySQL 中创建数据库

  1. import mysql.connector
  2.  
  3. mydb = mysql.connector.connect(
  4. host="localhost",
  5. user="myusername",
  6. passwd="mypassword"
  7. )
  8.  
  9. mycursor = mydb.cursor()
  10.  
  11. mycursor.execute("CREATE DATABASE mydatabase")
  12.  
  13. #If this page is executed with no error, you have successfully created a database.