def create_db(dbip,dbport,dbuser,dbpass,dbname): """ 创建用户数据库 @param dbip:待创建数据库ip @param dbport:待创建数据库端口 @param dbuser:待创建数据库用户 @param dbpass:待创建数据库密码 @param dbname:待创建数据库表 """ schema_db_conn=DBInstance(db_host=dbip, db_port=dbport, db_name='information_schema', db_username=dbuser, db_password=dbpass) schema_db_conn.init() sql = 'create database if not exists %s CHARACTER SET utf8 '%dbname schema_db_conn.read_schema(sql) return MysqlUtil.check_db_exist(dbip, dbport, dbuser, dbpass, dbname)
def check_db_exist(dbip,dbport,dbuser,dbpass,dbname): """ 检查数据库表是否存在 @param dbip:待检查数据库ip @param dbport:待检查数据库端口 @param dbuser:待检查数据库用户 @param dbpass:待检查数据库密码 @param dbname:待检查数据库表 """ schema_db_conn=DBInstance(db_host=dbip, db_port=dbport, db_name='information_schema', db_username=dbuser, db_password=dbpass) schema_db_conn.init() sql = "SELECT SCHEMA_NAME FROM SCHEMATA where SCHEMA_NAME = '%s'"%dbname ret = schema_db_conn.read_schema(sql) return ret
def check_db_exist(dbip, dbport, dbuser, dbpass, dbname): """ 检查数据库表是否存在 @param dbip:待检查数据库ip @param dbport:待检查数据库端口 @param dbuser:待检查数据库用户 @param dbpass:待检查数据库密码 @param dbname:待检查数据库表 """ schema_db_conn = DBInstance(db_host=dbip, db_port=dbport, db_name='information_schema', db_username=dbuser, db_password=dbpass) schema_db_conn.init() sql = "SELECT SCHEMA_NAME FROM SCHEMATA where SCHEMA_NAME = '%s'" % dbname ret = schema_db_conn.read_schema(sql) return ret
def create_db(dbip, dbport, dbuser, dbpass, dbname): """ 创建用户数据库 @param dbip:待创建数据库ip @param dbport:待创建数据库端口 @param dbuser:待创建数据库用户 @param dbpass:待创建数据库密码 @param dbname:待创建数据库表 """ schema_db_conn = DBInstance(db_host=dbip, db_port=dbport, db_name='information_schema', db_username=dbuser, db_password=dbpass) schema_db_conn.init() sql = 'create database if not exists %s CHARACTER SET utf8 ' % dbname schema_db_conn.read_schema(sql) return MysqlUtil.check_db_exist(dbip, dbport, dbuser, dbpass, dbname)