Mysql数据库导入教程及示例

Backup and Restore operations are important part of the database administration. mysqlimport command is used to load data in file into Mysql or Mariadb servers. Mysql import is generally used by providing SQLfile.

备份和还原操作是数据库管理的重要组成部分。 mysqlimport命令用于将文件中的数据加载到Mysql或Mariadb服务器中。 Mysql导入通常通过提供SQLfile来使用。

句法 (Syntax)

Syntax of mysqlimport is like below.

mysqlimport语法如下。

mysqlimport OPTIONS DBNAME FILE

mysqlimport选项DBNAME文件

  • OPTION is used provide detailed configuration

    OPTION用于提供详细的配置

  • DBNAME is the name of the database we want to import

    DBNAME是我们要导入的数据库的名称

  • FILE is the file which contains the data and schema

    FILE是包含数据和架构的文件

导入SQL文件(Import SQL File)

The first example is simply importing the data file into mysql database. We will provide the username with -u and insert into database name students the sql file named newstudents.sql .

第一个示例只是将数据文件导入mysql数据库。 我们将提供的用户名与-u并插入到数据库名students的sql文件名为newstudents.sql

$ mysqlimport -uroot students newstudents.sql

交互提供密码 (Provide Password Interactively)

We may need to provide the password for the user. We can use -p option to provide the password. In this example we will use user ismail and provide password interactively.

我们可能需要为用户提供密码。 我们可以使用-p选项来提供密码。 在此示例中,我们将使用ismail用户并以交互方式提供密码。

$ mysqlimport -u ismail -p students newstudents.sql

提供明文密码批处理模式 (Provide Password Batch Mode in Clear Text)

Another practical way to provide password is batch mode. But keep in mind this is a security violation for the most of the situations. We will provide the password in cleartext with -p option. In this example the password is sosecret .

提供密码的另一种实用方法是批处理模式。 但是请记住,在大多数情况下,这是违反安全性的行为。 我们将使用-p选项以明文形式提供密码。 在此示例中,密码为sosecret

$ mysqlimport -u ismail -p sosecret students newstudents.sql

从Mysql Interactive Shell导入 (Import From Mysql Interactive Shell)

We can use mysql shell in order to import sql files. In order to use mysql interactive shell for sql file import we should open the shell.

我们可以使用mysql shell来导入sql文件。 为了将mysql交互式外壳用于sql文件导入,我们应该打开外壳。

$ mysql -u root -p

选择数据库 (Select Database)

and then we will select the database we want to import given sql file.

然后,我们将选择要导入给定sql文件的数据库。

select students;

指定SQL文件 (Specify SQL File)

and the last step is specifying the sql file with \. operator. The SQL file must be in a compatible format in order to complete import operation successfully.

最后一步是使用\.指定sql文件\. 操作员。 SQL文件必须采用兼容格式,以便成功完成导入操作。

\. \home\ismail\newstudents.sql;
LEARN MORE  How To Recover or Reset Lost MySQL Password On Linux?
了解更多如何在Linux上恢复或重置丢失MySQL密码?

翻译自: https://www.poftut.com/mysql-database-import-tutorial-examples/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值