How to made a copy of a MySql database using the console.

Some times I happened that, I need get a copy of a data base running on MySql but the server can’t access using some graphical tools how MySql Workbench or HeidiSQL. If you also happened, don’t turn crazy, if you have access to the server using the linux console, exist an alternative. You can generate a copy of your data base using the program mysqldump that is common that this installed in the most servers that have installed the MySql service (for make maintenance of him).

For extract the data base info and save in a file, you must execute the next command:

View Code SHELL
1
mysqldump -u{user} -p{password} {data-base-name} > {location-and-name-of-the-sql-file-to-generate}

But be careful if you have procedures in your database because, by default, this command obvious it. For download too the procedures, add the option “routines”

View Code SHELL
1
mysqldump -u{user} -p{password} --routines {data-base-name} > {location-and-name-of-the-sql-file-to-generate}

Now, when this command finished, you will have a file with all sql necessary for generate a copy of your data base in other MySql server.

Next, only need download this file and execute it on new MySql server. I recommend use the MySql console for this task. If you not know how to do this, look this post that I explain how Import a data base MySql using the console.

Leave a Reply

Your email address will not be published. Required fields are marked *