Home >Backend Development >Python Tutorial >python3连接Mairadb数据库

python3连接Mairadb数据库

WBOY
WBOYOriginal
2016-06-06 11:14:501314browse

#本代码演示的是python3.3.5下连接Mairadb数据库
import mysql.connector
config={'host':'192.168.14.101',#默认127.0.0.1
        'user':'person',
        'password':'123456',
        'port':3306 ,#默认即为3306
	#在这里如果默认是3306的话不需要也可以
        'database':'one',
        'charset':'utf8'#默认即为utf8
        }
try:
  cnn=mysql.connector.connect(**config)
  print('连接成功')
except mysql.connector.Error as e:
  print('connect fails!{}'.format(e))

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn