From ce9db1bd1d2a3975a8a290d73368973bdaeefe82 Mon Sep 17 00:00:00 2001 From: halliday Date: Tue, 7 Nov 2023 18:01:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/DBConfig.py | 16 ++++++++-------- bin/SQLDataCreating.py | 2 +- bin/faker_data.py | 3 ++- bin/fileDataCreating.py | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bin/DBConfig.py b/bin/DBConfig.py index a33840a..a671e3b 100644 --- a/bin/DBConfig.py +++ b/bin/DBConfig.py @@ -19,14 +19,14 @@ etc_dir = path.parent.parent / "etc" def mysql_config(): mysql_info_dict={} - mysql_info_dict['driver_name'] = "com.mysql.jdbc.Driver" + mysql_info_dict['driver_name'] = "com.mysql.cj.jdbc.Driver" mysql_info_dict['driver_jar'] = "mysql-connector-java-8.0.29.jar" driver_jar_path = etc_dir / "driver" / mysql_info_dict['driver_jar'] mysql_info_dict['driver_jar_path'] = str(driver_jar_path) #这里要连接到具体的库 - mysql_info_dict['jdbc_url'] = "jdbc:mysql://10.10.29.9:3306/test2" + mysql_info_dict['jdbc_url'] = "jdbc:mysql://10.10.14.69:3306/sys" mysql_info_dict['db_user'] = "root" - mysql_info_dict['db_password'] = "Unary@2023" + mysql_info_dict['db_password'] = "111111" #create table sql # now_hours = get_now() @@ -44,13 +44,13 @@ def mysql_config(): create_sql_string += "`email` varchar(50) DEFAULT NULL," create_sql_string += "`job` varchar(50) DEFAULT NULL," create_sql_string += "`address` varchar(50) DEFAULT NULL," - create_sql_string += "`actime_time` timestamp NULL DEFAULT NULL" + create_sql_string += "`actime_time` varchar(50) NULL DEFAULT NULL" create_sql_string += ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;" mysql_info_dict['create_sql_string'] = create_sql_string # insert into sql insert_list = [] - data = faker_data.faker_data(lines=2)[1:] + data = faker_data.faker_data(lines=200)[1:] for a in data: #拼接sql insert_sql_string = "INSERT INTO " + table_name @@ -68,7 +68,7 @@ def mysql_config(): # uptata sql - updata_sql = "UPDATE "+ table_name + " t SET t.job='测试' WHERE t.name like '李%' AND sex = 1 AND id = 1 " + updata_sql = "UPDATE "+ table_name + " t SET t.job='unary_测试' WHERE t.name like '李%' AND sex = 1 AND id = 1 " mysql_info_dict['updata_sql'] = updata_sql return(mysql_info_dict) @@ -106,7 +106,7 @@ def oracle_config(): # insert into sql insert_list = [] - data = faker_data.faker_data(lines=2)[1:] + data = faker_data.faker_data(lines=200)[1:] for a in data: #拼接sql insert_sql_string = "INSERT INTO " + table_name @@ -124,7 +124,7 @@ def oracle_config(): # uptata sql - updata_sql = "UPDATE "+ table_name + " t SET t.job='测试' WHERE t.name like '李%' AND sex = 1 AND id = 1 " + updata_sql = "UPDATE "+ table_name + " t SET t.job='unary_测试' WHERE t.name like '李%' AND sex = 1 AND id = 1 " oracle_info_dict['updata_sql'] = updata_sql return(oracle_info_dict) diff --git a/bin/SQLDataCreating.py b/bin/SQLDataCreating.py index 4e4ddb9..55771e6 100644 --- a/bin/SQLDataCreating.py +++ b/bin/SQLDataCreating.py @@ -19,7 +19,7 @@ from schedule import every, repeat, run_pending """ # 目前支持 MySQL和Oracle两种数据库,其他的数据库需要做适配 -DBType = "oracle" +DBType = "mysql" #获取连接信息 diff --git a/bin/faker_data.py b/bin/faker_data.py index c6c8c12..55954a5 100644 --- a/bin/faker_data.py +++ b/bin/faker_data.py @@ -1,6 +1,7 @@ #encoding=utf-8 import csv from faker import Faker +from datetime import datetime """ 生成尽可能真实的假数据 @@ -65,7 +66,7 @@ def faker_data(lines=10): address = f.address()[:-9] + str(f.pyint(min_value=0, max_value=999))+ "号" data.append(address) #获取时间,近3年的 - actime_time = f.date_time_between(start_date="-3y", end_date="now") + actime_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') data.append(actime_time) #将这一行数据添加到datas中 datas.append(data) diff --git a/bin/fileDataCreating.py b/bin/fileDataCreating.py index 0ae6e4d..3e7bca8 100644 --- a/bin/fileDataCreating.py +++ b/bin/fileDataCreating.py @@ -56,7 +56,7 @@ def new(): if not finfo[2].exists(): finfo[2].mkdir() # 创建文件 - faker_data.save_data_csv(finfo[4], lines=50000) + faker_data.save_data_csv(finfo[4], lines=200000) # 每2秒插入10条数据