python连接mysql数据库
2008-11-26 10:16
411 查看
看自己的机器有没有python
[root@localhost zn]#python -v //会进入python
Python 2.4.3 (#1, Dec 11 2006, 11:38:52)
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> //想要退出python 按键Ctrl+D
pythontest。py文件内容
#!/usr/bin/python
# imoprt MySQL module
import MySQLdb
#connect to the database
db=MySQLdb.connect(host="127.0.0.1",user="root",passwd="666666",db="cityman")
#get a cursor
cursor=db.cursor()
#sql statement
cursor.execute("insert into person values('','wangzhi','25','male')")
cursor.execute("select * from person")
#get the result set
result=cursor.fetchall()
#iterate thtough the result set
for i in result:
print(i)
cursor.close
回到终端
[root@localhost zn]# python python2mysql.py
python2mysql.py:9: Warning: Out of range value adjusted for column 'id' at row 1
cursor.execute("insert into person values('','wangzhi','25','male')")
(1L, 'liujun', 28L, 'male')
(2L, 'shenyang', 22L, 'fmale')
(3L, 'lizhiwei', 32L, 'male')
(4L, 'wangzhi', 25L, 'male')
执行成功
perl和python非常相像,这是我见过的最简练的两种语言,真的很棒。
不过上次看到csdn的文章说python的排名有所上升。而perl的却下降了,就我个人感觉用python确实比较简单易懂,但是目前没有太多的机会使用。老板比较偏向.net,自从他不做技术以后敏感度有所下降。God bless him。
[root@localhost zn]#python -v //会进入python
Python 2.4.3 (#1, Dec 11 2006, 11:38:52)
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> //想要退出python 按键Ctrl+D
pythontest。py文件内容
#!/usr/bin/python
# imoprt MySQL module
import MySQLdb
#connect to the database
db=MySQLdb.connect(host="127.0.0.1",user="root",passwd="666666",db="cityman")
#get a cursor
cursor=db.cursor()
#sql statement
cursor.execute("insert into person values('','wangzhi','25','male')")
cursor.execute("select * from person")
#get the result set
result=cursor.fetchall()
#iterate thtough the result set
for i in result:
print(i)
cursor.close
回到终端
[root@localhost zn]# python python2mysql.py
python2mysql.py:9: Warning: Out of range value adjusted for column 'id' at row 1
cursor.execute("insert into person values('','wangzhi','25','male')")
(1L, 'liujun', 28L, 'male')
(2L, 'shenyang', 22L, 'fmale')
(3L, 'lizhiwei', 32L, 'male')
(4L, 'wangzhi', 25L, 'male')
执行成功
perl和python非常相像,这是我见过的最简练的两种语言,真的很棒。
不过上次看到csdn的文章说python的排名有所上升。而perl的却下降了,就我个人感觉用python确实比较简单易懂,但是目前没有太多的机会使用。老板比较偏向.net,自从他不做技术以后敏感度有所下降。God bless him。
相关文章推荐
- Windows与Linux系统如何基于Python安装连接MySQL数据库的工具包PyMySQL
- Python3 pymysql连接MySQL数据库
- Python连接MySQL数据库
- python3连接mysql数据库及异常信息处理【Python入坑系列】
- python学习笔记(十四) - python连接mysql数据库
- python连接mysql数据库实战
- 解决Python2.7 连接MySQL数据库遇到'can't connect to MySQL server on 'localhost'(10061)'问题
- python mysql数据库连接及基本操作
- python连接MySQL数据库讲解
- Mac下python连接mysql数据库
- Python连接mysql数据库
- Python MySQLdb模块连接操作mysql数据库实例
- python连接mysql数据库
- python 远程连接MySQL数据库 拉取数据存至本地文件
- python3使用pymysql连接mysql数据库的大坑
- python——连接MySQL数据库
- python连接MYSql数据库python连接MYSql数据库 使用 MySQLdb
- 人工智能之Python18 用python3连接mysql数据库
- python 连接MYSQL数据库(入门帖)
- python3使用PyMysql连接mysql数据库实例