Hi everybody

I have been using mysqldump utility to dump the contents of database to a file.

Everything is ok
but i want to eliminate the "USE `db_name`;" statement that appears in mysqldump.

Is it possible to do that.
Please help:sweat:

Hello,

It might depend on the version but normally if you dump a specific database it does not include the USE statement.

mysqldump my_cool_db -u root -p > mysqldumpfile.sql

Or you could set up a script that will create individual dumps for databases who's names are listed in a file. For example if your file that contains the list of databases you want to create mysql dumps for is called:
/home/me/mydb.list
And you want the files to be created in /var/backups/databases. the script could look like:

#!/bin/bash
for x IN `cat /home/me/mydb.list `
do
mysqldump -u <USER> -p<PASSWORD> $x > /var/backups/database/$x
done

*******Notes..
1. The DO should be lower case do but it keeps showing as DO when I review my post.
2. You will need to use a real user name with access to the database in place of <USER> and <PASSWORD> and there is a space between -u and the user name but not between -p and the password.

Hope this makes sense and helps.

I am using MySql version 5.0.51b.
and i am successfully able to dump the file but with "use db_name" statement.

Anyway thanks for reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.