<p>MySQL databases can be backed up from the <a href="https://www.thoughtco.com/learn-sql-mysql-2693872" data-component="link" data-source="inlineLink" data-type="internalLink" data-ordinal="1">Command Prompt</a> or from phpMyAdmin. It is a good idea to back up your MySQL data occasionally as a precautionary measure. It is also a good idea to create a back up before making any major changes, in case something goes wrong and you need to revert to the unmodified version. Database backups can also be used to transfer your database from one server to another if you change web hosts.</p><p>From a command prompt, you can back up an entire database using this line:</p><pre> <code>mysqldump -u user_name -p your_password database_name &gt; File_name.sql</code></pre><p><strong>Example:</strong><br/>Assume that:<br/>Username &#61; bobbyjoe<br/>Password &#61; happy234<br/>Database Name &#61; BobsData</p><pre> <code>mysqldump -u bobbyjoe -p happy234 BobsData &gt; BobBackup.sql</code></pre><p>This backs up the database to a file called BobBackup.sql</p><p>If you are moving your data to a new server or you have removed the old database completely, you can restore it using the code below. This only works when the database does not already exist:</p><pre> <code>mysql - u user_name -p your_password database_name &lt; file_name.sql</code></pre><p>or using the previous example:</p><pre> <code>mysql - u bobbyjoe -p happy234 BobsData &lt; BobBackup.sql</code></pre><p>If your database already exists and you are just restoring it, try this line instead:</p><pre> <code>mysqlimport -u user_name -p your_password database_name file_name.sql</code></pre><p>or using the previous example again:</p><pre> <code>mysqlimport -u bobbyjoe -p happy234 BobsData BobBackup.sql</code></pre><ol><li>Log in to <strong>phpMyAdmin.</strong></li><li>Click on your database name.</li><li>Click on the tab labeled <strong>EXPORT.</strong></li><li>Select all the tables you want to back up (usually all of them). Default settings usually work, just make sure <strong>SQL</strong> is checked.</li><li>Check the <strong>SAVE FILE AS</strong> box.</li><li>Click <strong>GO.</strong></li></ol><ol><li>Login to <strong>phpMyAdmin</strong>.</li><li>Click on the tab labeled <strong>SQL</strong>.</li><li>Unclick the <strong>Show query here again</strong> box</li><li>Choose your backup file</li><li>Click <strong>GO</strong></li></ol>