Importing and exporting MySQL databases using PHPMyAdmin


This article discusses importing and exporting your mySQL databases.

 

How can I import a MySQL database?

importing databases using phpmyadmin

  1. Log into your DirectAdmin Control Panel account.
  2. Navigate to the "phpmyadmin" section, in the advanced features section of your control panel.
  3. Log in with your Database username and your database password. Find more information about your installed databases in the MySQL Management section of your DirectAdmin control panel
  4. In phpMyAdmin you will see a list of your databases on the left side. Select the database you would like to import to.
  5. Once the database is selected, click the "Import" tab at the top.
  6. In this sub-section, a "browse" button will appear. Select this, and choose the desired .sql file on your PC.
  7. After you have selected the file, click "Go" at the bottom right; it will import your .sql file for you.

Note: The maximum size for a sql upload via phpMyAdmin is 50MB.

 

Overcoming file size limits when uploading SQL files to phpMyAdmin

If you find that you are unable to upload your backed-up SQL file to phpMyAdmin because the file is too large (even after zipping it) there are four options you could try:

1) Using a better compression algorithm
Zip is fairly good but there are better alternatives. GZip and BZip2 are good choices that should give you considerably lower file sizes (and phpMyAdmin understands them too). If you need a utility that can compress to gzip or bzip you could try 7zip.

2) Increasing the maximum file size phpMyAdmin will accept
If the limitation you are running into is a limit on the size of file uploads on your system, you may be able to increase this limit. By default it's usually 2M or 8M. To increase it you need to change PHP settings. You can change these settings either system-wide (if you have permission) or locally. The settings to change (with their typical defaults are):

post_max_size = 8M
upload_max_filesize = 2M

You must ensure that post_max_size is the same or larger than upload_max_filesize.

  • These settings can be changed globally by changing them in your php.ini file (its location varies depending on your system). After changing the settings, remember to restart your web server.
  • You may be able to change these settings locally if you're using Apache by putting a ".htaccess" file in phpMyAdmin's directory. The contents of the file should be:
    php_value post_max_size 20M
    php_value upload_max_filesize 20M
    Change '20M' to however large you want it to be. You shouldn't need to restart the web server for these changes to take effect, but if you start getting Internal Server Errors (500) then this probably means your host does not allow you to change these settings and you need to remove those settings.

3) Splitting up the file
This is quite tricky, but you could split the file into smaller pieces, compress each piece, and then load them in one after the other. You may need to be familiar with SQL to do this safely, and editing large files can be problematic depending on your system speed and text editor.

4) Importing the SQL file another way
If you have a Unix/Linux server and have SSH access to it then you can use the `mysql' command line program to import the file like so:

mysql -u myuser -p mydatabase < myfile.sql

This will prompt you for the password for `myuser' and then import the SQL from myfile.sql. Obviously you will need to have uploaded myfile.sql through FTP or similar. Ideally you would compress myfile.sql, upload it, uncompress it and then import using the command above.

 

How can I export a MySQL database?

exporting databases using phpmyadmin

  1. Log in with your Database username and your database password. Find more information about your installed databases in the MySQL Management section of your DirectAdmin control panel
  2. In phpMyAdmin you will see a list of your databases on the left side. Select the database you would like to export.
  3. Once the database is selected, click the "Export" tab at the top.
  4. Leave the settings as they are, click the "Save as file" checkbox and click Go.
  5. This will download a .sql file to your computer.
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Connecting to MySQL with PHP

Use the following outline to connect and begin querying the MySQL server from within your PHP...

MySQL Databases in DirectAdmin

This document provides information about MySQL databases. Topics include creating databases,...

How to optimize MySQL performance

  Structured Query Language (SQL) is a special purpose programming language used to store,...