This is a discussion on getting a list of all databases in a comma delineated format? within the MySQL forums, part of the Database Server Software category; --> I'm trying to write a batch file that'll backup all my databases and had a question. I was thinking ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I'm trying to write a batch file that'll backup all my databases and had a question. I was thinking about executing SHOW Databases to get a list of all the databases and then use mysqldump on each one. To do this, I was thinking I'd use for loops as described at <http:// www.robvanderwoude.com/for.html>. The only problem is that these for loops require you use a comma / space / semicolon delineated list. Here's the command I'm using to get the list of databases: mysql -u username -ppassword --execute="SHOW Databases" Here's what it returns: +--------------------+ | Database | +--------------------+ | information_schema | | test | | whatever else | +--------------------+ That's not all that helpful. Is there any way to get the list to output in the required format? |
| |||
| yawnmoth wrote: > +--------------------+ > | Database | > +--------------------+ > | information_schema | > | test | > | whatever else | > +--------------------+ > > That's not all that helpful. Is there any way to get the list to > output in the required format? > You could use awk to transform the outdata to what you want it to be. There are quite many resources how to use awk. -- //Aho |
| |||
| yawnmoth wrote: > I'm trying to write a batch file that'll backup all my databases and > had a question. I was thinking about executing SHOW Databases to get > a list of all the databases and then use mysqldump on each one. [...] What's the problem with: mysqldump --all-databases ... If you want to select a few: mysqldump -d $(mysql -NBe "show databases like '%pattern%'") Dimitre |
| ||||
| On Nov 5, 1:55 pm, "Radoulov, Dimitre" <cichomit...@gmail.com> wrote: > yawnmoth wrote: > > I'm trying to write a batch file that'll backup all my databases and > > had a question. I was thinking about executing SHOW Databases to get > > a list of all the databases and then use mysqldump on each one. > > [...] > > What's the problem with: > > mysqldump --all-databases ... > > If you want to select a few: > > mysqldump -d $(mysql -NBe "show databases like '%pattern%'") > > Dimitre I didn't know about that, heh. Thanks! |