[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems trying to use MySQL in conjunction with Emacs

From: Tim X
Subject: Re: Problems trying to use MySQL in conjunction with Emacs
Date: Thu, 03 Feb 2011 08:34:32 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

MBR <address@hidden> writes:

> I'm running into a problem trying to use MySQL in conjunction with Emacs.  Let
> me start by giving the relevant version information:
>     Local OS: Windows XP, SP3
>     Terminal emulator/SSH client: Putty 0.58
>     Remote OS: Linux 2.6.18
>     Emacs version (running on remote OS): 21.4.1
>     MySQL version (running on remote OS): 5.0.91
> I always have a shell buffer running inside Emacs, and I'd like to run the
> command 'mysql' so I can run SQL queries.  But if I type
>     mysql -uuserid -ppassword
> it just hangs.  When I kill the mysql process, it reports:
>     bash: [5423: 2] tcsetattr: Invalid argument
> Years ago I wrote C code that called tcsetattr() to set flags for the tty
> device driver.  I remember it being based on the idea that a tty was connected
> via RS-232, and many of the attributes you set via tcsetattr() controlled
> characteristics of the RS-232 connection - baud rate, parity, etc.  Obviously,
> for pseudo-ttys, most of that is irrelevant.  It looks like the 'mysql'
> executable is trying to do some hardware control that doesn't work in the
> context of an Emacs shell buffer.
> As I investigated further, I discovered that Emacs has a Lisp function named
> sql-mysql which sounds like it runs MySQL queries directly.  That sounded good
> to me.  But when I tried it I ran into different problems.
> What little documentation I could find on how to use M-x sql-mysql was rather
> incomplete.  It didn't give any information on how to run a query. 
> says,
>     "Type M-x sql-help RET to read the online help."
> so I did that.  The help suggests running:
>     M-x sql-mysql
> to invoke MySQL, and then says,
>     "Once you have the SQLi buffer, you can enter SQL statements in the
>     buffer.  The output generated is appended to the buffer and a new prompt 
> is
>     generated."
> The buffer never displayed a prompt.  I can't click on the items in the 
> menubar
> at the top because I'm connecting via ssh (client is putty), and putty doesn't
> seem to transmit mouse clicks.  So I can't get at the "SQL" or "In/Out" menus
> in Emacs' menubar.
> I tried sending a C-c (by typing C-c C-c) to the *SQL* buffer, expecting that
> would cause it to exit, just like a shell buffer.  Much to my surprise, IT
>     Ctrl-C -- exit!
>     Process SQL exited abnormally with code 1
> I then noticed that M-x sql-help also says:
>     "If you have a really complex SQL statement or if you are writing a
>     procedure, you can do this in a separate buffer. Put the new buffer in
>     `sql-mode' by calling M-x sql-mode.  The name of this buffer can be
>     anything.  The name of the major mode is SQL."
>     "In this SQL buffer (SQL mode), you can send the region or the entire
>     buffer to the interactive SQL buffer (SQLi mode).  The results are 
> appended
>     to the SQLi buffer without disturbing your SQL buffer."
> So I created a second buffer, named it "my-sql-buffer" and ran M-x sql-mode. 
> When I type the query:
>     show tables;
> into that buffer and terminate it with RET, nothing happens in the *SQL*
> buffer.  I tried positioning my cursor at the end of the query and typing C-c
> C-c.  The minibuffer at the bottom displayed:
>     "Sent string to buffer *SQL*."
> but nothing appeared in the *SQL* buffer.  I typed C-c C-c a few more times. 
> Each time the minibuffer redisplayed:
>     "Sent string to buffer *SQL*."
> After typing C-c C-c several times, suddenly output appeared in the *SQL*
> buffer.  It was the output from:
>     show tables;
> repeated 5 times!  Except the last time stopped in the middle.  This behavior
> suggests that something is buffering the output.  I checked how many bytes had
> been output (C-x h M-C-| wc -c) and it had output 4096 bytes!  Since 4K is a
> common buffer size, this confirms my suspicion that something is buffering the
> output.  But I can't figure out what's doing the buffering and how to turn the
> buffering off.
> Can anyone help me solve one or more of the following problems:
> 1. How to run the mysql executable from a bash prompt inside emacs and not 
> have
> it hang when it calls tcsetattr()?
> 2. How to run M-x sql-mysql, type a query into the *SQL* buffer and actually
> get it to run without making the SQL process exit?
> 3. How to flush the output to *SQL* after each query when I type a query into 
> a
> second buffer that's in sql-mode?
> advTHANKSance for your help.
>     Mark Rosenthal
>     address@hidden

I use sql-mode aq lot with Oracle and postgres and it works really well.
I'm a bit strapped for time right now, but here are some brief

1. Make sure you can run/access the myseql database from the command
line prior to starting emacs. 

2. After starting emacs, do M-x customize-group <ret> sql <ret)

and got through the various settings for mysql and set to appropriate
values. Then try again. Note that it may be called SQL rather than sql
for the customize group (though I think this is a later 24.0.50 version

Also, open a test file with the extension .sql as this may help ensure
things are loaded. Try and re-read the sql-help output as there are a
number of conceptual matters you don't appear to be clear on. 

Post back how you go and I will try to provide more detailed information
when I have more time.


tcross (at) rapttech dot com dot au

reply via email to

[Prev in Thread] Current Thread [Next in Thread]