Is query correct if connection was lost during it? - mysql

After establishing a remote connection to a MySQL server (using the MySQL command-line front-end) I started executing a very long stored procedure (I estimate that it may take longer than 7 hours) but in the middle of it I received the error:
ERROR 2013 (HY000): Lost connection to MySQL server during query
So I guess that my query got timed-out. This procedure just stores some values in a
previously empty table.
After receiving this error and re-establishing the connection to the server I could
verify that the procedure somehow continued executing. And some time later I also verified
that the previously empty table now has some rows.
My question is, Can I trust that the procedure's execution was correct even though the
connection was lost?

First, 7 hours seems too long. If the incompolete result bothers you, you could add some save point when N queries done, and combine the N queries into a single transaction. Then, Every time your procedure stops exceptionally, you could load the point you last saved.
I also suggest you could try to select the source data into your local pc, and make some script to get the result, then upload it to target table. This will reduce overhead on db server.

Related

What could cause MySQL to intermittently fail to return a row?

I have a MySQL database that I am running very simple queries against as part of a webapp. I have received reports from users starting today that they got an error saying that their account doesn't exist, and when they log in again, it does (this happened to only a few people, and only once to each, so clearly it is rare). Based on my backend code, this error can only occur if the same query returns 0 row the first time, and 1 row the second. My query is basically SELECT * FROM users WHERE username="...". How is this possible? My suspicion is that the hard disk is having I/O failures, but I am unsure because I would not expect MySQL to fail silently in this case. That said, I don't know what else it could be.
This could be a bug with your mysql client (Though I'm unsure as to how the structure of your code is, it could just be bad query). However let's assume that your query has been working fine up until now with no prior issues, so we'll rule out bad code.
With that in mind, I'm assuming it's either a bug in your mysql client or your max connection count is reached (Had this issue with my previous host - Hostinger).
Let's say your issue is a bug in your mysql client, set your sessions to per session basis by running this
SET SESSION optimizer_switch="index_merge_intersection=off";
or in your my.cnf you can set it globally
[mysqld] optimizer_switch=index_merge_intersection=off
As for max connection you can either increase your max_connection value (depending if your host allows it), or you'll have to make a logic to close the mysql connection after a query execution.
$mysqli->close();

MySQL connection loss during query

I am working on converting unix time to readable time.
It is necessary to insert a 6gb .txt file into my database
(XAMPP V3.2.2 , MYSQL workbench 5.2.34).
I have written the SQL query to convert unix time but whenever i run the query, Mysql workbench will crash
(error:2013.lost connection to database during query.).why?
my SQL query:UPDATE database.database SET readable_time=from_unixtime(unix_time);
Increasing net_read_timeout solves this problem
From doc:
Sometimes the “during query” form happens when millions of rows are being sent as part of one or more queries. If you know that this is happening, you should try increasing net_read_timeout from its default of 30 seconds to 60 seconds or longer, sufficient for the data transfer to complete.
Click here for more info.
Please check this post - Error Code: 2013. Lost connection to MySQL server during query
As you are talking about an insert, understand that the 'Workbench' loses the connection, but the query continues to execute in the 'server'. That is, the workbench can no longer update you on the status changes for that query execution. But, the execution of the query keeps continuing behind screens.
You might want to run show processlist to see if the insert process is still running or not.
However, while fetching data from the database, you might have to update your timeout settings.

Error #1159 with MySQL FEDERATED table and one kind of query

I have one problem with FEDERATED table in MySQL. I have one server (MySQL version 5.0.51a), who serve to store client data and actually nothing more. The logic database are stored in another server (version 5.1.56), sometimes it should handle that data from first server. So the second server have one FEDERATED table, which connect to the first server.
Actually, it has worked without any problems, but recently I got strange errors with this solution. Some kind of queries on second server cannot be performed correctly.
For example SELECT * FROM table - doesn't work. It hangs exactly 3 minutes and then gives:
Error Code: 1159 Got timeout reading communication packets
Ok, I checked table on the first server and it's Ok. Then I tried some another queries to FEDERATED table and they work...
For example, query like SELECT * FROM table WHERE id=x returns the result. Probably it could have problem with size of result, so I tried query with dummy WHERE-clause like SELECT * FROM table WHERE id > 0 - and it also works...
Finally I found a "solution", which helped only for two days - on the first server I made a copy of table, and on second server I re-declared a new FEDERATED table with new connection string to this copy. And it works, but after two days the same problem with new copied table.
I've already talk with both server providers, they see no problems, everything seems to work and other hosting provider is the causer of problems.
I've checked all variables in MySQL and there is no timeout parameter with 3 minutes etc. So how can I deal so kind of problems? It seems to be something automatic on network or database side, but I don't know, how to detect the reason of problems.
Do You have any ideas?
You may try checking MTU size settings for network interfaces on both servers.
This warning is logged when idle threads are killed by wait_timeout.
Normally, the way to avoid threads getting killed by wait_timeout is to call mysql_close() in scripts when the connection is no longer needed. Unfortunately that doesn't work for queries made through federated tables because the query and the connection are not on the same server.
For example, when a query is executed on server A of a federated table (pointing to data on server B), it creates a connection on server B. Then when you run mysql_close() on server A it obviously can not close the connection that was created on server B.
Eventually the connection gets killed by mysql after the number of seconds specified in "wait_timeout" have passed (the default is 8 hours). This generates the warning in your mysqlerror.log "Got timeout reading communication packets"

Error code: 2013: Lost connection to Mysql server during the query.. How can improve this query

I am getting the error stated in my post title. I have two tables. The first one, large is over than 4000,000 records and the second, small one is arounf 7000 records. I want to search for the value in the samll table and if found, I want to extract the whole record from the large table. The command never executed and always lose the connection with the database. I tried to limit the out put to 50 records only, the same thing happens. Please help me. If I need something like indexing (I read this might solve such performance problems, please clarify to me how. I'm not a DBA).
select * from db.large, db.small
where large.value=small.value;
*EDIT: * I use MySQL workbench 5.2.41 CE.
At one point on a previous project, I could actually crash the MySQL server reproducibly with a pretty simple query. In the code that called the database, I saw the same error message. Can you verify that the MySQL server's process ID is the same before and after the query? Chances are that your OS restarts the MySQL server immediately after the crash, and the MySQL command line client automatically reconnects (though it emits a notice when it does).

How do I fix the error that occurs during data transfer between SQL Server and MySql?

I have an SSIS package that connects to a mysql server and attempts to pulls data from different tables and inserts the rows into a SQL Server 2005 database.
One issue i notice is that at any given time it runs, regardless of what step it is on, it almost always fails to bring in the total records from mysql into sql server.
there are no errors thrown.
One morning it will have all 11M records and on the next run anywhere between 3K and 17K records.
Anyone notice anything like this?
I import data from two separate MySQL databases -- one over the Internet and one in-house. I've never had this type of issue. Can you describe how you setup your connection to the MySQL database? I used the ODBC driver available on the MySQL website and connect using an ADO.NET data source in my data flow that references the ODBC connection.
One possible way you could at least prevent yourself from loading incomplete data is only load new records. If the source table has an ID and the records never change once they are inserted, then you could feed in the maximum ID by checking your database first.
Another possible way to prevent loading incomplete data is loading the MySQL database into a staging table on your destination server and then only load records you haven't already loaded.
Yet another way to do it is load the data into a staging table, verify the records are greater than some minimum threshold such as the row count of the target table or the expected minimum number of transactions per day and then only commit the changes after this validation. If the rows are insufficent, then raise an error on the package and send a notification email. The advantage of raising an error is you can set your SQL Server Agent job to retry the step for a defined number of attempts to see if this resolves the issue.
Hope these tips help even if they don't directly address the root cause of your problem.
I've only tried MySQL -> SQL Server via SSIS once, but the error I found related to MySQL datetimes not converting to SQL Server datetimes. I would have thought this would break the whole dataflow, but depending on your configuration you could have set it purely to ignore bad rows?