mysqldatabaseshellscripting

Mysql backup script


I am using a script to take a backup of all my databases in the Mysql.

Script is :

#!/bin/bash
cd /root/Desktop/backup
echo “You are In Backup Directory”

Now=$(date +%d-%m-%Y--%H:%M:%S)

File=$Now.sql

mysqldump –u root --all-databases > $File

echo “Your Database Backup Successfully Completed”

But when i m trying to restore the database its giving me the following error and also there is no back at all just a file is created:

SQL query:

Usage: mysqldump [OPTIONS] database [tables]

OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]

OR     mysqldump [OPTIONS] --all-databases [OPTIONS]

For more options, use mysqldump --help

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Usage: mysqldump [OPTIONS] database [tables] OR mysqldump [OPTIONS] --databa' at line 1

Please help.


Solution

  • Finally i got it, i need to define password in my.cnf so it automatically used or i have to define it in the command i am executing in the script mysqldump -u root -p 'password' --all-databases > $File.

    Thanks for your efforts guys.