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 (as reported by uname -a): Linux 2.6.19.7 (also happens on another installation whose Linux is 2.6.18)
Emacs version (running on remote OS): 21.3.1 (also happens on another installation whose Emacs is 21.4.1)
MySQL version (running on remote OS): 4.1.22 (also happens on another installation whose MySQL is 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: [XXXXX: 2] tcsetattr: Invalid argument
(where XXXXX is the process id of the bash shell that's the parent of the mysql process that was killed.)
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. http://www.emacswiki.org/emacs/SqlMode 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 Emacs' menubar 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 DISPLAYED THE OUTPUT OF THE QUERY I'D ENTERED before reporting:
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:
How to run the mysql executable from a bash prompt inside emacs and not have it hang when it calls tcsetattr()?
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?
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
You got to add (setq sql-mysql-options '("-C" "-t" "-f" "-n")) to your _emacs to make sql-mysql work on Windows properly. M-x describe-variable sql-mysql-options to read the docs.
Related
While I try to source a .sql file of size 6GB, MySQL command line client crashes abruptly without even throwing any error.
I tried to set max_allowed_packet to a limit of 16M and tried SET ##local.net_read_timeout=360;.
The SQL file does not have any command that is likely to close the connection. Only table creation and value insertion commands are there. Since the crash is abrupt, can't figure out the root cause.
Can anyone help me in analyzing this further?
Assuming it's a Linux box, try running the command with strace
strace -ff -o mysql.strace <your mysql cmd>
Log at mysql.strace.[PID] can show how far the execution went.
I am very frequently getting this error in MySQL:
OS errno 24 - Too many open files
What's the cause and what are the solutions?
I was getting the errno: 24 - Too many open files too often when i was using many databases at the same time.
Solution
ensure that the connections to db server close propertly
edit /etc/systemd/system.conf. Uncomment and make
DefaultLimitNOFILE=infinity
DefaultLimitMEMLOCK=infinity
then run systemctl daemon-reload and service mysql restart.
You can check the results with the query: SHOW GLOBAL VARIABLES LIKE 'open_files_limit' and you may notice that the value has changed. You should not have any errno 24 now.
Please notice that the solution may differ from other OS/versions. You can try to locate the variables first.Tested with Ubuntu 16.04.3 and mysql 5.7.19.
In my case it was useless to setting up the open_files_limit variable in mysql configuration files as the variable is flagged as a readonly.
I hope it helped!
You probably have a connection leak in your application, that is why open connections are not closed once the function completes it's execution.
I would probably look into the application code and see where the connections/preparedstatement (if it's java) objects are not closed and fix it.
A quick workaround is to increase ulimit of the server (explained here) which would increase number of open file descriptors (i.e. connections). However, if you have a connection leak, you will encounter this error again, at later stages.
I faced the same problem and found a solution on another stackoverflow-question.
By running the following snippet with Bash:
ulimit -n 30000
Attempting to change directories, view directory contents, etc., but for some reason I don't have the system command to use the command line once I run mysql. These are the options I get:
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
notee (\t) Don't write into outfile.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog
with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
Any ideas what could cause this? It seems to be possible using windows (using \!).
As stated in the MySQL documentation, the MySQL system command works only in Unix and therefore not in Windows:
http://dev.mysql.com/doc/refman/5.6/en/mysql-commands.html
Notepad++ has been giving me issues whenever I leave it for several minutes, seems to be going into some type of standby mode.
Whenever I go to save a file (connected to an FTP server via NppFTP), I get the errors below after the upload hangs for around 20 seconds. If I try again immediately after I see the error message, the transfer then goes through.
--
Failure retrieving contents of directory /public_html/etc
-OR-
Upload of C:\Users\Nathan\AppData\Roaming\Notepad++\plugins\config\NppFTP\Cache\filenameanddirectoryhere failed
Is there a way to prevent this? (get Notepad to ping the server every X seconds to prevent the connection timing out or something like that?)
you got the server and give command setenforce 0 . this is a command to turn off se linux.
I have a problem with a hang using xp_cmdshell.
The executable is called, performs its work, and exits. It is not hanging because of a ui prompt in the exe. The exe is not hanging at all. The exe disappears from the process list in task manager, and internal logging from the exe confirms that it executed the very last line in the main function
the call to xp_cmdshell does NOT return control in SQL. It hangs on that line (it is the last line of the batch). Killing the process is ineffective. It actually requires a restart of sql server to get rid of the hung process (ugh)
The hang only happens the first time it is run. Subsequent calls to the procedure with identical parameters work and exit correctly so long as the first one is hung. Once SQL is restarted, the first subsequent call will hang again.
If it makes any difference, I am trying to receive the return value from the exe -- my sql procedure ends with:
exec #i = xp_cmdshell #cmd;
return #i;
Activity Monitor is reporting the process to be stuck on a wait type of PREEMPTIVE_OS_PROCESSOPS (what the other developer saw) or PREEMPTIVE_OS_PIPEOPS (what I'm seeing on my current testing)
Any ideas?
Just came across this situation myself where I've run an invalid comment via xp_cmdshell.
I managed to kill it without restarting SQL, what I've done was to identify the process that run the command and kill it from Task Manager.
Assume your SQL was running in Windows 2008 upward:
Under Task Manager, Processes tab. I enabled the column to show Command Line of each process (e.g.: View -> Select Columns..).
If you unsure what command you've run via xp_cmdshell, dbcc inputbuffer(SPID) should give you a clue.
We had the same issue, with SQL Server 2008, also with calls involving xp_cmdshell and BCP. Killing the sql process ID didn't help, it would just stay stuck in "KILLED/ROLLBACK" status.
Only way to kill it was to kill the bcp.exe process in Windows task manager.
In the end we traced the issue down to wrong SQL in sproc that was calling the xp_cmdshell. It was by mistake opening multiple transactions in a loop and not closing them. After BEGIN/COMMIT trans issues were fixed, PREEMPTIVE_OS_PROCESSOPS never came back again.
We actually did eventually figure out the problem here. The app being called was used to automatically dump some documents to a printer when certain conditions happened.
It turns out that a particular print driver popped up a weird little window in the notification tray on a print job. So it was hanging because of a ui window popping up -- but our app was exiting properly because it wasn't our window, it was a window triggered by the print driver.
That driver included an option to turn off that display window. Our problem went away when that option was set.