创建表

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