Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can tables in a mysql database be counted?

I'm using MySQL v.5.0.77 and I was wondering if it is possible to count the number of tables in a database. I have done a lot of research and am unable to find a way to do this that is not depreciated.

For each user that signs up I had generated a table in a database for them. And now I am trying to get a live count of those tables, if that makes sense. Is this a logical way of storing user information? I am unable to programmatically create entire databases on my server.

like image 934
John Doe Avatar asked Dec 03 '22 06:12

John Doe


1 Answers

You can do a query to information_schema.tables

SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA='$database_name';
like image 147
ajreal Avatar answered Dec 05 '22 21:12

ajreal