Feb 25, 2022
0
Level 9
Running raw db query with mysql's own prepare and execute statements
Hi all,
can anyone point me to right direction. I have some raw mysql query that counts table rows from all databases (I have also other queries in similar syntax that fetches colum values). I have problem with the last portion of query (prepare and execute), if I use raw and statement it return error.
Here is raw query in question:
Select
concat(
'select * from (',
group_concat(
concat('select ',
quote(db), ' db, ',
quote(tablename), ' tablename, '
'count(1) "rowcount" ',
'from ', db, '.', tablename)
separator ' union ')
, ') t order by 3 desc')
into @sql
from (
select
table_schema db,
table_name tablename
from information_schema.tables
where table_schema not in
('performance_schema', 'mysql', 'information_schema')
) t;
prepare s from @sql; execute s; deallocate prepare s;
Please or to participate in this conversation.