Vim用来当SQL Server Client?

最近迷上了Vim 了,感觉它有无穷无尽的玩法。那么它可以用来简单的查oracle 数据库吗?因为有一些现场只有ssh远程,如果直接在命令行 sqlplus用来查,总感觉体验不是很好。如果可以使用vim插件来查数据库会不会体验好一些呢?

vim-dadbod

Dadbod是一个用于与数据库交互的Vim插件。
项目地址:
https://github.com/tpope/vim-dadbod

vim-dadbod-ui

基于 vim-dadbod有图形化界面,比较好上手。
安装
我使用的是:Vundle插件管理器

Plugin 'kristijanhusak/vim-packager'
Plugin 'tpope/vim-dadbod'
Plugin 'kristijanhusak/vim-dadbod-ui'

:PluginList安装就搞定了。

数据源配置。
比如:

vim ~/.vim/vimrc

这里我以oracle为例。

let g:dbs = [
\ { 'name': 'centos', 'url': 'oracle://usr_sg:apexsoft@CentOS' },
\ { 'name': 'centos2', 'url': 'oracle:usr_sg/apexsoft@172.16.184.5:1521/orcl' }
\ ]

第一种是连接 tnsnames.ora 中配置的服务的形式。
第二种是直接连接的方式。
个人感觉第二种方式更简单直接一些。

查sql

:DBUI打开界面。
输入sql 在执行 :w后就会执行查询操作了。
在这里插入图片描述

使用 nerd fonts图标

vim的配置文件中加入以下内容,开启图标显示

let g:db_ui_use_nerd_fonts=1

显示效果确实要好一些了。
在这里插入图片描述

这下有图标了。

如果图标显示乱码,说明字体没有安装完成,可以参考《macOS中SpaceVim搭建java开发环境》
搜索 “字体乱码问题”

帮助

*dadbod.txt*

Author:  Tim Pope <http://tpo.pe/>
Repo:    https://github.com/tpope/vim-dadbod
License: Same terms as Vim itself (see |license|)

USAGE                                           *dadbod* *:DB*

:DB [url]               Start an interactive database console.  Uses
                        dispatch.vim's |:Start| if available.

:DB [url] {cmd}         Run {cmd} on the selected database and show the
                        results in a preview window.

:{range}DB [url]        Run the lines referenced by {range} on the selected
                        database and show the results in a preview window.

:DB [url] < {file}      Run the given {file} on the selected database and show
                        the results in a preview window.

:DB {var} = {url}       Assign the canonicalization of {url} to a |g:|, |w:|,
                        |t:|, |b:|, or environment variable.

:DB [url] :{command}    Run the Vim command {command} with the given URL set
                        as the default.  This is mainly useful with
                        |g:dadbod_manage_dbext|.

In the preview window, you can press "R" to rerun, "r" to interactively rerun,
or "q" to close the window.

URLS                                            *dadbod-urls*

URLs are adapter specific but generally take one of two formats:
>
    adapter://[user[:password]@][host][:port]/[database]
    adapter:[database]

A complete reference is below under |dadbod-adapters|, but a few examples should
mostly get the point across:
>
    postgresql://postgres:secret@remote-host/test
    mysql://root@localhost/test
    sqlite:db.sqlite3
    mongodb:///admin
    redis:///
<
Additionally, one can give:

* A Vim variable (e.g., g:foo, w:bar, t:baz, b:quux) or environment variable
  (e.g., $DATABASE_URL) containing a URL.
* File name of a supported database file (e.g. ~/db.sqlite3). Relative paths
  must start with "./", and spaces must be %20 URL encoded (NOT backslash
  escaped).

VARIABLES                                       *dadbod-variables*

If a |w:|, |t:|, |b:|, |g:|, or $ENVIRONMENT variable is given as a URL, its
value will be used.  Additionally, if no URL is given, the first of w:db,
t:db, b:db, $DATABASE_URL, and g:db will be used.  Suggested uses:

* w:db is best set interactively.
* b:db is most useful when set from an |autocommand|.
* g:db and other globals can be set in your |vimrc| or other startup file.
* $DATABASE_URL and other environment variables are easy to set externally.

Set a variable with |:let|, or use |:DB| to normalize the URL first:
>
    :DB w:db = adapter://...
<
ADAPTERS                                        *dadbod-adapters*

                                                *dadbod-dbext*
dbext ~
>
    dbext:type=<type>[:<attr>=<value>][...]
    dbext:profile=<profile>[...]
<
For supported adapters, dbext modelines and profiles can be used directly.

                                                *dadbod-impala*
Impala ~
>
    impala://[<host>[:<port>]]/[<database>]
<
                                                *dadbod-jq*
jq ~
>
    jq:relative/path
    jq:/absolute/path
    jq:C:/windows/path
    jq:///relative/or/absolute/path
<
An empty path runs jq without input, see --null-input parameter.

                                                *dadbod-mongodb*
