关闭

2016May Python学习笔记(MySQL&flask)

标签: pythonmysql可视化工具
545人阅读 评论(0) 收藏 举报
分类:

2016May Python学习笔记


MySQL安装及设置

MySQL命令

  1. mac进入mysql命令:
    mysql -u root -p
  2. 查看所有数据库:show databses; (会显示所有的数据库)
  3. 进入某个数据库: use mytest; (会提示database changed)
  4. 查看所有表格: show tables;(会显示mytest中的所有表格)

参考资料:
- 在mac系统下使用mysql数据库命令

MySQLdb

MySQLdb
Python 连接 MySQL 的模块。 MySQL versions 3.23-5.1; and Python versions 2.3-2.5 are supported.百度百科

可以参见例子:

#coding=utf-8

import MySQLdb
import hashlib

class UserInfoDao():
    def __init__(self):
        self.conn1 = MySQLdb.connect('localhost', 'root', 'root', 'MYTEST')
        self.cur1 = self.conn1.cursor()

    def get_admin(self):
        self.cur1.execute('select Users.Username,Users.Password from Users,Grants \
        where Users.UserID = Grants.UserID and Grants.Right = 1')
        result1 = self.cur1.fetchall()
        return result1

    def get_user(self):
        self.cur1.execute('select Username,Password from Users')
        result1 = self.cur1.fetchall()
        return result1

    def get_right(self,Username):
        sqlstr = 'select Grants.Right from Users,Grants where Users.UserID = Grants.UserID and  '\
                +'Users.Username = "'+ Username + '"'
        self.cur1.execute(sqlstr)
        result1 = self.cur1.fetchall()
        return result1

    def first_insert(self):
        users = [['monkey','admin','1'],['test1','123456','2'],['test2','123456','3'],['test3','123456','4']]
        for x in users:
            hash_md5 = hashlib.md5(x[1])
            x[1] = hash_md5.hexdigest()

        for x in users:
            sqlstr = 'insert into Users values ("' + x[0]+'","'+x[1]+'","'+x[2]+'")'
            #print sqlstr
            self.cur1.execute(sqlstr)
            self.conn1.commit()

    def __del__(self):
        self.cur1.close()
        self.conn1.close()

if __name__ == '__main__':
    F = UserInfoDao()
    F.first_insert()

Flask学习

<!DOCTYPE html>
<br lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户界面</title>
</head>

<a href="index">Home</a>

<body align="center">
    {% for message in message_list %}
    {% if message %}
    <br><br><br>
    <font size="8" color="black">{{message}}</font>
    {% endif %}
    {% endfor %}
</body>
</html>

其他


工具

  1. 工作画图

  2. conda

    Anaconda is the leading open data science platform powered by Python. The open source version of Anaconda is a high performance distribution of Python and R and includes over 100 of the most popular Python, R and Scala packages for data science. Additionally, you’ll have access to over 720 packages that can easily be installed with conda, our renowned package, dependency and environment manager, that is included in Anaconda. Anaconda is BSD licensed which gives you permission to use Anaconda commercially and for redistribution.

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:312211次
    • 积分:5733
    • 等级:
    • 排名:第4523名
    • 原创:269篇
    • 转载:3篇
    • 译文:0篇
    • 评论:96条
    联系方式
    Emai: 185986777@qq.com putao0124@gmail.com
    友情链接