python教程:数据库
1、安装mysql的扩展,执行指令sudo pip install PyMySQL如图所示:
2、关于pip的用法这里就不去详细解释了,记住两个最基本的。看装了那些扩展库:pip list安装扩展库:pip install 包名
3、编写下面的代码:这个代码连接到你的数据库,执行查询数据库版本返回。
4、查询数据库import pymysqlconn = pymysql.connect("127.0.0.1"稆糨孝汶;,'root','123456','logdb')cursor = conn.cursor()sql = "select id,name,age from user_info limit 1";data = cursor.execute(sql)print data;cursor.close()
5、更新或删除坡纠课柩import pymysqlconn = pymysql.connect("127.0.0.1&鳎溻趄酃quot;,'root','123456','logdb')cursor = conn.cursor()sql = "update user_info set age = 1 where id =1";cursor.execute(sql)cursor.close()
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:55
阅读量:26
阅读量:86
阅读量:71
阅读量:33