如何使用命令行将单个表导入mysql数据库 [英] how to import a single table in to mysql database using command line

查看:314
本文介绍了如何使用命令行将单个表导入mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用命令行成功导入了一个数据库,但现在我的痛点是如何使用命令行将单个表及其数据导入现有数据库。

I had successfully imported a database using command line, but now my pain area is how to import a single table with its data to the existing database using command line.

推荐答案

Linux:

在命令行中

 mysql -u username -p  databasename  < path/example.sql

将你的表放在example.sql中

put your table in example.sql

单个表的导入/导出:


  1. 导出表架构

  1. Export table schema

mysqldump -u username -p databasename tableName > path/example.sql

这将创建一个名为 example.sql的文件在提到的路径上并写入 create table sql命令来创建表 tableName

This will create a file named example.sql at the path mentioned and write the create table sql command to create table tableName.

将数据导入表格

mysql -u username -p databasename < path/example.sql

此命令需要一个包含为表 tableName 插入语句。所有 insert 语句都将被执行并且数据将被加载。

This command needs an sql file containing data in form of insert statements for table tableName. All the insert statements will be executed and the data will be loaded.

这篇关于如何使用命令行将单个表导入mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