How to show all the tables from multiple databases

How to select all the tables from multiple databases in mySql.. I am doing the following steps but not able to achive the goal.

<?php
$a = "SHOW DATABASES";
$da = $wpdb->get_results($a);

foreach($da as $k){
echo '<pre>';
print_r ($k->Database);//prints all the available databases
echo '</pre>';
$nq = "USE $k->Database";//trying to select the individual database
$newda = $wpdb->get_results($nq);
$alld = "SELECT * FROM $k->Database";
$td = $wpdb->get_results($alld);
var_dump($td);//returns empty array
}
?>

Please Help me

Answers


You cannot do

SELECT * FROM database

but you can do

USE DATEBASE;
SHOW TABLES;

or even better:

SHOW TABLES IN database

Use the INFORMATION_SCHEMA:

select table_schema, table_name from information_schema.tables;

Even better:

Show all tables in all databases (except internal mysql databases) in one SQL statement.

SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ( 'information_schema', 'performance_schema', 'mysql' )

mysql -e'select table_schema, table_name from information_schema.tables;'

This depends on you having a file ~/.my.cnf in place with the following contents:

[client]
user=ADMINUSER     ## set user, usually 'root' 
password=PASSWORD  ## set password

I would go for this this:

mysql -e "select table_schema, table_name from information_schema.tables;" | \
    grep -Pv '^(sys|performance_schema|TABLE_SCHEMA|mysql|information_schema)' | \
    perl -pe 's/\s+/./' | \
    sort -u

Need Your Help

Random "Element is no longer attached to the DOM" StaleElementReferenceException

java selenium-webdriver webdriver automated-tests

I'm hoping it's just me, but Selenium Webdriver seems like a complete nightmare. The Chrome webdriver is currently unusable, and the other drivers are quite unreliable, or so it seems. I am battl...

Convert Web API to use Self Hosting

c# asp.net iis asp.net-web-api owin

I am trying to convert an existing ASP.NET Web API project (currently hosted in IIS) into one that can use the SelfHost framework. I'm a bit fuzzy on the actual details but understand I can run a s...