MySql使用mysqldump 导入与导出方法总结
作者:扑哧 时间:2024-01-23 13:26:32
导出数据库数据:
首先打开cmd进入MySQL的bin文件夹下
1.导出education数据库里面的users表的表数据和表结构(下面以users表为例)
mysqldump -u[用户名] -h[ip] -p[密码] -P[端口号] 数据库名 表名 >导出的文件名.sql
mysqldump -uroot -h127.0.0.1 -proot -P3306 education users>d:/user.sql
导出多张表:
mysqldump -uroot -proot --databases test --tables t1 t2>two.sql
2. 只导出表结构不导表数据,添加“-d”命令参数
mysqldump -uroot -h127.0.0.1 -proot -P3306 -d education users>d:/user.sql
3.只导出表数据不导表结构,添加“-t”命令参数
mysqldump -uroot -h127.0.0.1 -proot -P3306 -t education users>d:/user.sql
4.导出数据库的表结构和表数据(导入的时候需要指定数据库,保证指定的数据库存在)
导出命令:mysqldump -h127.0.0.1 -P3306 -uroot -proot education >d:/database.sql
导入命令:mysql -uroot -proot -h127.0.0.1 -P3306 education<d:/database.sql
5.导出特定数据库的所有表格的表结构及其数据,添加“--databases ”命令参数(导入的时候直接执行导出sql就行)
导出命令:mysqldump -h127.0.0.1 -P3306 -uroot -proot education --databases education> database.sql
导入命令:mysql -uroot -proot -h127.0.0.1 -P3306 <d:/all_database.sql
6.导出所有数据库
该命令会导出包括系统数据库在内的所有数据库(all.sql默认保存在bin文件夹下面)
mysqldump -uroot -proot --all-databases>all.sql
7.导出db1、db2两个数据库的所有数据
mysqldump -uroot -proot --databases db1 db2>dbs.sql
8.只导出test数据库的表结构
导出命令:mysqldump -uroot -proot --no-data --databases test>s1.sql
导入命令:mysql -uroot -proot -h127.0.0.1 -P3306 test<s1.sql
恢复导入数据库数据:
系统命令行
格式:mysql -h[ip] -P[(大写)端口] -u[用户名] -p[密码] [数据库名] < d:XX.sql(路径)
导入命令:mysql -uroot -proot -h127.0.0.1 -P3306 education<d:/database.sql
导入命令:mysql -uroot -proot -h127.0.0.1 -P3306 <d:/all_database.sql
这个两种情况上面已经说明什么情况下使用
mysql命令行
首先链接mysql,命令行格式如下:
格式: mysql -h主机地址 -u用户名 -p用户密码
下图是链接本机的mysql:mysql -uroot -proot
链接远程:mysql -h10.0.0.10 -uroot -proot
mysql> use test;
mysql> source /home/test/database.sql
参考链接:
https://www.jb51.net/article/73230.htm
https://blog.csdn.net/helloxiaozhe/article/details/77680255
来源:https://blog.csdn.net/u012436346/article/details/86570902
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Server正则表达式 替换函数应用详解
设计手机端应用时的一些建议
详解OpenCV和PIL读取和显示图像的差异
![](https://img.aspxhome.com/file/2023/8/133288_0s.jpg)
推荐四款可视化工具(解决99%的可视化大屏需求)
![](https://img.aspxhome.com/file/2023/4/127204_0s.jpg)
PHP 页面跳转到另一个页面的多种方法方法总结
Ubuntu下安装卸载python3.8的过程
SQL语句练习实例之三——平均销售等待时间
selenium+python实现文件上传操作的方法实例
![](https://img.aspxhome.com/file/2023/4/87814_0s.png)
ASP.NET连接SQL数据库的简单实例代码
python 实现简单的FTP程序
![](https://img.aspxhome.com/file/2023/2/85382_0s.jpg)
Tensorflow 使用pb文件保存(恢复)模型计算图和参数实例详解
使用SQL Server2005扩展函数进行性能优化
![](https://img.aspxhome.com/file/UploadPic/20106/20106712295687s.jpg)
ASP FCKeditor在线编辑器使用方法
JavaScript在ASP页面中实现掩码文本框效果代码
浅谈python中列表、字符串、字典的常用操作
Python/JS实现常见加密算法的示例代码
![](https://img.aspxhome.com/file/2023/2/97072_0s.png)
PHP chr()函数讲解
![](https://img.aspxhome.com/file/2023/6/55396_0s.png)
Python并发:多线程与多进程的详解
![](https://img.aspxhome.com/file/2023/9/115179_0s.png)
对Python 中矩阵或者数组相减的法则详解
![](https://img.aspxhome.com/file/2023/1/97011_0s.jpg)
Python脚本实现虾米网签到功能
![](https://img.aspxhome.com/file/2023/9/75889_0s.jpg)