MySql server configuration for maximum 60000 rows with excel file - mysql

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

Related

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.

Lost connection to MySQL server during query just on MacOS

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.

Select statement failing SQL Server

I have a select statement running in a jsp against SQL Server (previously using MySql without issues).
the TOP 1 was added because otherwise SQL Server moans about order by clauses (but only when displaying a result in a jsp, not when running the query inside SQL Server Management Studio).
This query runs fine in SQL Server Management Studio
SELECT TOP 1
alerts.id,
alerts.ts,
asset_firstname,
asset_lastname,
assetid,
alerttype.name,
node.zonename,
node.ipaddress,
node.zonegroupid
from
alerts, asset, alerttype, node, alertrules
where
ack=0 and
alerts.nodeid = node.id and
alerts.alerttypeid = alerttype.id and
alertrules.alerttypeid = alerts.alerttypeid and
alerts.assetid = asset.id and
alerts.alerttypeid = 1 and
asset.id=1157 and
alertrules.userid = 1
order by alerts.ts desc
but, when run in the jsp it returns "Column alerts.ts is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause".
I don't want alerts.ts aggregated or grouped by, hence the 'correct' select statement.
If I remove TOP 1 or alerts.ts desc the query returns the wrong row (earliest rather than latest record)
Converting what should be straightforward basic SQL commands so they run properly with SQL Server is proving a nightmare.
Any thoughts appreciated.
Regards
Ralph
(I wrote this as an answer because as a comment would be a mess)
You are using old style joins, and have redundant checks. Maybe this could make a difference (not sure, as it seems to be a problem related to JSP):
SELECT TOP(1)
alerts.id, alerts.ts,
asset_firstname,
asset_lastname,
assetid,
alerttype.name,
node.zonename,
node.ipaddress,
node.zonegroupid
from alerts
inner join asset on alerts.assetid = asset.id
inner join alerttype on alerts.alerttypeid = alerttype.id
inner join node on alerts.nodeid = node.id
inner join alertrules on alertrules.alerttypeid = alerts.alerttypeid
where ack=0 and
alerts.alerttypeid = 1 and
asset.id=1157 and
alertrules.userid = 1
order by alerts.ts desc;

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 query running fine on v4.1.22 but not working on v5.x

I have an application that executes the following MySQL query:
SELECT 402 AS user_id,
p.id AS perm_id,
p.name AS perm_name,
lc.business_division_id,
bd.name AS bd_name,
bd.current_cycle, bd.current_moon,
lc.name AS cycle_name,
lc.milestone_date,
lc.scorecard_date,
bdm.name AS meta_name,
bdm.value AS meta_value
FROM lc_vc_cg_353.business_division bd,
lc_vc_cg_353.business_division_meta bdm,
lc_vc_cg_353.lunar_cycle lc
LEFT OUTER JOIN lc_vc_cg_353.permissions ps
ON ps.user_id = 402 AND ps.business_division_id = bd.id inner
join lc_vc_central.permission p
ON ((ps.privilege_id IS NOT null AND p.id = ps.privilege_id)
OR
(ps.privilege_id IS NULL AND p.id = 1024))
WHERE
bd.active = 1
AND
bdm.business_division_id = bd.id
AND
lc.business_division_id = bd.id
AND
lc.id = bd.current_cycle
ORDER by bd.name asc;
The production server works fine and is running MySQL v4.1.22 (Redhat), however when I execute the same query on a Windows machine running MySQL v5.1.43-community it comes up with the following error:
ERROR 1054 (42S22): Unknown column 'bd.id' in 'on clause'
Any ideas on what the issue could be? Could it be that particular syntax has been deprecated in newer versions of MySQL?
Any help would be greatly appreciated.
You should check that the schemas match as well.
Does business_division have an id column on the Windows system?
I assume the database names (e.g. lc_vc_cg_353) also match.
I cannot see anything obvious in the syntax.
I fixed this by installing MySQL v4.1.22 on the Windows machine.