mysql数据库的导入导出

系统 1808 0
      
        
          MySQL命令行导出数据库
        
1. 导出数据库 :mysqldump -u 用户名 -p 数据库名 > 导出的文件名     mysqldump -u root -p Movie >Movie .sql (输入后会让你输入进入MySQL的密码) (如果导出单张表的话在数据库名后面输入表名即可) mysqldump -u root -p Movie movies>tab_movies.sql 2. 会看到文件Movie.sql自动生成到var/lib/mysql数据库存储目录下,如下所示:
        root@landen-Lenovo:/var/lib/
        
          mysql# ls

debian
        
        -5.5
        
          .flag  ib_logfile1   
          
            
              Movie.sql
            
          
                    news                test

ibdata1          metastore_db  mysql               performance_schema

ib_logfile0      Movie         mysql_upgrade_info  student
        
      
    

注意:Movie.sql中存放的是之前操作的脚本语言,即增删改查,创建存储过程,触发器的相关脚本。   

      
        
MySQL命令行导入数据库
1. 将要导入的.sql文件移至 var/lib/mysql数据库存储目录下 2. 进入MySQL命令行客户端:mysql -u 用户名 - p    mysql -u root - p (输入同样后会让你输入MySQL的密码) 4. 在MySQL- Front中新建你要建的数据库,这时是空数据库,如新建一个名为news的目标数据库
mysql>create database if not exists news;
5. 输入:mysql> use 目标数据库名 mysql >use news; 6. 导入文件 :mysql> source 导入的文件名; mysql > source news.sql;
相关操作数据如下
        root@landen-Lenovo:/var/lib/mysql# mysql -uroot -
        
          p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 
        
        53
        
          

Server version: 
        
        5.5.29-0ubuntu0.12.04.2
        
           (Ubuntu)



Copyright (c) 
        
        2000, 2012, Oracle and/
        
          or its affiliates. All rights reserved.



Oracle is a registered trademark of Oracle Corporation and
        
        /
        
          or its

affiliates. Other names may be trademarks of their respective

owners.



Type 
        
        'help;' or '\h' 
        
          for
        
         help. Type '\c'
        
           to clear the current input statement.



mysql
        
        >
        
           show databases;


        
        +--------------------+

| Database           |

+--------------------+

| information_schema |

| Movie              |

| metastore_db       |

| mysql              |

| performance_schema |

| student            |

| test               |

+--------------------+

7 rows in set (0.01
        
           sec)



mysql
        
        > create database 
        
          if
        
        
           not exists news;

Query OK, 
        
        1 row affected (0.02
        
           sec)



mysql
        
        >
        
           show databases;


        
        +--------------------+

| Database           |

+--------------------+

| information_schema |

| Movie              |

| metastore_db       |

| mysql              |

| news               |

| performance_schema |

| student            |

| test               |

+--------------------+

8 rows in set (0.01
        
           sec)



mysql
        
        >
        
           use news;

Database changed

mysql
        
        >
        
           source Movie.sql

Query OK, 
        
        0 rows affected (0.02
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.01
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.10
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.33
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.04
        
           sec)



Query OK, 
        
        44625 rows affected (0.65
        
           sec)

Records: 
        
        44625  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        44027 rows affected (0.51
        
           sec)

Records: 
        
        44027  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        44050 rows affected (1.57
        
           sec)

Records: 
        
        44050  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        43180 rows affected (0.60
        
           sec)

Records: 
        
        43180  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42200 rows affected (1.03
        
           sec)

Records: 
        
        42200  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42238 rows affected (1.35
        
           sec)

Records: 
        
        42238  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42235 rows affected (0.95
        
           sec)

Records: 
        
        42235  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42237 rows affected (0.98
        
           sec)

Records: 
        
        42237  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42291 rows affected (0.77
        
           sec)

Records: 
        
        42291  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42266 rows affected (1.19
        
           sec)

Records: 
        
        42266  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42270 rows affected (0.90
        
           sec)

Records: 
        
        42270  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42238 rows affected (0.88
        
           sec)

Records: 
        
        42238  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42285 rows affected (1.14
        
           sec)

Records: 
        
        42285  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42285 rows affected (0.64
        
           sec)

Records: 
        
        42285  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42295 rows affected (0.96
        
           sec)

Records: 
        
        42295  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42297 rows affected (0.69
        
           sec)

Records: 
        
        42297  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42253 rows affected (1.11
        
           sec)

Records: 
        
        42253  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42291 rows affected (0.95
        
           sec)

Records: 
        
        42291  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42286 rows affected (0.55
        
           sec)

Records: 
        
        42286  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42260 rows affected (1.12
        
           sec)

Records: 
        
        42260  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42276 rows affected (0.89
        
           sec)

Records: 
        
        42276  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42295 rows affected (0.98
        
           sec)

Records: 
        
        42295  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        42296 rows affected (1.10
        
           sec)

Records: 
        
        42296  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        21233 rows affected (0.23
        
           sec)

Records: 
        
        21233  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.06
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.30
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.02
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        3883 rows affected (0.33
        
           sec)

Records: 
        
        3883  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.02
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.17
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        6040 rows affected (0.14
        
           sec)

Records: 
        
        6040  Duplicates: 0  Warnings: 0
        
          



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



Query OK, 
        
        0 rows affected (0.00
        
           sec)



mysql
        
        >
        
           show tables;


        
        +-------------------+

| Tables_in_news    |

+-------------------+

| movie_preferences |

| movies            |

| users             |

+-------------------+

3 rows in set (0.00
        
           sec)



mysql
        
        > select * from users limit 20
        
          ;


        
        +--------+--------+-----+------------+---------+

| UserID | Gender | Age | Occupation | Zipcode |

+--------+--------+-----+------------+---------+

|      1 | F      |   1 |         10 | 48067   |

|      2 | M      |  56 |         16 | 70072   |

|      3 | M      |  25 |         15 | 55117   |

|      4 | M      |  45 |          7 | 02460   |

|      5 | M      |  25 |         20 | 55455   |

|      6 | F      |  50 |          9 | 55117   |

|      7 | M      |  35 |          1 | 06810   |

|      8 | M      |  25 |         12 | 11413   |

|      9 | M      |  25 |         17 | 61614   |

|     10 | F      |  35 |          1 | 95370   |

|     11 | F      |  25 |          1 | 04093   |

|     12 | M      |  25 |         12 | 32793   |

|     13 | M      |  45 |          1 | 93304   |

|     14 | M      |  35 |          0 | 60126   |

|     15 | M      |  25 |          7 | 22903   |

|     16 | F      |  35 |          0 | 20670   |

|     17 | M      |  50 |          1 | 95350   |

|     18 | F      |  18 |          3 | 95825   |

|     19 | M      |   1 |         10 | 48073   |

|     20 | M      |  25 |         14 | 55113   |

+--------+--------+-----+------------+---------+

20 rows in set (0.06 sec)
      
  

 

mysql数据库的导入导出


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论