1.存在莫數據庫,則刪除創建一個新庫
drop database if exists `tpm_business`;
CREATE DATABASE tpm_business DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
操作如圖,先刪后建數據庫
2.不存在某數據庫,則創建
CREATE DATABASE if not exists tpm_business DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
3.存在某表,先刪除再創建
DROP TABLE IF EXISTS `sys_auth`;
CREATE TABLE if not exists `sys_auth` (
`authorizer_id` bigint(20) NOT NULL COMMENT '授權對象id', `role_id` bigint(20) NOT NULL COMMENT '角色id' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='授權表';
4.不存在某表,則創建
CREATE TABLE if not exists `sys_auth` ( `authorizer_id` bigint(20) NOT NULL COMMENT '授權對象id', `role_id` bigint(20) NOT NULL COMMENT '角色id' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='授權表';
有同學如果執行出錯,應該是數據庫版本的問題本例子是在 mysql5.7.27版本運行,版本5.6以下的可能報錯,請注意調整