赞
踩
上次写了一个bat,根据输入的数字,进入对应的MySQL命令行,链接如下:
bat批处理:根据输入的数字,进入对应的MySQL命令行https://blog.csdn.net/weixin_43893037/article/details/130164627
这个地址,端口,用户名都写死了,有时候不是很方便。这次搞了一个提示输入这三个信息,然后根据输入的信息,进入对应的MySQL命令行。
两个各有各的优点,直接上代码!
- @echo off
-
- title MySQL Utils
-
- color 0A
- MODE con: COLS=60 LINES=20
- echo ============================
- echo MySQL Utils
- echo ============================
-
- set firstFlag=true
- goto queryHost
-
- :queryHost
- set host=
- set /p host=请输入地址(留空为localhost):
- if "%host%"=="" (
- set host=-h localhost
- ) else (
- set host=-h %host%
- )
- echo 地址为:%host%
- echo ============================
- if "%firstFlag%"=="true" (
- goto queryPort
- ) else (
- goto queryStart
- )
-
- :queryPort
- set port=
- set /p port=请输入端口(留空为3306):
- if "%port%"=="" (
- set port=-P 3306
- ) else (
- set port=-P %port%
- )
- echo 端口为:%port%
- echo ============================
- if "%firstFlag%"=="true" (
- goto queryUser
- ) else (
- goto queryStart
- )
-
- :queryUser
- set user=
- set /p user=请输入用户名(留空为root):
- if "%user%"=="" (
- set user=-u root
- ) else (
- set user=-u %user%
- )
- echo 用户名为:%user%
- echo ============================
- goto queryStart
-
- :queryStart
- set firstFlag=false
- set query=
- echo 当前命令为:mysql -p %host% %port% %user%
- echo ----------------------------
- echo 回车:确认无误,进入MySQL console
- echo 数字1:更改地址
- echo 数字2:更改端口
- echo 数字3:更改用户
- echo ============================
- set /p query=请选择:
- if "%query%"=="" (
- goto openConsole
- )else if "%query%"=="1" (
- cls
- goto queryHost
- )else if "%query%"=="2" (
- cls
- goto queryPort
- )else if "%query%"=="3" (
- cls
- goto queryUser
- )else (
- echo 输入有误
- echo ============================
- goto queryStart
- )
-
- :openConsole
- cls
-
- echo Connecting to mysql -p %host% %port% %user%
- echo ========================================================
-
- mysql -p %host% %port% %user%
-
- echo Connection closed.
-
- pause
- cls
- goto queryStart
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。