ZKX's LAB

如何对SQL中的所有数据库执行脚本 sql脚本执行命令

2021-04-06知识3

MySQL在DOS命令行中,执行a.sql脚本并生成a.log。如何实现? -使用 mysql 带-e选项来完成mysql-uusername-ppassword-e\"source e:/a.sql\">;e:/a.log

如何执行一个mysql的sql脚本文件 基本步骤如下:一、创建包含sql命令的sql脚本文件文件中包含一系列的sql语句,每条语32313133353236313431303231363533e4b893e5b19e31333339656535句最后以;结尾,假设文件名为ss.sql,文件内容示例如下(使用“-”进行注释):-创建表create table 表名称(Guid Varchar(38)not null primary key,Title Varchar(255),TYPE=InnoDB;在表A中增加字段Statusalter table A add Status TinyInt default '0';在表A上创建索引create index XX_TaskId_1 on A(Id_);在A表中添加一条记录Insert into A(Id,ParentId,Name)values(1,0,'名称');添加、修改、删除数据后,有可能需要提交事务Commit;二、执行sql脚本文件方法一 使用cmd命令执行(以windows为例,unix或linux的在其类似的控制台下运行)格式:【Mysql的bin目录】\\mysql –u用户名 –p密码 –D数据库<;【sql脚本文件路径全名】示例:D:\\mysql\\bin\\mysql –uroot –p123456-Dtest注意事项:1、如果在sql脚本文件中使用了use 数据库,则-D数据库选项可以忽略2、如果【Mysql的bin目录】中包含空格,则需要使用“”包含,如:“C:\\Program Files\\mysql\\bin\\mysql”–u用户名 –p密码 –D数据库<;【sql脚本文件路径。

用cmd命令执行SQL脚本的问题 To allow advanced options to be changed.EXEC sp_configure 'show advanced options',1GO-To update the currently configured value for advanced options.RECONFIGUREGO-To enable the feature.EXEC sp_configure 'xp_cmdshell',1GO-To update the currently configured value for this feature.RECONFIGUREGO这个先写了保证不会再Cmd中出错然后/这是判断是否有同名的数据库存在if exists(select*from sysdatabases where name='hotel')drop database hotelgo/这是判断是否有同名的表if exists(select*from sysobjects where name='hotel')drop table hotelgo

#sql脚本执行命令#sql脚本执行#linux执行sql脚本命令#sql脚本执行方法

随机阅读

qrcode
访问手机版