By dos batch command, implement the system context switches

technology

Two mysql

Scene Description:

Application systems can be configured according to the database parameters to determine the current mode is the formal environment or test environment;
depending on the application front desk does not provide configuration functions Each time you switch, you need to use the tool to connect mysql database, and then modify the database configuration.

Problem Description

Due to frequent switching and formal testing environment, modify the database configuration parameters are more complicated by mysql tools;

Solution

This article explains how to use the dos batch command, to achieve switching system environment.

Steps

1, the relevant documents

Here Insert Picture Description

  • System Configuration Table .sql
/*
系统配置表
*/
create table sys_config(
cfg_id int, /*主键*/
cfg_name varchar(20), /*配置名称*/
cfg_notes varchar(50), /*配置描述信息*/
cfg_value varchar(20), /*配置值*/
constraint pk_sys_config primary key(cfg_id)
)
;
-- 写入数据
insert into sys_config(cfg_id, cfg_name, cfg_notes, cfg_value) values(1,'env_opt','系统环境(1:正式,2:测试)','1');

-- 查询数据
select * from sys_config;

  • Formal environment .sql
-- 切换正式环境
update sys_config set cfg_value = '1' where cfg_id = 1;

  • .Sql test environment
-- 切换测试环境
update sys_config set cfg_value = '2' where cfg_id = 1;

  • Context switching .bat
@echo off
echo -------------------------------
echo 请选择需要切换的环境
echo [1]正式环境(默认)
echo [2]测试环境
echo -------------------------------
set /p env_opt=请输入[1]:

if "%env_opt%"=="1" goto opt1
if "%env_opt%"=="2" goto opt2

:opt1
echo 正在切换环境:正式
set cfg_value=正式环境.sql
goto :exec_cmd

:opt2
echo 正在切换环境:测试
set cfg_value=测试环境.sql

:exec_cmd
mysql -u root -p123456 -h 127.0.0.1 test <%cfg_value%
IF ERRORLEVEL 1 goto err_change
echo 切换成功!
pause
exit

:err_change
echo 切换失败!
pause

2, the effect screenshots

Here Insert Picture Description

Published 230 original articles · won praise 29 · Views 230,000 +

Guess you like

Origin blog.csdn.net/huryer/article/details/104011379