Reputation: 4245
Is there a way that I can output a list of all databases into a file. I know that you can use the SHOW DATABASES;
command to return the databases but that is not in the correct format:
+-------------------------+
| Database |
+-------------------------+
| information_schema |
| abcd |
| mysql |
| performance_schema |
| stathisK_travelbox |
+-------------------------+
I want a file like:
information_schema
abcd
mysql
performance_schema
stathisK_travelbox
Upvotes: 2
Views: 307
Reputation: 4245
This is what I have done:
SQL="SELECT schema_name FROM information_schema.schemata"
mysql -u root -p -ANe"${SQL}" > /listofdatabases.txt
Upvotes: 2
Reputation: 3072
sudo mysql -u username -p -e "show databases" > /tmp/output.txt
your output file must have write permission
Upvotes: 1