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?
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?
(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
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
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
posted by mbrubeck at 7:27 PM on July 27, 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]
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
you can do what mbrubeck said, but it's a pain.
posted by juv3nal at 12:29 AM on July 29, 2007
This thread is closed to new comments.
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