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 configurationOPTION
用于提供详细的配置DBNAME
is the name of the database we want to importDBNAME
是我们要导入的数据库的名称FILE
is the file which contains the data and schemaFILE
是包含数据和架构的文件
导入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;
翻译自: https://www.poftut.com/mysql-database-import-tutorial-examples/