MySQL Command Line Client: editing lines of a multiple line statement?
July 27, 2007 7:14 PM   Subscribe

Very very very stupid MySQL command line client question: how do I edit an earlier line of a multiple line statement?

So say I've done this:

mysql> create table CUSTOMER_TBL
-> (
-> CUST_ID VARCHAR(!0) NOT NULL primary key,
-> CUST_NAME VARCHAR(30) NOT NULL,
-> CUST_CITY VARCHAR(20) NOT NULL, etc...

How do I get back to the third line and change "(!0)" to "(10)"? The help files for the tool don't have this level of novice information. The closest thing I've found is using "\c" to cancel the current statement and start over, but there must be something less draconian, right?

Also, is this specifically a MySQL issue or is this some basic command line convention I don't know? If it is, what else am I likely not to know as a newbie, and what's the best way to fill in the gaps?
posted by Lentrohamsanin to Computers & Internet (8 answers total)
 
Best answer: You can't edit previous lines. Just type it all on one line. The multi-line thing is really just handy for cutting and pasting. If you need multiline editing, edit in a text editor and either cut and paste or use the \. command to read in a file full of SQL that you saved.

It is a command-line convention, thanks to the "readline" library. At a bash prompt, if you typed

for flie in *; do
echo $file;

you can't go back and fix "flie" either!
posted by mendel at 7:18 PM on July 27, 2007


(And if you find yourself stuck, control-C will exit mysql without running the statement you're typing.)
posted by mendel at 7:20 PM on July 27, 2007


Type "\e" to edit the statement in the buffer. Up-arrow should also bring back the previous statement.
posted by ldenneau at 7:25 PM on July 27, 2007


After you \c, you can press the "up" arrow key to re-edit a previous line.
posted by mbrubeck at 7:27 PM on July 27, 2007


yeah, it's '\e'.

in bash, hit ctrl-c and then 'fc'.
posted by sfenders at 8:12 PM on July 27, 2007


in bash, hit ctrl-c and then 'fc'.

Or just Ctrl+X, E.
posted by grouse at 3:50 AM on July 28, 2007


I like to break big queries across multiple lines while prototyping them, especially when there are lots of joins involved, so I'll write them in whichever simple text editor the OS provides, then copy/paste them into mysql.
posted by dws at 12:58 PM on July 28, 2007 [1 favorite]


seconding what dws said.
you can do what mbrubeck said, but it's a pain.
posted by juv3nal at 12:29 AM on July 29, 2007


« Older The Movers Say the Muffins Aren't Enough.   |   Missing: Lemon basil marinade. Newer »
This thread is closed to new comments.