您的位置:首页 > 运维架构 > Linux

windows下python连接linux的mysql并且使用

2016-06-06 13:38 501 查看
1\linux上成功安装mysql

2\授权mysql可以远程访问

开放防火墙的端口号

 # GRANT ALL PRIVILEGES ON *.* TO root@'%'  IDENTIFIED BY ‘1714004716’  WITH GRANT OPTION;

#FLUSH   PRIVILEGES;

3\windows安装python 的mysql依赖库:MySQL-python-1.2.3.win-amd64-py2.7.exe

4\开始编写代码测试

 #coding:utf8

#import Mysqldb as mysql

获取连接

#conn=mysql.connect(host=’192.168.142.111’,user=’root’,passwd=’1714****’,db=’dg’)

获取游标

#cursor=conn.cursor()

编写操作的sql语句

#sqlStr=’select * from t_user’

#cursor.execute(sqlStr)

获取返回数据

#result=cursor.fetchall()

#print result

释放游标

#cursor.close()

释放连接

#conn.close()

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: