-- 创建表格
CREATE TABLE my_table (
id INT AUTO_INCREMENT,
name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
email VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
password VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- 插入100条随机生成的数据
INSERT INTO my_table (name, email, password)
VALUES ('John Doe', '[email protected]', 'password123'),
('Jane Doe', '[email protected]', 'password123'),
('User 99', '[email protected]', 'password123'),
('User 100', '[email protected]', 'password123');
select * from test
以下是建表语句及对应的存储过程:
-- 建表语句
CREATE TABLE test (
id INT AUTO_INCREMENT,
name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
email VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
password VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
DELIMITER $$
-- 创建存储过程
CREATE PROCEDURE insert_data()
BEGIN
DECLARE i INT DEFAULT 1;
WHILE i <= 1000 DO
INSERT INTO test (name, email, password)
VALUES (CONCAT('User ', i), CONCAT('user', i, '@example.com'), CONCAT('password', i));
SET i = i + 1;
END WHILE;
END$$
-- 调用存储过程
CALL insert_data1();
DELIMITER ;
标签:8.0,ci,SET,utf8mb4,ai,写入,COLLATE,mysql,0900 From: https://www.cnblogs.com/wzljy/p/17805485.html