本文整理匯總了Python中mysql.connector.errorcode.ER_BAD_DB_ERROR屬性的典型用法代碼示例。如果您正苦於以下問題:Python errorcode.ER_BAD_DB_ERROR屬性的具體用法?Python errorcode.ER_BAD_DB_ERROR怎麽用?Python errorcode.ER_BAD_DB_ERROR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類mysql.connector.errorcode
的用法示例。
在下文中一共展示了errorcode.ER_BAD_DB_ERROR屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from mysql.connector import errorcode [as 別名]
# 或者: from mysql.connector.errorcode import ER_BAD_DB_ERROR [as 別名]
def __init__(self, user, password, database=None, verbose=LOG_OFF):
# passwd = input("Password > ")
# passwd = password
self._v = verbose
if database is not None:
self.database = database
try:
self.conn = maria.connect(user=user, password=password, database=self.database)
except maria.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
else:
try:
self.conn = maria.connect(user=user, password=password)
except maria.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
else:
print(err)
示例2: create_connection
# 需要導入模塊: from mysql.connector import errorcode [as 別名]
# 或者: from mysql.connector.errorcode import ER_BAD_DB_ERROR [as 別名]
def create_connection(database=None, user=None, password=None, port=None):
args = {}
option_files = list(filter(os.path.exists, map(os.path.abspath, map(os.path.expanduser, [
'/etc/my.cnf',
'~/.my.cnf',
]))))
if option_files:
args['option_files'] = option_files
if database:
args['database'] = database
if user:
args['user'] = user
if password:
args['password'] = password
if port:
args['port'] = port
cnx = None
try:
cnx = mysql.connector.connect(**args)
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
return cnx
示例3: ConnectToDatabase
# 需要導入模塊: from mysql.connector import errorcode [as 別名]
# 或者: from mysql.connector.errorcode import ER_BAD_DB_ERROR [as 別名]
def ConnectToDatabase(self):
try:
self.cnx.database = self.db
except mysql.connector.Error as err:
if err.errno == errorcode.ER_BAD_DB_ERROR:
self.CreateDatabase()
self.cnx.database = self.db
else:
print(err.msg)
示例4: connect
# 需要導入模塊: from mysql.connector import errorcode [as 別名]
# 或者: from mysql.connector.errorcode import ER_BAD_DB_ERROR [as 別名]
def connect(self):
"""
Creates connection to database, sets connection and cursor
Connection to database can be loosed,
if that happens you can use this function to reconnect to database
"""
if self.engine == "mysql":
found_connector = False
try:
# Import official mysql connector if exists
import mysql.connector as mysql_module
from mysql.connector import errorcode
found_connector = True
except ImportError:
pass
if not found_connector:
# Check MySQLdb as secondary option
try:
import MySQLdb as mysql_module
except ImportError:
raise ValueError(
'Please, install mysql-connector or mysqlclient module before using this library.'
)
# Connect to db
try:
self.connection = mysql_module.connect(**self.settings)
except mysql_module.Error as err:
if found_connector:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
raise ValueError("Wrong credentials, ACCESS DENIED")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
raise ValueError(
"Database %s does not exists" % (self.settings['database'])
)
else:
raise ValueError(err)
# @TODO Add detailed errors for MySQLdb
raise err
elif self.engine == "postgres":
try:
import psycopg2
except ImportError:
raise ValueError(
'Please, install psycopg2 module before using plugin.'
)
self.connection = psycopg2.connect(**self.settings)
else:
raise NotImplementedError(
"Database engine %s not implemented!" % self.engine
)
self.cursor = self.connection.cursor()