百G数据库迁移测试
1、安装mariadb和mariadb-server
yum install mariadb mariadb-server #安装数据库和数据库客户端
systemctl start mariadb #启动数据库
systemctl enable mariadb #设置数据库为自启动
systemctl stop firewalld #关闭防火墙
setenforce 0 #关闭selinux
#也可以修改/etc/selinux/conf
mysql_secure_installation #数据库安全初始化
创建相应数据库(这里展示我自己创建的数据库)
create database test; #创建test数据库
use test #进入test数据库
create table testtable(
id bigint(255) NOT NULL AUTO_INCREMENT PRIMARY KEY,
name char(255),
math int(255),
english int(255),
chinese int(255),
glass int(255),
zxcv int(255),
zxcb int(255),
zxcn int(255),
zxcm int(255),
zxca int(255),
zxcs int(255),
zxcd int(255),
zxcf int(255),
zxcg int(255),
zxch int(255),
zxcj int(255),
zxck int(255),
zxcl int(255),
zxcq int(255),
zxcw int(255),
zxce int(255),
zxcr int(255),
zxct int(255),
zxcy int(255),
zxcu int(255),
zxci int(255),
zxco int(255),
zxcp int(255)
);
#创建testtable数据表
2、编写python脚本向数据库插入数据
import pymysql
import random
fname = ['赵','钱','孙','李','周','吴','郑','王','冯','陈','楮','卫','蒋','沈','韩','杨','朱','秦','尤','许','何','吕','施','张','孔','曹','严','华','金','魏','陶','姜','戚','谢','邹','喻','柏','水','窦','章','云','苏','潘','葛','奚','范','彭','郎','鲁','韦','昌','马','苗','凤','花','方','俞','任','袁','柳','酆','鲍','史','唐','费','廉','岑','薛','雷','贺','倪','汤','滕','殷','罗','毕','郝','邬','安','常','乐','于','时','傅','皮','卞','齐','康','伍','余','元','卜','顾','孟','平','黄','和','穆','萧','尹','姚','邵','湛','汪','祁','毛','禹','狄','米','贝','明','臧','计','伏','成','戴','谈','宋','茅','庞','熊','纪','舒','屈','项','祝','董','梁','杜','阮','蓝','闽','席','季','麻','强','贾','路','娄','危','江','童','颜','郭','梅','盛','林','刁','锺','徐','丘','骆','高','夏','蔡','田','樊','胡','凌','霍','虞','万','支','柯','昝','管','卢','莫','经','房','裘','缪','干','解','应','宗','丁','宣','贲','邓','郁','单','杭','洪','包','诸','左','石','崔','吉','钮','龚','程','嵇','邢','滑','裴','陆','荣','翁','荀','羊','於','惠','甄','麹','家','封','芮','羿','储','靳','汲','邴','糜','松','井','段','富','巫','乌','焦','巴','弓','牧','隗','山','谷','车','侯','宓','蓬','全','郗','班','仰','秋','仲','伊','宫']
mname = ['玉', '明', '玲', '淑', '偑', '艳', '大', '小', '风', '雨', '雪', '天', '水', '奇', '鲸', '米', '晓', '泽', '恩', '葛', '玄', '道',
'振', '隆', '奇']
lname = ['', '玲', '', '芳', '明', '红', '国', '芬', '', '云', '娴', '隐', '', '花', '叶', '', '黄', '亮', '锦', '茑', '军', '', '印',
'', '凯']
# 数据库连接参数,替换成你自己的IP和账号密码,以及数据库名
conn = pymysql.connect(host='192.168.197.128',user = "root",passwd = "857493511",db = "test")
cur = conn.cursor()
while 0<1:
# 生成随机数据
name = random.choice(fname) + random.choice(mname) + random.choice(lname)
math = random.randint(40, 100000)
english = random.randint(40, 100000)
chinese = random.randint(40, 100000)
glass = random.randint(1, 100000)
zxc = random.randint(1, 100000)
zxcv = random.randint(1, 100000)
zxcb = random.randint(1, 100000)
zxcn = random.randint(1, 100000)
zxcm = random.randint(1, 100000)
zxca = random.randint(1, 100000)
zxcs = random.randint(1, 100000)
zxcd = random.randint(1, 100000)
zxcf = random.randint(1, 100000)
zxcg = random.randint(1, 100000)
zxch = random.randint(1, 100000)
zxch = random.randint(1, 100000)
zxcj = random.randint(1, 100000)
zxck = random.randint(1, 100000)
zxcl = random.randint(1, 100000)
zxcq = random.randint(1, 100000)
zxcw = random.randint(1, 100000)
zxcr = random.randint(1, 100000)
zxct = random.randint(1, 100000)
zxcy = random.randint(1, 100000)
zxcu = random.randint(1, 100000)
zxci = random.randint(1, 100000)
zxco = random.randint(1, 100000)
zxcp = random.randint(1, 100000)
zxce = random.randint(1, 100000)
# 插入数据 (特别注意只能用%s 不能用%d,数值型数据不用引号,要换成你创建的数据表)
cur.execute("insert into testtable values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", (id, name, math, english, chinese, glass,zxcv,zxcb,zxcn,zxcm,zxca,zxcs,zxcd,zxcf,zxcg,zxch,zxcj,zxck,zxcl,zxcq,zxcw,zxce,zxcr,zxct,zxcy,zxcu,zxci,zxco,zxcp))
conn.commit() # 提交命令,否则数据库不执行插入操作
cur.close()
conn.close()
3、运行脚本,慢慢等待
开始运行
2.8G的数据已经达到近八百万条数据了,等待百G
文章内容仅用于作者学习使用,如果内容侵犯您的权益,请立即联系作者删除,作者不承担任何法律责任。