Lost connection to MySQL server during query just on MacOS - mysql

I have an SQL query with 2 subqueries. whenever I run it on MySQL Workbench on macOS, it gives "Error Code: 2013. Lost connection to MySQL server during query". However, when it runs on Workbench on Windows, it runs normally without any errors.
I tried to increase the connection timeout, but still no success!
Any clue on how to solve this issue?
I appreciate your support and cooperation.
here is a query that gives an error:
with t1 as(
SELECT s.name rep_name, r.name region_name, sum(o.total_amt_usd) as total_amt
FROM sales_reps s
JOIN accounts a
ON a.sales_rep_id = s.id
JOIN orders o
ON o.account_id = a.id
JOIN region r
ON r.id = s.region_id
group by 1,2),
t2 as(
select region_name, max(total_amt) as total_amt
from t1
group by 1)
select t1.rep_name, t1.region_name, t1.total_amt
from t1
join t2
ON t1.region_name = t2.region_name AND t1.total_amt = t2.total_amt;

Your query is taking too long to return data so the connection gets dropped. There are 2 ways to fix this issue.
(i) Optimize query
(ii) Increase MySQL timeout
Explaining 2nd way:
1. In the application menu, select Edit > Preferences > SQL Editor.
2. Look for the MySQL Session section and increase the DBMS connection read time out value.
3. Save the settings, quite MySQL Workbench and reopen the connection.

Finally, I uninstalled the workbench and installed it again and now it is working properly. Thanks for who tried to answer my questions.

Related

MySql Query acts differently on my local version (8.0.21) and my staging (5.7.12)

I have an issue running a query on MySql using a Goapplication.
My local version works fine using mysql 8.0.21 but the same query on my staging version 5.7.12 on aurora fails
SELECT COUNT(*) AS cnt
FROM (
SELECT ? AS item_id, ? AS ar
)
AS A
JOIN item ON A.item_id = item.id
AND A.ar + item.existing_qty > item.qty;
Running this code in data grip with replacements works fine on both local and staging
Running this code but replacing the question marks with ints works fine
The error I get is:
Error 1054: Unknown column 'A.ar' in 'field list
I am thinking there is some driver / version issue
Does it work if you phrase the query like this?
select count(*)
from item
where item = ? and existing_qty + ? < qty
This is the same logic as your original query, and the parameters are passed in the same order.

Same SQL query give different results on the same MySQL server and DB

I am running the following mysql query:
SELECT
MAX(CONCAT('FY', weeks.fy, ' Q', weeks.q, 'W', weeks.wInQuarter)) AS `Fiscal Week`,
SUM(cb_arr.total) AS `Cloud Backup Service Total`
FROM
billing.customers c
JOIN
billing.date_fiscal_weeks weeks
LEFT JOIN
cloud_backup_service.arr_customers cb_arr
ON cb_arr.src_id = c.alias AND weeks.weekDate = cb_arr.weekDate
WHERE
weeks.weekDate>'2020-04-19'
GROUP BY
weeks.weekDate
However each time I run it I get different output:
Any idea what is the issue here?
Thanks,
SHmulik.

Improve SQL Query for this error: Incorrect key file for table '/tmp/#sql_XXXX_0.MYI'; try to repair it

I have this sql query in my code (php)
SELECT * FROM (
SELECT
A.ID,
A.ID as QuoteID,
A.Price as QuotePrice,
A.Price_Per,
A.Currency,
P.Packaging,
A.PackagingID,
A.Quantity,
A.MOQ,
A.QuoteDate,
A.IncoTerm,
A.RefNO,
B.E_name,
B.C_name,
B.Type,
B.Form,
B.Dosage,
B.ProductID,
C.E_Name as SupplierName,
C.SupplierID,
A.Remark
FROM quote A
left join prodpackaging P on A.PackagingID = P.PackagingID
join product B on A.ProductID = B.ProductID
join supplier C on A.SupplierID = C.SupplierID
left join rfq r on r.RefNO = A.RefNO and r.RefNO like 'PL%'
WHERE IFNULL(r.status,'Valid') = 'Valid'
) oph;
This is not getting results in my local application. I checked it on phpMyAdmin and run it there, so this error is displayed
Error Code: 126. Incorrect key file for table '/tmp/#sql_4a9_0.MYI'; try to repair it
I saw this is a very common problem with the size of the query result and the /tmp folder size. I have tried these things:
1.- Changing system variables (join_buffer_size, sort_buffer_size, tmp_table_size, max_heap_table_size).
2.- Releasing space in disk.
Unfortunately, i couldn't solved this problem yet. Probably i need to improve the sql query or add more space to the /tmp folder, maybe any of these ways work. I'll really appreciate your help.
Thanks for your time.
Note, i attached the df -h command and the ncdu of "/":

