Easy-to-use MySQL client for Vim
Based on pipe.vim
Features
- Work with MySQL database at local (with respect to Vim) or at remote machine (via SSH)
- No need to have MySQL installed at local if you plan to execute MySQL statements at remote machine
- Edit MySQL script locally, execute at remote machine, and get result back in Vim's Preview window at local
- Execute a whole MySQL script file, a single line, or a block of MySQL statements
- Set SSH remote and MySQL access on the fly; or use preset for frequently used login info
- Each buffer has independent login info to database
- Easily switch database on the fly
- Include common queries to operate on the target where the cursor is at
by default, it works for filetype 'mysql'. so if you want to use othertype (ex. sql), set in your .vimrc like
au BufRead,BufNewFile *.sql set filetype=mysql
Using Vundle plugin manager:
Plugin 'NLKNguyen/pipe.vim' "required
Plugin 'NLKNguyen/pipe-mysql.vim'
The plugin comes with default keymaps for MySQL filetype. To turn off, add let g:pipemysql_no_mappings = 0
to your .vimrc file
Mode | Key | Action | Function call |
---|---|---|---|
Normal | <leader>sr |
Set remote info (SSH) | g:PipeMySQL_SetRemote() |
Normal | <leader>sa |
Set MySQL access info | g:PipeMySQL_SetAccess() |
Normal | <leader>sd |
Set database to use | g:PipeMySQL_SetDatabase() |
Normal | <leader>se |
Set all fields empty | g:PipeMySQL_SetEmpty() |
Normal | <leader>sp |
Select preset info* | g:PipeMySQL_SelectPreset() |
* See Use Preset Login Info for how to store preset login info in .vimrc file
Mode | Key | Action | Function call |
---|---|---|---|
Normal | <leader>rf |
Run MySQL script file | g:PipeMySQL_RunFile() |
Normal | <leader>rs |
Run statement on the current line (table view) | g:PipeMySQL_RunLine('table') |
Visual | <leader>rs |
Run selected block of statements (table view) | g:PipeMySQL_RunBlock('table') |
Normal | <leader>rS |
Run statement on the current line (batch view) | g:PipeMySQL_RunLine('batch') |
Visual | <leader>rS |
Run selected block of statements (batch view) | g:PipeMySQL_RunBlock('batch') |
Normal | <leader>rc |
Run custom statement (prompt) | g:PipeMySQL_RunCustom() |
Mode | Key | Action | Function call |
---|---|---|---|
Normal | <leader>dl |
List databases | g:PipeMySQL_DatabaseListing() |
Normal | <leader>ds |
Switch database | g:PipeMySQL_DatabaseSwitching() |
Normal | <leader>tl |
List tables | g:PipeMySQL_TableListing() |
Normal | <leader>ts |
Select * from table at cursor | g:PipeMySQL_TableSelectAll() |
Normal | <leader>td |
Describe table at cursor | g:PipeMySQL_TableDescription() |
Normal | <leader>tD |
Show create SQL definition of table at cursor |
g:PipeMySQL_TableDefinition() |
In .vimrc
you can store frequently used login info like the below snippet. The description
value is what you see in the list of preset info in order to select.
All other fields are optional. They can be set on the fly using the Set Actions; therefore, you don't have to store sensitive information like password in .vimrc if you don't want to.
if in your preset mysql_password is not specified, then follow mysql-clients setting for that.
(for example, find it from .my.cnf
).
and you can also use defaults file for mysql access configuration.
in below example, using .test.my.cnf file for 4th preset.
let g:pipemysql_login_info = [
\ {
\ 'description' : 'my server 1',
\ 'ssh_address' : 'root@server1',
\ 'ssh_port' : '',
\ 'mysql_hostname' : 'somehostname',
\ 'mysql_username' : 'my_username',
\ 'mysql_password' : 'my_password',
\ 'mysql_database' : 'cs332h20'
\ },
\ {
\ 'description' : 'my server 2',
\ 'ssh' : 'root@server2',
\ 'mysql_hostname' : 'somehostname',
\ 'mysql_username' : 'my_username',
\ },
\ {
\ 'description' : 'my local',
\ 'mysql_hostname' : 'localhost',
\ },
\ {
\ 'decription' : 'using defaults file',
\ 'mysql_defaults_file' : '$HOME/.test.my.cnf'
\ }
\ ]
example for .test.my.cnf this configuration is can be used when your enviroments are diverse, and maintain connection with seperated file as traditional in mysql configuration.
[mysql]
host=my-awesome-prod-server
user=my-user
password=my_password
In .vimrc
you can set mysql options by using variables.
let g:pipemysql_option = '-vvv'
let g:pipemysql_pager = 'grcat ~/.grcat'
the variables
variable | description |
---|---|
pipemysql_option | set mysql custom option. for example (-vvv, -show-warnings). some options actually does not affect behavior cause the client was disconnected after executes. check: mysql-doc |
pipemysql_pager | give pager option to mysql client. check: mysql-doc |
👤 Nikyle Nguyen
- Website: https://dephony.com/Nikyle
- Twitter: @NLKNguyen
- Github: @NLKNguyen
- LinkedIn: @NLKNguyen
Give a ⭐️ if this project helped you working with MySQL in Vim seamlessly!
Contributions, issues and feature requests are welcome! Feel free to check issues page.
I create open-source projects on GitHub and continue to develop/maintain as they are helping others. You can integrate and use these projects in your applications for free! You are free to modify and redistribute anyway you like, even in commercial products.
I try to respond to users' feedback and feature requests as much as possible. Obviously, this takes a lot of time and efforts (speaking of mental context-switching between different projects and daily work). Therefore, if these projects help you in your work, and you want to encourage me to continue create, here are a few ways you can support me:
- 💬 Following my blog and social profiles listed above to help me connect with your network
- ⭐️ Starring this project and sharing with others as more users come, more great ideas arrive!
- ☘️ Donating any amount is a great way to help me work on the projects more regularly!
Thanks to all contributors who make pipe-mysql.vim great! ❤️
Copyright © 2015 - 2020 Nikyle Nguyen
The project is MIT License