在命令行下mysql的數據導出有個很好用命令mysqldump,它的參數有一大把,可以這樣查看:
mysqldump
最常用的:
mysqldump -uroot -pmysql databasefoo table1 table2 > foo.sql
這樣就可以將數據庫databasefoo的表table1,table2以sql形式導入foo.sql中,其中-uroot參數表示訪問數據庫的用戶名是root,如果有密碼還需要加上-p參數
C:\Users\jack> mysqldump -uroot -pmysql sva_rec date_drv > e:\date_drv.sql
mysql的數據導入也是相當便捷的,如:
mysql -uroot databasefoo < foo.sql
這樣就可以將foo.sql的數據全部導入數據庫databasefoo
1.導出整個數據庫
mysqldump -u用戶名 -p密碼 數據庫名 > 導出的文件名
C:\Users\jack> mysqldump -uroot -pmysql sva_rec > e:\sva_rec.sql
2.導出一個表,包括表結構和數據
mysqldump -u用戶名 -p 密碼 數據庫名 表名> 導出的文件名
C:\Users\jack> mysqldump -uroot -pmysql sva_rec date_rec_drv> e:\date_rec_drv.sql
3.導出一個數據庫結構
C:\Users\jack> mysqldump -uroot -pmysql -d sva_rec > e:\sva_rec.sql
4.導出一個表,只有表結構
mysqldump -u用戶名 -p 密碼 -d數據庫名 表名> 導出的文件名
C:\Users\jack> mysqldump -uroot -pmysql -d sva_rec date_rec_drv> e:\date_rec_drv.sql
5.導入數據庫
常用source 命令
進入mysql數據庫控制台,
如mysql -u root -p
mysql>use 數據庫
然後使用source命令,後面參數為腳本文件(如這裡用到的.sql)
mysql>source d:wcnc_db.sql
==============
If it's an entire DB, then:
$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql
If it's all DBs, then:
$ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql
If it's specific tables within a DB, then:
$ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql
You can even go as far as auto-compressing the output using gzip (if your DB is very big):
$ mysqldump -u [uname] -p[pass] db_name | gzip > db_backup.sql.gz
If you want to do this remotely and you have the access to the server in question, then the following would work (presuming the MySQL server is on port 3306):
$ mysqldump -P 3306 -h [ip_address] -u [uname] -p[pass] db_name > db_backup.sql
Type the following command to import sql data file:
$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
In this example, import 'data.sql' file into 'blog' database using Sathish as username:
$ mysql -u sat -p -h localhost blog < data.sql
If you have a dedicated database server, replace localhost hostname with with actual server name or IP address as follows:
$ mysql -u username -p -h 202.54.1.10 databasename < data.sql
OR use hostname such as mysql.cyberciti.biz
$ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql
If you do not know the database name or database name is included in sql dump you can try out something as follows:
$ mysql -u username -p -h 202.54.1.10 < data.sql
Refer: http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html
If you want a GUI tool then you could probably use SQLyog