批量数据脚本
目录
建表
|
|
设置参数
-
创建函数,假如报错:This function has none of DETERMINISTIC………
-
由于开启过慢查询日志,因为我们开启了bin-log,我们就必须为我们的function指定一个参数。
如果没开启bin-log就不用管
假设开启了bin-log, 我们就必须指定我们的函数是否是
1 DETERMINISTIC 不确定的
2 NO SQL 没有SQl语句,当然也不会修改数据
3 READS SQL DATA 只是读取数据,当然也不会修改数据
4 MODIFIES SQL DATA 要修改数据
5 CONTAINS SQL 包含了SQL语句
其中在function里面,只有 DETERMINISTIC, NO SQL 和 READS SQL DATA 被支持。如果我们开启了 bin-log, 我们就必须为我们的function指定一个参数。
解决方法:
开启log_bin_trust_function_creators
-
log_bin_trust_function_creators = OFF
,默认必须为 function 传递一个参数1 2 3 4 5 6 7
mysql> show variables like 'log_bin_trust_function_creators'; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | log_bin_trust_function_creators | OFF | +---------------------------------+-------+ 1 row in set (0.00 sec)
-
通过
set global log_bin_trust_function_creators=1;
我们可以不用为 function 传参1 2 3 4 5 6 7 8 9 10
mysql> set global log_bin_trust_function_creators=1; Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'log_bin_trust_function_creators'; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | log_bin_trust_function_creators | ON | +---------------------------------+-------+ 1 row in set (0.00 sec)
-
-
这样添加了参数以后,如果mysqld重启,上述参数又会消失,永久方法在配置文件中修改‘
- windows下:my.ini –> [mysqld] 节点下加上
log_bin_trust_function_creators=1
- linux下:/etc/my.cnf –> [mysqld] 节点下加上
log_bin_trust_function_creators=1
- windows下:my.ini –> [mysqld] 节点下加上
创建函数,保证每条数据都不同
随机产生字符串的函数
|
|
随机产生部门编号的函数
|
|
创建存储过程
创建往emp表中插入数据的存储过程
|
|
创建往dept表中插入数据的存储过程
|
|
调用存储过程
向 dept 表中插入 10 条记录
|
|
|
|
向 emp 表中插入 50w 条记录
|
|
|
|