MongoDB ~
>
    mongodb://[<user>[:<password>]@][<host>[:<port>]]/[<database>][?ssl=true]
    mongodb:[<database>]
<
                                                *dadbod-mysql*
MySQL ~
>
    mysql://[<user>[:<password>]@][<host>[:<port>]]/[database]
    mysql://[<user>[:<password>]@][<%2Fsocket%2Fpath>]/[<database>]
    mysql:///[<database>]?login-path=<login-path>
    mysql:[<database>]
<
                                                *dadbod-oracle*
Oracle ~
>
    oracle://[<user>[:<password>]@][<host>][:<port>]/[<database>]
    oracle:<user>/<password>@[//]<host>[:<port>]/<database>
<
                                                *dadbod-osquery*
osquery ~
>
    osquery:relative/path
    osquery:/absolute/path
    osquery:C:/windows/path
    osquery:///relative/or/absolute/path
<
An empty path portion uses an in-memory database, which is how osquery is
typically invoked.

                                                *dadbod-postgresql*
PostgreSQL ~
>
    postgresql://[<user>[:<password>]@][<host>[:<port>]]/[<database>]
    postgresql://[<user>[:<password>]@][<%2Fsocket%2Fpath>]/[<database>]
    postgresql:[<database>]
<
For interop, postgres:// URLs are also accepted.

                                                *dadbod-presto*
Presto ~
>
    presto://[<host>[:<port>]]/[<catalog>[/<schema>]]
<
                                                *dadbod-redis*
Redis ~
>
    redis://[[unused[:<password>]@]<host>]/[<database-number>]
    redis:[<database-number>]
<
Redis doesn't have a username, so use a dummy one in the URL if a password is
required.

                                                *dadbod-sqlserver*
SQL Server ~
>
    sqlserver://[<user>[:<password>]@][<host>][:<port>]/[<database>]
    sqlserver://[<host>[:<port>]][;user=<user>][;...]
<
If the user and password are omitted, a trusted connection is used.

                                                *dadbod-sqlite*
SQLite ~
>
    sqlite:relative/path
    sqlite:/absolute/path
    sqlite:C:/windows/path
    sqlite:///relative/or/absolute/path
<
In the wild, uses of sqlite:///path vary on whether the path is relative or
absolute, so both are checked.  The preferred form is sqlite:path, which
avoids this ambiguity.

An empty path portion uses an in-memory database, which is occasionally useful
for an interactive invocation.

DBEXT MANAGEMENT                                *g:dadbod_manage_dbext*

If you like Dadbod's configuration but need some of dbext's functionality, set
the following variable to enable an experimental mode where dbext's
configuration always mirrors Dadbod's default.
>
  let g:dadbod_manage_dbext = 1
<
 vim:tw=78:et:ft=help:norl:

总结

使用以后,感觉跟使用sqlplus差不了多少,只是体验略好一些,比起PL\SQL之类的工具还是差太远了。用于临时查询维护数据库还是不错的。

参考资源链接:[VMware vCenter 6.7 安装步骤解析(图文)](https://wenku.csdn.net/doc/6bqc7sh0x7?utm_source=wenku_answer2doc_content) 安装VMware vCenter 6.7 VIM版本的过程中,正确的配置对于确保系统的稳定性和安全性至关重要。首先,安装前请确保服务器满足硬件和软件的最低要求,并下载对应版本的安装程序。接着,运行安装向导并按照以下步骤进行配置: 1. 在配置网络设置时,确保使用完全限定域名(FQDN)或静态IP地址,并检查DNS服务器设置,确保vCenter能够被网络内其他设备正确解析。 2. 选择数据库类型时,如果你的环境属于生产级别,建议使用外部数据库,如Microsoft SQL ServerOracle,以支持更大的数据量和更复杂的查询。对于内嵌式数据库,虽然配置简便,但更适合小型部署和测试环境。 3. 对于端口配置,确保vCenter的默认端口没有被网络防火墙或其他安全设备阻止,并根据实际需求考虑端口的调整和安全性设置。 4. 安装过程结束后,登录vCenter Server,通过vSphere Web Client进行进一步的配置,包括添加和管理主机、创建数据中心和群集、配置网络和存储资源等。 在整个安装和配置过程中,务必参考《VMware vCenter 6.7 安装步骤解析(图文)》这份资料。它详细讲解了安装过程的每一步,并提供了图示辅助理解,是完成vCenter安装的宝贵指南。 如果你已经顺利安装并开始使用vCenter,接下来为了深入理解vCenter的高级功能和最佳实践,建议深入学习更多关于vCenter的高级配置、性能优化以及故障排除的知识。此外,VMware官方文档、社区论坛和专业博客也是学习的重要资源。 参考资源链接:[VMware vCenter 6.7 安装步骤解析(图文)](https://wenku.csdn.net/doc/6bqc7sh0x7?utm_source=wenku_answer2doc_content)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值