python怎么操作mysql数据库
展开全部
#连接数据库
conn = MySQLdb.Connect(
host = 'localhost',
port = 3306,
user = 'root',
passwd = '',
db = 'mytest',
charset = 'utf8'
)
cursor = conn.cursor()
#创建一个表存储数据
sql_create = "create table if not exists account(nameid int, money varchar(100)) "
#插入两条数据
sql_insert1 = "insert into account(nameid,money) values(13,120)"
sql_insert2 = "insert into account(nameid,money) values(14,10)"
#执行上述sql语句
cursor.execute(sql_create)
cursor.execute(sql_insert1)
cursor.execute(sql_insert2)
conn.close()
python操作mysql数据库的完整demo与知识点讲解
http://blog.csdn.net/tangdou5682/article/details/52524036
conn = MySQLdb.Connect(
host = 'localhost',
port = 3306,
user = 'root',
passwd = '',
db = 'mytest',
charset = 'utf8'
)
cursor = conn.cursor()
#创建一个表存储数据
sql_create = "create table if not exists account(nameid int, money varchar(100)) "
#插入两条数据
sql_insert1 = "insert into account(nameid,money) values(13,120)"
sql_insert2 = "insert into account(nameid,money) values(14,10)"
#执行上述sql语句
cursor.execute(sql_create)
cursor.execute(sql_insert1)
cursor.execute(sql_insert2)
conn.close()
python操作mysql数据库的完整demo与知识点讲解
http://blog.csdn.net/tangdou5682/article/details/52524036
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询