python create a database operation

python create a database operation

# ! / Usr / bin / python3 
# - * - Coding: UTF-8 - * - 
# @time: 2019/12/23 14:01 
"" " 
. All privileges ON * * Grant to 'bkuser' @ '%' identified by 'bkuserpwd'; 
reference: HTTPS: //blog.csdn.net/kongsuhongbaby/article/details/84948205 
"" " 
" "" create a database "" " 
Import pymysql
 # open database connectivity, do not need to specify the database, because We need to create a database 
conn = pymysql.connect ( ' 10.10.50.60 ' , the User = ' bkuser ' , password = ' bkuserpwd ')
 # Get a cursor on 
the Cursor = conn.cursor ()
 # Create a database pythpdb
cursor.execute ( " the CREATE DATABASE IF the NOT EXISTS pythondb " ) 
cursor.close () # turn off the cursor 
conn.Close () # and then close the database connection 
Print ( ' Creating a database pythonBD success ' )

Guess you like

Origin www.cnblogs.com/bjx2020/p/12083688.html