0

Suppose that I want to access mysql server and print all tables and databases and their data in localhost using bash script.

The script I have looks like:

mysql -u root -p password

After the script is executed, the mysql shell opens instead of bash. So how can I run a command with mysql?

Also, what command should I execute to print out all databases, tables and their data?

Edit: I now get which command I should use, but still the question remains:

I need to make it into the script, but when entering mysqldump command, it asks for password interactively.

So how can I handle password in a bash script?

3 Answers 3

1

See mysqldump which does what you want.

Usage example:

mysqldump -u root -p --all-databases

See the manual for more switches to suit your particular situation.

0

try this..

mysqldump -u root -p databasename > filename.sql

all tables store in filename.sql. its like as backup.

and if you want to store tables back in database then use this command.

mysqldump -u root -p databasename < filename.sql
0

If you execute man mysqldump, you will get the following output:

--password[=password], -p[password]

The password to use when connecting to the server. If you use the short option form (-p), you cannot have a space between the option and the password. If you omit the password value following the --password or -p option on the command line, mysqldump prompts for one.

Specifying a password on the command line should be considered insecure. See Section 6.1.2.1, "End-User Guidelines for Password Security". You can use an option file to avoid giving the password on the command line.

Assuming your root password is PASSWORD, just try the following command:

mysqldump -u root -pPASSWORD --all-databases > database.sql

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .