1.安装系统包
[root@localhost python_script]# yum install MySQL-python
2.脚本
-
import MySQLdb
-
conn= MySQLdb.connect(
-
host='192.168.1.118',
-
port = 8066,
-
user='root',
-
passwd='mysql',
-
db ='devdb',
-
)
-
cur = conn.cursor()
-
cur.execute("insert into tb_test(id,name) values(1,'python')")
-
conn.commit()
3.运行
[root@localhost python_script]# python insert.py
阅读(2948) | 评论(0) | 转发(0) |