MySQL Database Operations

From SuperbHosting.net Support Wiki

Jump to: navigation, search

How to Import a MySQL Database From a Linux Command Line

Here, we import a database. Use this to restore data from a backup or to import from another MySQL server. Start by uploading the FILE.sql file to the server where you will be running this command, or you can upload it to any Linux shell account and just use the -h flag for hostname and put the FQDN after the -h

mysql -u username -ppassword database_name < FILE.sql

Replace the username and password with your own information.

This powerful, easy-to-use command has many functions.

An example of this usage from a remote host would be this:

mysql -u username -h hostnameof.server.at.superb.net -ppassword database_name < FILE.SQL


How to Export a MySQL Database Via the Linux Command Line

This how-to shows you how to export a MySQL datbase with mysqldump which is a tool to import and export MySQL databases. It can be used to back up a database or to move database information from one server to another.

This example shows you how to export a database. It is a good idea to export your data often as a backup.

First connect to the MySQL server that has the database and use this command line.

mysqldump -u username -ppassword database_name > FILE.sql

Replace username, password and database_name with your MySQL username, password and database name. File FILE.sql now holds a backup of your database, download it to your computer.

Or you can do this from your Linux shell.

mysqldump -u username -h hostname.of.server.com -ppassword database_name > FILE.sql

This will remotely connect to the server and download it if you're remote.

Personal tools