可以在配置文件里指定mysql启动以后初始执行的SQL文件, 其语法是:

在[mysqld]下指定:

init-file="D:/mysql/test.sql",  后面为具体的sql文件值。

注意下边两点就行了:

1. 确保你的mysqld 编译的时候没有加  --disable-grant-options 开关。

2. 确保init-file指定的脚本每行是一个具体的可以执行的语句。

Mysql启动时执行文件init-file的使用

废话不多说(上面截图我使用的mysql7)。直入正题:test.sql为:

use test;  
begin;  
create table if not exists test123(id int);  
insert into test123 values(1);  
insert into test123 values(2);  
select * from test123;  
-- drop table test123;  
end;  

 启动完mysql以后,得到查询可以看到

Mysql启动时执行文件init-file的使用

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
猜你喜欢
  • 2021-10-11
  • 2022-12-23
  • 2022-01-08
  • 2021-11-21
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案