• 首页
  • Android
  • Java
  • Python
  • 信息安全
  • 闲扯淡

Guge's blog

以大多数人的努力程度之低,根本轮不到去拼天赋

数据库

Python每日一题(第0002题)

2015年2月5日 by Guge Leave a Comment

题目:将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#coding=utf-8
import MySQLdb
import random,string
 
 
def password(len):
chars = string.ascii_letters.lower() + string.digits
return ''.join(random.sample(chars,len))
 
def insertcdkey():
number = 1
for i in range (200):
passwd = password(10)
cur.execute('insert into jihuoma (id, cdkey) values (%s, %s)', [number, passwd])
number += 1
#print number,passwd
 
if __name__ == '__main__':
conn = MySQLdb.connect(
host = 'localhost',
    port = 3306,
    user = 'root',
    passwd = '',
    db = 'test')
cur = conn.cursor()
cur.execute("create table jihuoma(id varchar(20) primary key,cdkey varchar(20))")
insertcdkey()
cur.close()
conn.commit()
conn.close()

笔记:MySQL的SQL占位符是%s;

Posted in: Python Tagged: MySQL, MySQLdb, 占位符, 数据库

python操作Mysql数据库

2015年1月27日 by Guge Leave a Comment

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#coding=utf-8
import MySQLdb
 
conn= MySQLdb.connect(
        host='localhost',
        port = 3306,
        user='root',
        passwd='123456',
        db ='test',
        )
cur = conn.cursor()
 
#创建数据表
#cur.execute("create table student(id int ,name varchar(20),class varchar(30),age varchar(10))")
 
#插入一条数据
#cur.execute("insert into student values('2','Tom','3 year 2 class','9')")
 
 
#修改查询条件的数据
#cur.execute("update student set class='3 year 1 class' where name = 'Tom'")
 
#删除查询条件的数据
#cur.execute("delete from student where age='9'")
 
cur.close()
conn.commit()
conn.close()

PS:由于Kali已安装了MySQL-python,故无需安装,如在Python下,输入

Python
1
>>> import MySQLdb

报错提示模块找不到,则需要安装MySQL-python:

下载地址:https://pypi.python.org/pypi/MySQL-python/

下载MySQL-python-1.2.5.zip 文件之后直接解压,然后进入目录安装即可:

>>python setup.py install

Posted in: Python Tagged: MySQL, MySQL-Python, 数据库

微信公众平台

站内搜索

标签

360 Activity ADB Android android studio apktool arm BCTF CSRF CTF drozer hacker精神 IDA ISG java线程 Json Launch4j MySQL ndk Phantomjs python ROP xposed xss Zaker 一周安全 信息安全 信息安全,干货 加壳 华尔街之狼 安全 安全干货 安全竞赛 寄存器 干货 数据库 查找 步长 每天一个小程序 爬虫 程序员 系统信息获取 脱壳 逆向 遍历

近期文章

  • 关于绕过域名(ip)的一些小技巧
  • 骨哥电台第4期:马斯克之地启示录1
  • 骨哥电台第3期:了解马斯克
  • 骨哥电台第2期:钢铁侠原型-霍华德·休斯的故事
  • 它终于让我换下了使用多年的谷歌浏览器

友情链接

CRoot' Blog
void* Future

Copyright © 2022 Guge's blog.

Omega WordPress Theme by ThemeHall