運行.bat執行sql文件 —— mysql
阿新 • • 發佈:2019-01-24
log host fault rds rec color done 四川 htm
參考地址: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‘, ‘鎮汙水處理廠‘, ‘四川‘);
運行.bat執行sql文件 —— mysql