<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE artikkel PUBLIC "-//infoweb.ntnu.no//DTD Infoweb//1.0"
"http://infoweb.ntnu.no/infoweb.dtd">
<artikkel versjon="1.0" spraak="en">
   <tittel>Using mysqldump to export databases</tittel>
   <forfatter>andersl</forfatter>
   <sammendrag>
      Description of how to use the command mysqldump for exporting the contents of a database to a file.
   </sammendrag>

   <hoveddel>
      <os2>mysqldump</os2>
         <avsnitt>
	         If you want to retrieve information from a database for backup or move its contents to another 
            database, the program <kommando>mysqldump</kommando> proves to be quite convenient. It is installed 
            at all login-hosts and can be used to generate sql-data from databases and tables. 
         </avsnitt>

         <avsnitt>
            To retrieve all information from a database:
         </avsnitt>

         <konsoll>
            mysqldump -u andersl_user -p andersl_database <tegn symbol="gt" /> databasefile.sql
         </konsoll>

         <avsnitt>
	         With this command a file will be generated with the name <kommando>databasefile.sql</kommando> 
            which contains codes for creation of all tables and their contents in the database called 
            <kommando>andersl_database</kommando>.    
         </avsnitt>

         <avsnitt>
            The difference between logging in normally to your mysql-database and this command is that the information 
            gets sent to a file instead of to your ssh-consoll.
         </avsnitt>

         <avsnitt>
            You can of course add options so that you only get one table:
         </avsnitt>

         <konsoll>
            mysqldump -u andersl_user -p andersl_database name_of_table <tegn symbol="gt" /> tablefile.sql
         </konsoll>

      <os2>Exporting studorg-databases</os2>
         <avsnitt>
            You can export databases in a studorg in the same way as described earlier as long as you have permission to 
            access the database in some way. For information about permissions and access to databases, see 
            <infoweb aid="87">this page</infoweb>.
         </avsnitt>

      <os2>Importing sql-filer</os2>
         <avsnitt>
	         To import a file you have used mysqldump on to another database, use this code: 
         </avsnitt>

         <konsoll>
            mysql -u andersl_user -p andersl_database <tegn symbol="lt" /> databasefile.sql
         </konsoll>

      <os2>Other options</os2>
         <avsnitt>
	         The code for importing sql-files can be expanded with more options as to how the tables are imported. 
            As it is written it generates SQL-code for creating tables with data in given database. 
            For further help using mysqldump, use the command <kommando>man mysqldump</kommando>.
         </avsnitt>
  </hoveddel>
</artikkel>