MySql server configuration for maximum 60000 rows with excel file

I wrote a query which is fetching 60000 rows and creating excel file which should be available for download as excel file, but every time I am getting some errors like '500 internal server error' or 'mysql server has gone away'. But it works fine for lesser rows(10-15k) Here is mysql query:
SELECT C.*, T.Name AS TankName, T.*, P.*
FROM properties P
LEFT JOIN contacts C ON C.ID = P.ContactID AND C.CompanyID = $companyID
LEFT JOIN tanks T on T.PropertyID = P.ID $subQuery
WHERE P.CompanyID = $companyID
$condition
ORDER BY C.FullName = '', C.LastName, P.City, P.Address, P.ID
Do I need to optimize the query or change some sql configuration.
Try increasing your my.cnf variables...
If this is innodb table or myisam table, according to this increase variables value in my.cnf.
Either memory is used up and server terminates the query or restarts mysql...
what error log give in this query ?
Thanks

SQL query slow when executed with LINQ (using full text search)

I have a query that's generated by LINQ and generates a time out error.
But when I run the generated query in SQL server management studio it executes in less than one second.
Here's the query:
exec sp_executesql N'SELECT COUNT(*) AS [value]
FROM [dbo].[Document] AS [t0]
INNER JOIN [dbo].[Document_Search_order_nummer](#p0) AS [t1] ON [t0].[DocumentID] = [t1].[Key]
LEFT OUTER JOIN [dbo].[DocType] AS [t2] ON [t2].[Id] = [t0].[DocumentTypeIDOut]
LEFT OUTER JOIN [dbo].[DocTypeFormat] AS [t3] ON [t3].[Id] = [t2].[FormatId]
LEFT OUTER JOIN [dbo].[DocTypeType] AS [t4] ON [t4].[Id] = [t2].[TypeId]
INNER JOIN [dbo].[OriginalDocument] AS [t5] ON [t5].[OriginalDocID] = [t0].[OriginalDocID]
INNER JOIN [dbo].[User] AS [t6] ON [t6].[User_ID] = [t0].[DocumentFrom]
INNER JOIN [dbo].[User] AS [t7] ON [t7].[User_ID] = [t0].[DocumentTo]
WHERE ([t0].[DocumentID] <> #p1)',N'#p0 nvarchar(4000),#p1 int',#p0=N'"*+11110001+*" ',#p1=270675
Below is the log from SQL server profiler:
Using LINQ:
Eventclass= RPC:Completed
ApplicationName= .Net SqlClient Data Provider
CPU= 12625
Reads= 1137844
Writes = 0
Duration = 29989
Using SQL Server Management Studio:
Eventclass= SQL:BatchCompleted
ApplicationName= Microsoft SQL Server Management Studio - Query
CPU= 78
Reads= 31645
Writes = 0
Duration = 99
What's the cause of this big performance difference with an equal query and how can I solve this issue?
We had exactly the same problem once.
One possible cause could be the parameters type mismatching that causes this.
But, this wasn't the issue in our case. Turned out that in some cases the query just takes longer time to execute. So we isolated the query and ran it trough ADO.NET SqlCommand class. Believe it or not when we added extra white spaces between the sql commands caused the query to execute much faster.
So we took the query and created a view from it. It solved our problem.