CentOS 7.2 安装 python 读 mysql
来源:互联网 发布:中央数据交换平台 编辑:程序博客网 时间:2024/06/05 23:29
1、系统自带python 2.7
2、安装mysql:
点击打开链接
3、安装 MySQLdb 库
yum install MySQL-python
在python客户端导入看是否报错:
import MySQLdb
4、自己先建一个users表:
import MySQLdbimport tornado.ioloopimport tornado.webcxn = MySQLdb.Connect(host = '127.0.0.1', user = 'root', passwd = '')class Test(tornado.web.RequestHandler): def get(self): result = "" cur = cxn.cursor() cur.execute("USE test") cur.execute("SELECT * FROM users") for row in cur.fetchall(): result += row.__str__() print(result) self.write(result)class Login(tornado.web.RequestHandler): def get(self): userName = self.get_argument('userName','hello') passWord = self.get_argument('passWord','hello') sql = "SELECT * FROM users WHERE username='%s'" %(userName) cur = cxn.cursor() cur.execute("USE test") cur.execute(sql) result = cur.fetchall() cur.close() cxn.commit() if result[0][2] == passWord: self.write("1") else: self.write("0")application = tornado.web.Application([ (r"/test", Test), (r"/login", Login)])if __name__=="__main__": application.listen(8888) tornado.ioloop.IOLoop.instance().start() cxn.close()
0 0
- CentOS 7.2 安装 python 读 mysql
- centos 安装mysql-python
- CentOS 安装MySQL-python
- centos 安装 MySQL-python
- CentOS Python 安装MySQL-python
- centos安装mysql-python注意事项
- centos下安装MySQL-python
- centos 7 安装mysql-python
- CentOS 6 安装 MySQL-python
- centos 7.2 mysql 安装
- CentOS安装python2.6以及MySQL-python
- Centos环境下MySQL-python安装过程
- 如何在centos安装python-mysql?
- 如何在centos安装python-mysql?
- Centos 下 安装 flask ,Mysql-python 步骤
- Centos 安装python MySQL 模块 -- MySQLdb
- centos 6.5 安装MySQL-python模块
- centos 7.2 安装python talib
- 进制转换--数字转26字母进制-matlab
- 【机器学习(李宏毅)】 三、Bias and Variance
- maven+springMVC+mybatis+junit详细搭建过程
- [SMOJ1810]基因测试
- jenkins安装部署过程简记
- CentOS 7.2 安装 python 读 mysql
- C++核心知识整理——标准库和oop
- [高德地图 应用找不到本地方法nativeNewInstance] 代码正常,啥都没做就报错,地图当然也不能显示
- Intellij idea破解办法
- 正则表达式基本语法
- 关于欧拉函数和费马小定理的应用
- 【idea】基于jmeter的性能测试自动化平台开发
- Vs2013搭建socket服务器/客户端,开线程thread
- SlidingMenu_RelativeLayout_CustomViewAbove