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

python3连接Mairadb数据库

WBOY
Release: 2016-06-06 11:14:50
Original
1312 people have browsed it

#本代码演示的是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))
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template