Install MySQL-python to connect MySQL
2015-01-25 00:00
281 查看
# yum -y install MySQL-python
运行上面的命令即可安装centos7自带的rpm安装包,但是默认的是为python2.*安装
连接MySQL小Demo
运行上面的命令即可安装centos7自带的rpm安装包,但是默认的是为python2.*安装
连接MySQL小Demo
#-*- encoding:UTF-8 -*- import os, sys, string import MySQLdb try: conn = MySQLdb.connect(host="localhost", user="root", passwd="123456",db="mydatabase") except Exception, e: print e; sys.exit() #Get cursor obj to operator database cursor = conn.cursor() sql = "create table if not exists test(name varchar(128) primary key, age int(3))" cursor.execute(sql) #insert data to db sql = "insert into test(name, age) values ('%s', %d)" % ("coode", 25) sql2 = "insert into test(name, age) values ('%s', %d)" % ("Ben", 19) try: cursor.execute(sql) conn.commit(); cursor.execute(sql2) conn.commit() except Exception, e: print e #select data from db sql = "select * from test" cursor.execute(sql) result = cursor.fetchall() #the result is a list if result: for rs in result: print rs[0], rs[1] cursor.close() conn.close()
相关文章推荐
- Install MySQL-python to connect MySQL
- python MySQLdb连接MySQL数据库报错(2003, "Can't connect to MySQL server on 'localhost' (10061)")解决办法
- 运行python manage.py syncdb时出现“cannot connect to MySQL server on 'localhost'”的解决方法
- python pip install 失败原因之ProxyError('Cannot connect to proxy.
- 解决Python2.7 连接MySQL数据库遇到'can't connect to MySQL server on 'localhost'(10061)'问题
- mysql-Can\'t connect to MySQL server on \'127.0.0.1\' (10061) (code 2003)"): error calling Python mo
- Python报错-(2003 Can t connect to MySQL server on 127.0.0.1)
- windows下用Python连接mysql报错问题“MySQLdb in Python: “Can't connect to MySQL server on 'localhost'””
- centos howto yum install mysql-python
- Ubuntu install mysql-connector-java for java to connect MySQL database
- using DTP to connect to MySQL
- How to install new version of mysql
- ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL
- null, message from server: "Host ***" is not allowed to connect to this MySQL server"
- MySQL:ERROR 2003:Can't connect to MySQL server on 'localhost'
- Can't connect to local MySQL server through socket 问题解决
- Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’解决方法
- 出现Fatal error: Call to undefined function mysql_connect()错误的解决方法
- 出现:Connect(0) to MySQL (localhost,root) failed
- How to install Nginx, PHP, PHP-FPM and MySQL under Windows with Cygwin