Find the answer to your Linux question:
Results 1 to 3 of 3
I have FC6 and use the following script to backup a mysql database from the command line: mysqldump -h localhost -u db_user -p database1 > database1.sql I have a few ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2006
    Posts
    82

    mysql backup/reload question


    I have FC6 and use the following script to backup a mysql database from the command line:

    mysqldump -h localhost -u db_user -p database1 > database1.sql

    I have a few questions:
    1. Using this I have to enter the db_user password. Is there a way to have the password in the script so it will run automatically?

    2. What would the script look like to be able to load the database from the command line to restore?

    3. Is there a way to have "Drop Database..." added to the backup script?

    Thanks.

  2. #2
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,790
    You can indeed put the password in here. Where you have the "-p" flag, put the password DIRECTLY after that like: "-ppassword" no space, and it will use that password for you.

    To restore the database, it's probably easier to have the mysqldump include the create database statement, and a statement that says if the database exists, to delete it. That way, if the database exists, it will remove it, create it, and then run the rest of the SQL. The way that you will do this is:

    Code:
    mysql -u db_user -pdb_pass < database1.sql
    To find out what options there are available, try "man mysqldump"
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

  3. #3
    Just Joined!
    Join Date
    Mar 2006
    Posts
    82
    thank you, this worked perfect for me!

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •