Import method MySQL database

Problem 
how to import the MySQL database

Solution 
1. Overview of
import MySQL database, there are two methods:
1) export the database SQL script, then import;
2) a direct copy of the database directories and files.

Under different operating systems or versions of MySQL, the case method copy files directly may be incompatible occur.
It is generally recommended for introduction in the form of SQL scripts. The following describes two methods.

2. The method of a SQL script form
steps are as follows:
2.1 Export SQL script
in the original database server, phpMyAdmin tool can be used, or the command line mysqldump derived SQL script.
2.1.1 phpMyAdmin tool with
export options, select Export "structure" and "data" do not add "DROP DATABASE" and "DROP TABLE" option.
Select "Save as File" option, if more data, you can select "gzipped" option.
Save the exported SQL files down.

2.1.2 mysqldump command line with
command format
mysqldump -u username -p database name> database name .sql
example:
mysqldump -p-uroot-abc> abc.sql
(abc to abc.sql export the database file)

When prompted for a password, enter the password for the database user name.

2.2. Create an empty database
through the master interface / control panel, create a database. Assume that the database abc, and the full database users abc_f.

2.3 The SQL script into the implementation of
the same are two methods, one using phpMyAdmin (mysql database management) tools, or mysql command line.
PhpMyAdmin 2.3.1 using tools
from the Control Panel, select an empty database created, click "management" tools into the management page.
In the "SQL" menu, browse to select just exported SQL file, click "Run" to upload and execute.

Note: phpMyAdmin have the uploaded file size limit, php itself has a limit on the upload file size, if the original sql file
is relatively large, can be first compressed with gzip it, for such a text file sql file obtained 1: 5 or higher compression rates.
gzip use:
# gzip xxxxx.sql
get
xxxxx.sql.gz file.

When prompted for a password, enter the password for the database user name.

3 direct copy
if the database is large, you can consider using the method of direct copy, but may not be compatible between different versions of the operating system, to be used with caution.
3.1 Preparation of the original file
with packaged as a tar file

3.2 create an empty database

3.3 decompression
codecs in the temporary directory, such as:
CD / tmp
the tar zxf mydb.tar.gz

3.4 copy of
the database file after decompression copied to the relevant directory
cd mydb /
cp * / var / lib / MySQL / mydb /

For the FreeBSD:
CP * / var / DB / MySQL / mydb /

3.5 permissions
to copy files over the main metal to mysql: mysql, Permissions to 660.
chown MySQL: MySQL / var / lib / MySQL / mydb / *
the chmod 660. / var / lib / MySQL / mydb / *

Guess you like

Origin www.cnblogs.com/itps/p/12381445.html