1

I am trying to operate a SQL query using excel VBA

select count(distinct column_name) from db_name.table_name

but, I end up with the following error:

Run-time error '-2147467259 (80004005)' [MySQL] [ODBC 8.00(w) Driver][mysqld-5. 7.21] Query execution was interrupted, maximum statement execution time exceeded

There are 4 million records in the table with 230 columns. I have tried increasing "max_execution_time" value but it does not help. The error comes up in 30 seconds after execution.

How can I get past this timeout issue?

  • MYSQL version 5.7.21 (WAMP 32 bit)
  • Excel - Office 365
8
  • Using a passthrough query? Commented Aug 17, 2018 at 12:35
  • I don't have MS Access installed, I guess that's what you meant to use right?! Commented Aug 17, 2018 at 12:38
  • See here stackoverflow.com/questions/35905858/… Commented Aug 17, 2018 at 12:40
  • Have come across it for the first time, let me post back what I get - in some time. Commented Aug 17, 2018 at 12:47
  • 1
    What did you set max_execution_time to? And did you restart the MySQL server after changing the global variable? Please show the actual VBA code block including connection and recordset call (not line snippet of SQL). You can set query time on the ODBC call. Commented Aug 17, 2018 at 15:31

1 Answer 1

1

I've been struggling for while with a similar problem. I see your post is an old post, but who knows, maybe it can still help you or anyone that comes for a solution to this problem. What I did was divide the SELECT process in batches. So I have a column called Unique (which is the primary key and auto-increasing). So in VBA i do a FOR/NEXT loop, kinda like this:

For i= 0 to 10,000,000
Select * from table where unique>= i and unique< i+1,000,000

Then I copy the query to another cell, compiling all the queries next.

Well, it's not the perfect solution, but it worked for me and hope it helps someone!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.