运行.bat执行sql文件 —— mysql
参考地址:https://www.cnblogs.com/dingjiaoyang/p/9990188.html
运行test.bat 执行 test.sql文件
test.bat:
@ECHO OFF SET dbhost=127.0.0.1 SET dbuser=root SET dbpasswd=123456 SET dbName=test SET sqlpath=%~dp0 set sqlfile=test.sql cd C:\Program Files\MySQL\MySQL Server 5.5\bin ::执行SQL脚本 mysql -h%dbhost% -u%dbuser% -p%dbpasswd% < %sqlpath%%sqlfile% --default-character-set=utf8 ECHO OK! PAUSE @ECHO Done!
test.sql:
DROP database IF EXISTS `test`; create database test; use test; SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for `test_1` -- ---------------------------- DROP TABLE IF EXISTS `test_1`; CREATE TABLE `test_1` ( `idd` int(11) unsigned NOT NULL DEFAULT '0', `codee` varchar(20) DEFAULT NULL, `namee` varchar(50) DEFAULT NULL COMMENT '工厂名', `addrr` varchar(100) DEFAULT NULL COMMENT '地址' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of test_1 -- ---------------------------- INSERT INTO `test_1` VALUES ('1', 'aaa', '县城区污水处理厂', '四川'); INSERT INTO `test_1` VALUES ('2', 'bbb', '县工业园区污水处理厂', '四川'); INSERT INTO `test_1` VALUES ('3', 'ccc', '县污水处理厂', '四川'); INSERT INTO `test_1` VALUES ('4', 'ddd', '镇污水处理厂', '四川');