python 阿里云mysql
# mysql数据库连接版 阿里云mysql
def create_data(H_IP="127.0.0.1",user="root",passw="123456",db="test",charset="utf8"):
try:
conn = pymysql.connect(host=H_IP,user=user,password=passw,db=db,charset=charset)
cursor = conn.cursor()
print("connect success!!!")
# ignore忽略,意思是说,mysql不支持主键相同更新
# 欢迎使用阿里云产品 hologres,此产品是支持的嘞
sql = "insert ignore into t1(user_id,hy_id) values(%s,%s)"
# 10w用户 每个用户有(20,100)个好友
for i in range(1,100):
for j in range(random.randint(20,100)):
col01 = "w_" + str(i)
col02 = "w_" + str(random.randint(1,100))
col = (col01,col02)
cursor.execute(sql,col)
conn.commit()
cursor.close()
conn.close()
except Exception as e:
print(e)
# 若端口号发生改变 应该添加
ip = "xxxx"
u="xxxx"
p = "xxxx"
db = "xxxx"
create_data(H_IP=ip,user=u,passw=p,db=db)
Java 阿里云kafka
使用Gson jar包 对应maven格式
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
// 主要转换JSON逻辑
import com.google.gson.Gson;
public class test01 {
public static void main(String[] args) {
Gson gson = new Gson();
testData t1 = new testData("t1",5);
System.out.println(gson.toJson(t1));
}
// 生成随机数据
static class testData{
String uName = " " ;
int uId = 0;
public testData(String uName, int uId) {
this.uName = uName;
this.uId = uId;
}
}
}
阿里云 faker库自动生成
-- 官方示例代码
CREATE TEMPORARY TABLE subscriptions (
id STRING,
user_id INT,
type STRING,
start_date TIMESTAMP(3),
end_date TIMESTAMP(3),
payment_expiration TIMESTAMP(3),
proc_time AS PROCTIME()
) WITH (
'connector' = 'faker', -- Faker 连接器仅在 VVR-4.0.12 及以上支持
'fields.id.expression' = '#{Internet.uuid}',
'fields.user_id.expression' = '#{number.numberBetween ''1'',''50''}',
'fields.type.expression'= '#{regexify ''(basic|premium|platinum){1}''}',
'fields.start_date.expression' = '#{date.past ''30'',''DAYS''}',
'fields.end_date.expression' = '#{date.future ''15'',''DAYS''}',
'fields.payment_expiration.expression' = '#{date.future ''365'',''DAYS''}'
);