LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   vi editor and mysql (https://www.linuxquestions.org/questions/slackware-14/vi-editor-and-mysql-190164/)

slackerboy 06-05-2004 08:29 PM

vi editor and mysql
 
Hi there,

I am trying to use vi or even emacs from within mysql
and neither one seems to work. I even checked my.cnf
but did not see anything that could help me set up any
editor. I know that by default mysql uses vi.

My problem is that I would like to edit sql scripts inside
mysql. As it is right now, I have to open another xterm and
invoke emacs or vi to edit the scripts. I can execute them
from mysql (source filename.sql). has anyone seen this
problem? It is kicking my rear end hard. I'm using mysql
version 4.1.1-alpha.

Thaks in advance for any feedback.

keefaz 06-06-2004 12:08 PM

Quote:

I know that by default mysql uses vi.
Where did you learn that ?

solnul 06-07-2004 01:33 AM

I assume you're talking about the MySQL monitor you get by logging into a DB with the mysql command? This program doesn't use either vi or emacs. It uses the GNU readline command line editing library. The default keybindings are emacs-like, and configured in ~/.inputrc.

There are all sorts of other interfaces you can use. For example, if you want to connect to MySQL inside Emacs, use "M-x sql-mysql", which opens a comint buffer with the monitor.

slackerboy 06-09-2004 07:07 PM

keefaz: I noticed the default editor after I attempted
to open an sql script from inside mysql: I saw the typical
~ in a vertical line from top to bottom.

====
solnul: no luck on your suggestion from inside mysql.
Maybe there is something else going on here that I need
to sort out. I managed to set the editor to emacs via my
.bash_profile. However, I cannot get to the scripts I
want. I know I am getting closer to resolving this puzzle.
By the way, I do not have a file named .inputrc.

Thanx for the feedback anyway :D

keefaz 06-10-2004 03:53 PM

I was curious and just do :
Code:

$ mysql -u admin -p
mysql> help
...
pager  (\P)    Set PAGER [to_pager]. Print the query results via PAGER.
...
mysql> pager vi
mysql>

...and all result of query return in a sort of vi editor, but I didn't find a good way to exit this mode after ;)

slackerboy 07-12-2004 09:01 PM

Ok, I found the answer to my previous question: according to the book
'Beginning Databases with MySQL" by Neil Mathews and Richard Stones,
chapter 5, page, 121, the default editor for MySQL is vi. However, the
choice of an editor can be altered by passing it as an option when
connecting to MySQL.. I'll try that next.

dotancohen 12-18-2012 10:18 AM

Quote:

Originally Posted by keefaz (Post 984076)
I was curious and just do :
Code:

$ mysql -u admin -p
mysql> help
...
pager  (\P)    Set PAGER [to_pager]. Print the query results via PAGER.
...
mysql> pager vi
mysql>

...and all result of query return in a sort of vi editor, but I didn't find a good way to exit this mode after ;)

Use the 'nopager' command:
Code:

> nopager
The pager is meant to filter the output from mysqld, not mean to edit the input. To edit the input, use the '\e' command. It leaves a lot to be desired, though, as you can only edit the previous command, and the command is not shown in the CLI afterward.

astrogeek 12-18-2012 02:48 PM

I think what you are after is to execute a shell command from within the mysql client.

Do that like this

Code:

\! command
So to edit the file slack.sql you would do this:

Code:

\! vi slack.sql
Then, of course, to execute the file:

Code:

\. slack.sql
[EDIT]
I just noticed this is a very old thread that someone woke up - hope the answer is useful to someone! :)
[/EDIT]

dotancohen 12-19-2012 05:34 AM

The post was useful to me, Astrogeek! I usually have an extra screen window open just to run the occasional Bash command, you just saved me the trouble!

I once has someone reply to a four-year-old thread of mine with a useful answer that was able to help me, and other people will google the threads (I found this thread through google) so helpful answers to old questions are still relevant.


All times are GMT -5. The time now is 12:50 PM.