-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae237fc
commit cdb896c
Showing
4 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,43 @@ | ||
# vim-mysql | ||
# vim-mysql | ||
|
||
<!-- more --> | ||
<!-- toc --> | ||
## 安装 | ||
### Pathogen | ||
```bash | ||
$ cd ~/.vim/bundle | ||
$ git clone https://github.com/wxnacy/vim-mysql.git | ||
$ cd ~/.vim/bundle/vim-mysql | ||
$ ./install.sh | ||
``` | ||
|
||
### Vundle | ||
修改 `~/.vimrc` | ||
```bash | ||
Plugin 'wxnacy/vim-mysql' | ||
``` | ||
在 Vim 中运行 | ||
```bash | ||
:PluginInstall | ||
``` | ||
```bash | ||
$ cd ~/.vim/bundle/vim-mysql | ||
$ ./install.sh | ||
``` | ||
|
||
## 配置 | ||
配置密码 | ||
```bash | ||
echo 'export MYSQL_LOCAL_USER=your_local_user' >> ~/.bash_profile | ||
echo 'export MYSQL_LOCAL_PASSWORD=your_local_password' >> ~/.bash_profile | ||
echo 'export MYSQL_LOCAL_HOST=your_local_host' >> ~/.bash_profile | ||
source ~/.bash_profile | ||
``` | ||
这样可以配置 ***local***环境的 Mysql 信息,如果需要 ***prod*** 环境 | ||
可以继续配置 `MYSQL_PROD_USER, MYSQL_PROD_PASSWORD, MYSQL_PROD_HOST` | ||
|
||
## 使用 | ||
```bash | ||
<Leader>rs # 在 normal 模式运行光标所在行的命令 | ||
<Leader>rsp # 在 prod 环境中运行 mysql 命令 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
VIM_MYSQL=`pwd` | ||
echo $VIM_MYSQL | ||
echo `pwd` | ||
|
||
ln -sf ${VIM_MYSQL}/plugin/mysql_run /usr/local/bin/mysql_run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env expect | ||
|
||
set timeout 10 | ||
|
||
if { $argc == 0 } { | ||
set ENV local | ||
} | ||
if { $argc > 0 } { | ||
set ENV [lindex $argv 0] | ||
set sql [lindex $argv 1] | ||
} | ||
if { $ENV == "local" } { | ||
set name $env(MYSQL_LOCAL_USER) | ||
set password $env(MYSQL_LOCAL_PASSWORD) | ||
set host $env(MYSQL_LOCAL_HOST) | ||
} | ||
if { $ENV == "prod" } { | ||
set name $env(MYSQL_PROD_USER) | ||
set password $env(MYSQL_PROD_PASSWORD) | ||
set host $env(MYSQL_PROD_HOST) | ||
} | ||
|
||
spawn sh -c "mysql -u$name -p -h ${host} --tee=/data/log/mysql/`date +%Y-%m-%d`.log" | ||
expect "*assword:*" | ||
send "$password\r" | ||
expect "*>" | ||
send "$sql;\r" | ||
send "exit;\r" | ||
interact |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
select * from screen limit 1\G; |