0

MySQL CLI: Edit previous query

Posted by admin on Apr 23, 2010 in Mac OS X, MySQL

One of the very useful features of the mysql command line utility is the ability to edit the query you just executed and then execute it again.

Here is a query:

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2010-04-23 15:57:02 |
+---------------------+
1 row in set (0.00 sec)

I can now edit this by entering the command “edit” at the mysql prompt:

mysql> edit

The query is opened in an editor (vi for me) and I can edit and save the new query. When I exit the editor, it does NOT display the query. Instead, it just says “edit” and I must now append a final semi-colon before pressing return to execute the new query:

mysql> edit
    -> ;
+--------------+---------------------+
| The time is: | now()               |
+--------------+---------------------+
| The time is: | 2010-04-23 16:00:14 |
+--------------+---------------------+
1 row in set (0.00 sec)

Copyright © 2017 Standalone Code LLC All rights reserved. Theme by Laptop Geek.