我试图用MySQL和pythonmysql连接器初始化我的数据库。
运行下面的代码后,我收到以下异常:mysql.connector.errors.DatabaseError: 2014 (HY000): Commands out of sync; you can't run this command now
我尝试了几件事,包括提交连接对象,但没有什么对我有效。在def initialization():
cnx = mysql.connector.connect(user="root", password="xxxxxxxxx", host='127.0.0.1')
cursor = cnx.cursor()
cursor.execute("CREATE DATABASE IF NOT EXISTS izugitdb;")
cursor.execute("USE izugitdb;")
cursor.execute("CREATE TABLE IF NOT EXISTS employee_users (user_id INT AUTO_INCREMENT PRIMARY KEY,username VARCHAR(40) NOT NULL, password VARCHAR(40) NOT NULL,isadmin TINYINT(1) DEFAULT 0 NOT NULL);")
cursor.execute("CREATE TABLE IF NOT EXISTS clients (client_id INT AUTO_INCREMENT PRIMARY KEY,client_name VARCHAR(255) NOT NULL); ENGINE = InnoDB;")
cursor.execute("CREATE TABLE IF NOT EXISTS clients_workers (id INT AUTO_INCREMENT PRIMARY KEY, worker_id INT ,worker_name VARCHAR(255) NOT NULL, client_id INT);")