日期:2014-05-16  浏览次数:20588 次

Linux下导入导出Mysql数据库

windows我还没玩儿明白呢,就让人家做Linux。。。
不发牢骚了,步骤如下:
1:先查看自己的数据库,看数据库中的表
[root@localhost /]# mysql -uroot ;? (因为我密码为空,所以后面没有-p)
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.5.12-log MySQL Community Server (GPL)
Copyright (c) 2000, 2010, 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 |
| bxdq?????????????? |
| bxdq1????????????? |
| mysql????????????? |
| performance_schema |
| tour?????????????? |
+--------------------+
6 rows in set (0.00 sec)

导出表是用的mysqldump命令,直接在命令行上输入命令(我好笨啊,当时一直在Mysql下use bxdq下输入命令呢,半天木有反应)
2:ctrl+z回到root根目录
[root@localhost /]# mysqldump -uroot bxdq>bxdq.sql ;
这是把bxdq.sql导出到跟目下了,然后直接在根目录下就能找到
[root@localhost /]# ls
bin?? bxdq.sq l? etc?? lib??? lost+found? misc? net? proc? sbin???? srv? tftpboot? usr
boot? dev?????? home? lib64? media?????? mnt?? opt? root? selinux? sys? tmp?????? var

3:导入
导入要在mysql数据库控制台下进行
mysql> drop database bxdq;? (删除bxdq这个数据库,只是测试用,所以先删除这个数据库)
mysql>create database bxdq: (建立一个空数据库,用来做导入用)
mysql>use bxdq ; (进入bxdq数据库)
mysql>source bxdq.sql ?? (使用source命令将bxdq.sql导入到bxdq)
完成,然后可以
mysql>cd . .? (从bxdq这个数据库中返回上一级目录)
mysql>show databases ;? (显示所有的数据库)