测试MySQL单表10E数据性能
表结构
CREATE TABLE `name_10e` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1075600001 DEFAULT CHARSET=utf8mb4;
插入数据
from faker import Faker
import random
import string
import pymysql
fake = Faker('zh_CN') # 使用中文环境
def generate_name():
# 随机选择生成英文名或中文姓名
if random.choice([True, False]):
return fake.name() # 生成中文姓名
else:
return ''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase, k=5)) # 生成简单的英文名
# # 生成10亿个姓名
# names = [generate_name() for _ in range(10_0000_0000)]
#
# print(names)
# 连接数据库
conn = pymysql.connect(host='localhost', user='root', password='root', db='big_data')
cursor = conn.cursor()
# 设置自动提交为False
conn.autocommit(False)
# 批量插入的大小,你可以根据需要进行调整
batch_size = 10000
data = []
for _ in (range(10_0000_0000)):
data.append(generate_name())
if len(data) >= 10000:
# 构建批量插入语句
query = "INSERT INTO `name_10e` (`name`) VALUES (%s)"
# 执行批量插入
cursor.executemany(query, data)
data = []
# 提交事务
conn.commit()
# 关闭连接
cursor.close()
conn.close()
不加索引
select * from name_10e where name = '赵婷'
第一次
ALTER TABLE big_data
.name_10e
ADD INDEX idx_name
(name
) USING BTREE
1034 - Incorrect key file for table ‘name_10e’; try to repair it
时间: 1617.613s