前往release页面中找到最新的jar,当前最新版本为java-sql-cli-1.0.jar
在java-sql-cli-{version}.jar的同一目录下,创建一个名为application.properties的文件
touch application.properties在此文件中键入相关配置(花括号中的配置项需要改成自己的),下面分别是oracle和mysql的配置文件示例
# oraclejdbc.driver=oracle.jdbc.OracleDriver jdbc.url=jdbc:oracle:thin:@{db_ip}:{port}/{scheme} jdbc.username={username} jdbc.password={password} outputfile=output.log# mysqljdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://{db_ip}:{port}/{databases} jdbc.username={username} jdbc.password={password} outputfile=output.logjava -jar java-sql-cli-{version}.jar注意此步骤是在启动jar之后的交互界面中进行的
exec"select * from help_keyword limit 10"默认返回的是一个表格,如下
+---------------------------------------------+ | Result | |---------------------------------------------| |help_keyword_id| name | |---------------------------------------------| | 670 | (JSON | | 475 | -> | | 658 | <> | | 510 | ACCOUNT | | 642 | ACTION | | 450 | ADD | | 327 | AES_DECRYPT | | 619 | AES_ENCRYPT | | 497 | AFTER | | 398 | AGAINST | | 109 | AGGREGATE | | 456 | ALGORITHM | | 217 | ALL | +---------------------------------------------+ 还可以通过—json选项来指定返回值按照json的格式来输出
exec"select * from help_keyword limit 5" --json返回的是一段json字符串,如下
[{"name":"(JSON", "help_keyword_id":"670" },{"name":"->", "help_keyword_id":"475" },{"name":"<>", "help_keyword_id":"658" },{"name":"ACCOUNT", "help_keyword_id":"510" },{"name":"ACTION", "help_keyword_id":"642" } ]执行过的sql,其结果会自动保存到output.log之中(文件名称可以在application.properties中修改)