Unix Technical Forum

getting a list of all databases in a comma delineated format?

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:29 AM
yawnmoth
 
Posts: n/a
Default getting a list of all databases in a comma delineated format?

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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:29 AM
J.O. Aho
 
Posts: n/a
Default Re: getting a list of all databases in a comma delineated 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:29 AM
Radoulov, Dimitre
 
Posts: n/a
Default Re: getting a list of all databases in a comma delineated format?

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:29 AM
yawnmoth
 
Posts: n/a
Default Re: getting a list of all databases in a comma delineated format?

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!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:46 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com