#/usr/bin/python
#-*- coding:utf-8 -*-
#@Time :2017/11/24 2:59
#@Auther :liuzhenchuan
#@File :增加#数据.py
#select * from tmp 10行数据
#select * from tmp a ,tmp b, tmp c: 1000行数据=10*10*10
#tmp a tmp b tmp c 对应表1 表2 表3
#获得随机字符串的设计
#增加的数据是随机数据,rand() 函数生成0-1 的一个随机数
#shal() 对数字进行加密,然后就生成了一堆字符串
#concat() 拼接多个字符串的函数
#substr() 取多少个字符
#获得随机整数的设计
# rand()*50 通过rand() 函数获得一个0-1的数,然后再乘以50 取到的数就是0-50
# floor() 这个函数代表的是去尾法取整数
# 男女的设计
# rand()*10 /2 最后取余数
# 如果余数为1,就设置为M
#如果余数为0,就设置为F
import MySQLdb
student = '''
set @a = 10000;
insert into student select @a := @a + 1, substr(concat(sha1(rand()), sha1(rand())), 1, 5+floor(rand()* 50)), case floor(rand()*10) mod 2 when 1 then "M" else "F" end, 20+floor(rand() * 8) from tmp a, tmp b, tmp c, tmp d;
'''
# insert into student select @i:=@i+1, substr(concat(sha1(rand()), sha1(rand())), 1, 3 + floor(rand() * 75)), case floor(rand()*10) mod 2 when 1 then 'M' else 'F' end, 25-floor(rand() * 5) from tmp a, tmp b, tmp c, tmp d;
# 我用下去这种insert就会有同名字的学生名
course = '''set @i := 10;
insert into course select @i:=@i+1, substr(concat(sha1(rand()), sha1(rand())), 1, 5 + floor(rand() * 45)), 100 + floor(rand() * 100) from tmp a;
'''
score = '''set @i := 10000;
insert into score select @i := @i +1, floor(10001 + rand()*10000), floor(11 + rand()*10), floor(1+rand()*100) from tmp a, tmp b, tmp c, tmp d;
'''
teacher = '''set @i := 100;
insert into teacher select @i:=@i+1, substr(concat(sha1(rand()), sha1(rand())), 1, 5 + floor(rand() * 80)) from tmp a, tmp b;
'''
def connect_mysql():
db_config = {
"host": "192.168.16.70",
"port": 3306,
"user": "root",
"passwd": "123123",
"db": "students",
"charset": "utf8"
}
try:
cnx = MySQLdb.connect(**db_config)
except Exception as e:
raise e
return cnx
if __name__ == "__main__":
cnx = connect_mysql()
try:
cus = cnx.cursor()
cus.execute(student)
cus.close()
cus = cnx.cursor()
cus.execute(course)
cus.close()
cus = cnx.cursor()
cus.execute(score)
cus.close()
cus = cnx.cursor()
cus.execute(teacher)
cus.close()
cnx.commit()
except Exception as e:
cnx.rollback()
raise e
finally:
cnx.close()
查看数据库:
ysql> show tables;
+--------------------+
| Tables_in_students |
+--------------------+
| course |
| score |
| student |
| teacher |
| tmp |
+--------------------+
mysql> select *from course limit 10;
+-------+---------------------------------------------+-----+
| couid | cname | tid |
+-------+---------------------------------------------+-----+
| 11 | 86c85fe76342ff5e376264621 | 100 |
| 12 | ccef65aa5b377ac39ddd7dc44 | 143 |
| 13 | 0e8a391f36 | 146 |
| 14 | 6755d9fa73 | 146 |
| 15 | 8c79d4684d88065b1cecbe76 | 143 |
| 16 | 6bf78ad3dd4f5db7751fcfff6e661d526e814c54 | 166 |
| 17 | 2210cf9debd4a096373fd452d057f5c0f | 141 |
| 18 | 16e99f932a599ca8f940eeabebc04996c | 126 |
| 19 | a839d37dffd0cdd80bc7d | 181 |
| 20 | 17601ade7e74aa81f3fdf23d47af85bf2e8ed232288 | 152 |
+-------+---------------------------------------------+-----+
10 rows in set (0.00 sec)
mysql> select *from score limit 10;
+-------+-------+-----+-------+
| sid | stdid | cid | grade |
+-------+-------+-----+-------+
| 10001 | 10742 | 19 | 78 |
| 10002 | 14902 | 12 | 12 |
| 10003 | 12126 | 18 | 99 |
| 10004 | 17672 | 19 | 5 |
| 10005 | 16303 | 11 | 15 |
| 10006 | 17104 | 12 | 43 |
| 10007 | 18091 | 18 | 37 |
| 10008 | 15446 | 17 | 53 |
| 10009 | 17175 | 11 | 96 |
| 10010 | 16939 | 17 | 100 |
+-------+-------+-----+-------+
10 rows in set (0.00 sec)
mysql> select *from student limit 10;
+-------+-------------------------------------------------------+--------+-------+
| stdid | stdname | gender | agent |
+-------+-------------------------------------------------------+--------+-------+
| 10001 | 05be2e1f6be2dba3496d | M | 27 |
| 10002 | 8d21176c8a4cad420d9adec8dd6022146ed0b69dabe80c56c91 | F | 24 |
| 10003 | 582cf648fbb65fcae2eb0 | F | 22 |
| 10004 | ece0f0bb303e98859d9d41b6f246864e22d86ad405048ee | M | 23 |
| 10005 | e484bfbd4011fcebfa0d18271975b0834a1ccedd | M | 26 |
| 10006 | bb1ecba374c1dbdda1be | F | 22 |
| 10007 | 0b30cf54b756d4665e8fc41c7450433f590aefc37c8ea9afbbe8e | M | 27 |
| 10008 | 3cdf0dddcd8911386fd36b2bf3 | F | 27 |
| 10009 | f699c14f237ad1778fe2f1d | F | 20 |
| 10010 | a4b36903fd1c0e2f8f4151706e9d95ebfdf068b2f | F | 27 |
+-------+-------------------------------------------------------+--------+-------+
10 rows in set (0.00 sec)
mysql> select *from teacher limit 10;
+-----+------------------------------------------------------------------------+
| tid | tname |
+-----+------------------------------------------------------------------------+
| 101 | 7684b4b |
| 102 | 497c1eeb229d5faf8a88213f1a28ad5ceab755e222b832f50ef3b71f73860 |
| 103 | f7307 |
| 104 | 9c44341e4fd84d1545f5293df4762695e962540b39ebb528d58c509ab5 |
| 105 | d1cd631d236e48a8efccb032c833f867e863bbe361ef8cfd0869601 |
| 106 | 2cf3b9da2484eb560a8000be460f529dd17c |
| 107 | edc0ad15105a4dde02214a482fd0ac695517e307999fb7695bf1f6cfead6 |
| 108 | 8109966982f40ad1819d9c94023f4227eb019bd779305c0b8e9a87a7b0ddd436e97842 |
| 109 | 76433 |
| 110 | 438032fb74888de54a09e2cbd846650c85079f8feda82 |
+-----+------------------------------------------------------------------------+
10 rows in set (0.00 sec)
- [更新]跨平台物联网通讯框架 ServerSuperIO v1.2(SSIO),增加数据分发控制模式
1.[开源]C#跨平台物联网通讯框架ServerSuperIO(SSIO) 2.应用SuperIO(SIO)和开源跨平台物联网框架ServerSuperIO(SSIO)构建系统的整体方案 3.C#工业 ...
- 计算概论(A)/基础编程练习(数据成分)/3:整数的个数
#include<stdio.h> int main() { ] = {}; // 输入k个正整数 scanf("%d",&k); // 循环读入和进行算术 w ...
- 计算概论(A)/基础编程练习(数据成分)/2:奥运奖牌计数
#include<stdio.h> int main() { // n天的决赛项目 int n; scanf("%d",&n); ] = {}; while ( ...
- 计算概论(A)/基础编程练习(数据成分)/1:短信计费
#include<stdio.h> int main() { // 输入当月发送短信的总次数n和每次短信的字数words int n,words; scanf("%d" ...
- 多媒体基础知识之PCM数据《 转》
多媒体基础知识之PCM数据 1.什么是PCM音频数据 PCM(Pulse Code Modulation)也被称为脉冲编码调制.PCM音频数据是未经压缩的音频采样数据裸流,它是由模拟信号经过采样.量化 ...
- Java基础-线程操作共享数据的安全问题
Java基础-线程操作共享数据的安全问题 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.引发线程安全问题 如果有多个线程在同时运行,而这些线程可能会同时运行这段代码.程序每次运 ...
- ORACLE数据库增加表空间大小或给表空间增加数据文件
转载 2017年11月24日 11:00:28 ----查询表空间使用情况--- SELECT UPPER(F.TABLESPACE_NAME) "表空间名", D.TOT_GRO ...
- laravel基础课程---16、数据迁移(数据库迁移是什么)
laravel基础课程---16.数据迁移(数据库迁移是什么) 一.总结 一句话总结: 是什么:数据库迁移就像是[数据库的版本控制],可以让你的团队轻松修改并共享应用程序的数据库结构. 使用场景:解决 ...
- Django多变关联、增加数据、删除数据
建立表之间的关联关系: models.py里面对表的字段及外键关系的设置如下: from django.db import models # Create your models here. #出版社 ...
随机推荐
- window linux 文件传输
window 安装:pscp.exe (放在C:\Windows\System32 目录下) Linux 安装: 1: 先更新apt-getroot@ubuntu:/home/ubuntu# sudo ...
- appium python api(转)
Appium_Python_Api文档 1.contextscontexts(self): Returns the contexts within the current session. 返回当前会 ...
- 【Hadoop】Flink VS Spark?Drill VS Presto?
参考资料: drill 官网:http://drill.apache.org/ drill安装使用:https://segmentfault.com/a/1190000002652348 drill简 ...
- How to support both ipv4 and ipv6 address for JAVA code.
IPv6 have colon character, for example FF:00::EEIf concatenate URL String, IPv6 URL will like: http: ...
- python 处理抓取网页乱码问题一招鲜
FROM: http://my.oschina.net/012345678/blog/122355 相信用python的人一定在抓取网页时,被编码问题弄晕过一阵 前几天写了一个测试网页的小脚本,并查找 ...
- java-selenium(二)富文本编辑框的处理
首先先看一下什么是富文本编辑框 HTML源码 思路:首先先进入到iframe中,再用js写,最后切出iframe 如果想要换行可以在换行的地方加上<br> 如果添加的文本中包含单引号.双引 ...
- smarty在循环的时候计数来显示这是第几次循环的功能
想必有很多人比较喜欢这个smarty循环的时候有个变量增加的功能或比较需要这个功能吧?其实不需要额外的变量,当然你也许根本用不了.我们用smarty内置的就可以了.就是smarty有foreach和s ...
- SpringMVC 下载XLS文档的设置
页面设置参考上文.SpringMVC 下载文本文档的设置 此文是关于xls文档下载的,这个文档使用Apache的POI生成,需要的jar包可以从下面地址下载: http://pan.baidu.com ...
- Rails 状态码
Response Class HTTP StatusCode Symbol Informational 100 :continue Success 200 :ok Redirection 300 :m ...
- Mismatched locale IDs. The component locale ID (2052) does not match the connection manager locale ID (2057)
Snapshot: When using the 'Flat File Source' and 'OLE DB Destination' or something else components to ...