安装MySQL-python

本文介绍了使用yum命令快速安装MySQL-python的方法,适用于需要在Linux环境中连接MySQL数据库的开发者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最快速最简单方法:

yum install MySQL-python

[root@node2 python_lib]# yum install MySQL-python
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirror.bit.edu.cn
 * updates: mirrors.aliyun.com
base                                                                                                                                            | 3.7 kB     00:00     
extras                                                                                                                                          | 3.4 kB     00:00     
updates                                                                                                                                         | 3.4 kB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package MySQL-python.x86_64 0:1.2.3-0.3.c1.1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                                   Arch                                Version                                         Repository                         Size
=======================================================================================================================================================================
Installing:
 MySQL-python                              x86_64                              1.2.3-0.3.c1.1.el6                              base                               86 k

Transaction Summary
=======================================================================================================================================================================
Install       1 Package(s)

Total download size: 86 k
Installed size: 246 k
Is this ok [y/N]: y
Downloading Packages:
MySQL-python-1.2.3-0.3.c1.1.el6.x86_64.rpm                                                                                                      |  86 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64                                                                                                              1/1 
  Verifying  : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64                                                                                                              1/1 

Installed:
  MySQL-python.x86_64 0:1.2.3-0.3.c1.1.el6                                                                                                                             

Complete!

测试一下:

[root@node2 python_lib]# python
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> conn=MySQLdb.connect(host="172.16.73.50",user="root",passwd="root",db="sc_centaurus",charset="utf8")
>>> cursor = conn.cursor()
>>> cursor.execute("select * from tb_sys_component")
3L
>>> data = cursor.fetchall()
>>> for row in data:
...     print(row)
... 
(37L, 46L, 22000L, u'poseidon', 0L, None)
(38L, 47L, 23000L, u'centaurus', 0L, None)
(39L, 48L, 21001L, u'adapter01', 0L, None)
>>> cursor.close()
>>> conn.close()
>>> 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值