Bug #66913 intermittent corruption of large queries pasted into the command-line client
Submitted: 21 Sep 2012 17:12 Modified: 16 Apr 2015 15:07
Reporter: Alex Frase Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1.61 OS:Linux
Assigned to: CPU Architecture:Any
Tags: client, corrupt, paste, race condition

[21 Sep 2012 17:12] Alex Frase
Description:
I am using Geany (a basic text/code editor) to edit large MySQL queries (220 lines, ~9kb), but when I try to copy and paste them into the mysql command line client (running inside GNOME Terminal on Scientific Linux 6.1), the query text is intermittently corrupted. MySQL will then return a syntax error at some random point in the query where some text was omitted during the paste. If I paste again (without even copying again from Geany), the lost text and syntax error will be somewhere else in the query. I can repeat this process a dozen times or more until it finally pastes correctly and runs the query, but it is extremely frustrating.

The lost text appears to usually be from some random point until the end of that line; if there are 'string literals' or /*comments*/ in the query, this sometimes means the end of the string or comment is dropped and the client remains in the corresponding input mode afterwards (i.e. displaying a "/*>" prompt for continuation rather than the normal "->").

I also tested using nano to create ten different empty text files, and pasting exactly the same large query into each of them. The resulting files were all correct and identical, confirming that the problem is not in the GNOME Terminal application or in GNOME's clipboard handling; it is specific to the mysql command-line client.

How to repeat:
Write a very long query in any text editor; the nature of the query's behavior doesn't seem to matter much, it just has to be at least 200 lines and 8kb of text or thereabouts. Then copy that text with CTRL-C and try to paste it into the command-line client (i.e. with right-click Paste in the terminal window). MySQL will probably fail to parse the query, and if you look back at what was pasted, you'll see a chunk of your query text missing, even though it's clearly present in the original that you copied to the clipboard.

Suggested fix:
Because the bug is intermittent when pasting repeatedly from the same clipboard, and the location of the dropped text varies each time, I'd guess there's some kind of race condition in the command-line client's input buffer processing.
[22 Sep 2012 2:15] MySQL Verification Team
I can't repeat on CentOS 6.3 using Konsole and my own long query, please provide a file with your offended query. Thanks.
[23 Oct 2012 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[29 Sep 2014 18:35] Rolf Ruediger
This bug still exists for me.
mysql Ver 14.14 Distrib 5.5.38, for debian-linux-gnu (x86_64) using readline 6.3
Linux Mint 17 Kernel 3.13.0-24-generic MATE 1.8.1

Code to reproduce: First create this table:
CREATE TABLE test
(
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(50) DEFAULT '',
  value INT DEFAULT 0,
  PRIMARY KEY (id),
  INDEX index_id (id)
);

Now copy this query a 100 times or more in a text editor:
INSERT INTO test SET
  name='bla',
  value=5;

Select all and copy&paste it into MySQL command line. MySQL will corrupt the text at random places and generate errors.
[9 Oct 2014 15:13] MySQL Verification Team
mysql> INSERT INTO test SET
    ->   name='bla',
    ->   value=5;
Query OK, 1 row affected (0.04 sec)

mysql> INSERT INTO test SET
    ->   name='bla',
    ->   value=5;
Query OK, 1 row affected (0.05 sec)

mysql> select count(*) from test;
+----------+
| count(*) |
+----------+
|      101 |
+----------+
1 row in set (0.00 sec)

mysql>
[15 Apr 2015 17:32] Miguel PĂ©rez
This still happens to me on Debian GNU/Linux 7 with the Debian packaged mysql client version 5.5.41 on xfce4-terminal, when pasting from anything.
[16 Apr 2015 15:07] Alex Frase
Miguel Solorzano, from your comment I can't tell exactly how you went about trying to reproduce this.

Please note that the problem does *not* arise if you paste a short query into the client, even if you do so many times in a row, because then you are only executing small "paste" operations.

The problem arises when you execute a single very large "paste" operation. So in order to reproduce this, open a GUI text editor and write whatever short query statement you want, and then copy and paste it several hundred times within that external GUI text editor. Make sure you end up with at least 10000 characters and several hundred lines.

Then, select *everything* from that GUI text editor and paste it all at once into the mysql client.
[5 May 2017 9:28] MySQL Verification Team
I've now filed
https://bugs.mysql.com/bug.php?id=86193