import pymysql
from pymysql import Error

def create_table(connection):

create_table_sql = """
CREATE TABLE IF NOT EXISTS `auth_group_permissions` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `group_id` INT(11) NOT NULL,
    `permission_id` INT(11) NOT NULL,
    PRIMARY KEY (`id`),
    CONSTRAINT `auth_group_permissions_group_id_permission_id_0cd325b0_uniq` UNIQUE KEY (`group_id`, `permission_id`),
    CONSTRAINT `auth_group_permissions_group_id_b120cbf9_fk_auth_group_id` FOREIGN KEY (`group_id`) REFERENCES `auth_group` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
    CONSTRAINT `auth_group_permissio_permission_id_84c5c92e_fk_auth_perm` FOREIGN KEY (`permission_id`) REFERENCES `auth_permission` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
"""
try:
    with connection.cursor() as cursor:
        cursor.execute(create_table_sql)
        connection.commit()
        print("Table created successfully")
except Error as e:
    print(f"Error: '{e}' occurred")
    connection.rollback()

def main():

connection_config_dict = {
    'host': '172.23.119.14',
    'port': 2883,
    'user': 'cap@AIPro_test#obtest00',
    'password': 'capCAP12!@',
    'database': 'ai_admin',
}

try:
    connection = pymysql.connect(**connection_config_dict)
    print("Connected to MySQL database 'ai_admin'")
    create_table(connection)
except Error as e:
    print(f"Error: '{e}' occurred")
finally:
    connection.close()
    print("MySQL connection is closed")

if name == "__main__":

main()
最后修改:2024 年 04 月 08 日
如果觉得我的文章对你有用,请随意赞赏