mysql在win上bat脚本使用

init.bat

@echo off  
chcp 65001

set MYSQL_BIN="C:\Program Files\MySQL\MySQL Server 5.7\bin\"

set HOST=localhost
set USR=root
set PWD=xxx
set NAME=etag

echo ###正在创建及初始化数据库###
:begin
	%MYSQL_BIN%mysql -h%HOST% -u%USR% -p%PWD% < init.sql
echo ###创建及初始化数据库完毕###

PAUSE
exit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

init.sql

SET NAMES utf8mb4;

-- DROP DATABASE if exists etag;
CREATE DATABASE IF NOT EXISTS etag CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
SHOW DATABASEs;
USE etag;

SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for category
-- ----------------------------
-- DROP TABLE IF EXISTS `category`;
CREATE TABLE IF NOT EXISTS `category` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `unique_type_id` int(11) DEFAULT NULL,
  `level` int(11) DEFAULT NULL,
  `type` int(11) NOT NULL,
  `cover` text COLLATE utf8mb4_unicode_ci,
  `createdAt` datetime NOT NULL,
  `updatedAt` datetime NOT NULL,
  `version` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
上次更新: 2022/04/15, 05:41:31
×