You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the sake of security and convenience, this plugin utilizes a command line parameter of MySQL client called `defaults-group-suffix`, for more details about `defaults-group-suffix`, check out the documentation [here](https://dev.mysql.com/doc/refman/5.5/en/option-file-options.html#option_general_defaults-group-suffix); but now just put your configuration in the file `~/.my.cnf` like this:
55
+
Be sure you have `git` installed and configured to [authenticate to github.com via ssh](https://docs.github.com/en/authentication/connecting-to-github-with-ssh).
56
+
In your terminal...issue the following commands, one by one (this assumes you have `git` installed and configured):
**Note**: if you already use `.my.cnf`, then add the new contents at the end. As your configuration options will be read after the main `[Client]` ones, you do not need to repeat those if the values are the same, for example, to set up a section for a particular database using your normal credential, your `.my.cnf` might look like this:
66
+
## Usage
69
67
70
-
```conf
71
-
[client]
72
-
user = mymysqlmamaria
73
-
password = neveryoumind
68
+
There are two things to do after installation:
69
+
70
+
1. Put your database credentials in `~/my.cnf`
74
71
75
-
# ↑ that config was there before
76
-
# ↓ this config is what we added
77
-
[clientMyDb]
78
-
database = mydb
79
72
```
73
+
[client]
74
+
user=your_user_here
80
75
81
-
## Usage
76
+
[clientAnysuffix]
77
+
database=mydb"
78
+
```
82
79
83
-
Create a new file whose name ends with `.sql`, adding the following three lines in the very beginning of the file:
80
+
2. Use vim to issue mysql commands!
81
+
82
+
-`vim anyfile` (so that you can type your sql)
83
+
- typically using a file with name ending in `.sql` is best (for syntax highlighting)
84
+
- at the top of the file you may put command line args (but one is mandatory)
85
+
- the `--defaults-group-suffix` has to be there (at least the `database` parameter must be set)
86
+
- the suffix is a personal choice but it must match what is in your my.cnf (see "Anysuffix" in example)
87
+
-[read more about defaults-group-suffix](https://dev.mysql.com/doc/refman/5.5/en/option-file-options.html#option_general_defaults-group-suffix)
88
+
- the `--login-path` option is useful
89
+
- this can be set to makes use of `mysql_config_editor` created `my_login.cnf` files
90
+
- the syntax for this is `--login-path=<configured db path>` for instance `--login-path=myMysql`
91
+
- the `-t` switch sets the output to table
92
+
- omit this to get raw, tabbed output
93
+
- omit this and replace the semi-colon at the end of the query with '\G' to get vertical format
94
+
- each mysql option **must** be on its own line
84
95
85
-
```sql
86
-
-- --defaults-group-suffix=ExampleTest
96
+
```
97
+
-- --defaults-group-suffix=Anysuffix
87
98
-- -t
88
99
--
100
+
101
+
SELECT * FROM USER;
102
+
```
103
+
- Query `SELECT * FROM USER` with these keystrokes _(`<CR>` is carriage return/"enter")_:
104
+
105
+
```
106
+
/SELECT<CR>
107
+
V
108
+
\rs
89
109
```
90
110
91
-
Notes:
111
+
The following is a description of the commands including an explanation of the `\SELECT<CR>V\rs` sequence:
92
112
93
-
- The first line with `--default-group-suffix` identifies the configuration **suffix**, defined above. i.e. we're entering `ExampleTest` not `ClientExampleTest`. To use the 2nd configuration example you'd use `--default-group-suffix=MyDb`.
113
+
-`/SELECT` then *<CR>* moves your cursor (via *search*) to the query
114
+
-`V`*shift+v* selects the entire query (line)
115
+
-`\rs` issues `<leader>`+rs
116
+
- earlier we set `mapleader` to backslash _(change it in .vimrc)_
94
117
95
-
- The -t option means output as a table. You can ommit this if you want bare output.
118
+
Query results appear in a split pane.
96
119
97
-
- Each mysql option **must** be on its own line.
120
+
Remember to delimit your queries with semi-colons.
98
121
99
-
Then add your sql statements following the three lines. Here is a sample of the `sql` file:
122
+
### Command Reference
100
123
101
-
```sql
124
+
-`<leader>rr` "Run Instruction"
125
+
-`<leader>ss` "Select Cursor Table"
126
+
-`<leader>ds` "Descript Cursor Table"
127
+
-`<leader>rs` "Run Selection"
128
+
-`<leader>re` "Run Explain"
129
+
130
+
"Run Instruction" executes query and can be run from anywhere within the query.
131
+
132
+
"Explain" can be run from anywhere within the query.
133
+
134
+
"Selection" means select _query_ before issuing command.
135
+
136
+
"Cursor" means place your cursor on _the table_ to issue command.
137
+
138
+
"Selection" means select _query_ before issuing command.
139
+
140
+
### Usage Notes
141
+
142
+
If you already use `.my.cnf`, then add the new `[clientAnySuffix]` group at the end. As your configuration options will be read after the main `[Client]` ones, you do not need to repeat those if the values are the same, for example, to set up a section for a particular database using your normal credential, your `.my.cnf` might look like this:
143
+
144
+
```conf
145
+
[client]
146
+
user = mymysqlmamaria
147
+
password = neveryoumind
148
+
149
+
# ↑ that config was there before
150
+
# ↓ this config is what we added
151
+
[clientMyDb]
152
+
database = mydb
153
+
```
154
+
155
+
This is because `database` must be set, when the query is issued the database must already be selected.
156
+
157
+
Remember, add your sql statements following the three lines. Here is another sample `sql.sql` file:
158
+
159
+
```sql.sql
102
160
-- --defaults-group-suffix=ExampleTest
103
161
-- -t
104
162
--
105
163
106
164
SELECT*FROM USER;
107
165
```
108
166
109
-
- Move the caret to the line `select * from user;` and type `<leader>rr` in VIM normal mode to run the line;
167
+
Here are more examples of how to run `SELECT * FROM USER:`
110
168
111
-
- Move the caret to the table name (such as `user`) and type `<leader>ds` (stands for "Descript") to show the columns of the table, type `<leader>ss` to `SELECT *` from the table;
169
+
- Position caret/cursor on line `SEELCT * FROM USER;` and (in VIM normal mode) type `<leader>rr`
170
+
- if the query does not run, but instead a replacement of the character underneath the cursor occurs your `<leader>` is not set
171
+
- to set `<leader>` to the recommended backslash place `let mapleader = '\'` in your `.vimrc`
112
172
113
-
- Using VIM visual mode to select a range of statement and type `<leader>rs` to execute the selected statements;
173
+
- Position caret/cursor on (within) the table name (`USER`) and type `<leader>ds` (stands for "Descript") to show the columns of the table
174
+
- Type `<leader>ss` to select all from the `USER` table
114
175
115
-
> `<leader>` is the "leading key" when mapping a shortcut to a specific function, the default `<leader>` may be `\`
176
+
- Using VIM visual mode, select a range of statement and type `<leader>rs` to execute the selected statements
177
+
- the results (if multiple queries selected) will stack in the result window
116
178
117
-
After typing the shortcut the VIM window will be splitted into two, the bottom of which will show the result of the statement;
179
+
Remember, after typing the shortcut the VIM window will be splitted into two, the bottom of which will show the result of the statement.
180
+
Switch windows by typing [Cntl-W]+[W]. [Read more about split window navigation in VIM](http://vimdoc.sourceforge.net/htmldoc/windows.html#window-move-cursor)
181
+
182
+
Remember to delimit your queries with semi-colons.
118
183
119
184
## Contribution
120
185
121
186
If you find it difficult to use this plugin, please open issues or help to improve it by creating pull requests.
122
187
123
188
## Change log
124
189
190
+
- Added a simplified install sequence with some descriptions that may be useful for those just getting started in vim.
191
+
125
192
- Security improvement: all shell commands are escaped with shellescape(). This means MySQL command options must now be one-per-line.
126
193
127
194
- Security improvement: Previously SQL with double quotes `"` that was run with `<Leader>rr` would escape the shell argument, meaning the following code was run in the shell(!). This would potentially do very bad things.
0 commit comments