This paper version for the operating system and mysql8.0 the window.
1.mysql Export sql file
Here direct use mysql provided mysqlpump tool, the following explanation is mysqlpump
mysqlpump client backup utility execution logic to generate a set can be performed to reproduce the original database object definition table data and SQL statements. It dumps MySQL database to one or more backup or transfer to another SQL Server.
mysqlpump features include:
-
Parallel processing and database objects in the database, to accelerate the process dump
-
Better control to dump the database and database objects (tables, stored procedures, user account)
-
Dump user account management account statement ( , ) rather than as an insert system database
CREATE USER
GRANT
mysql
-
The ability to create compressed output
-
Progress Indicator (values are estimates)
-
For dump file reload,
InnoDB
by adding indexes after inserting rows to serve tables create a faster secondary index
mysqlpump need at leastdump the tableofprivilege,dump view,dump triggers, andnot usethe optionof privilege. Dump user-defined database system needsthepermission. Some options may require additional rights, such as the option descriptions.SELECT
SHOW VIEW
TRIGGER
LOCK TABLES
--single-transaction
SELECT
mysql
(1) a single database derived
语法:mysqlpump -h [ip] -P [port] -u [user_name] -p[password] db_name [tbl_name1 tbl_name2 ...] > file_path
(2) more Database Export
语法:mysqlpump -h [ip] -P [port] -u [user_name] -p[password] --databases db_name1 db_name2 ... > file_path
mysqlpump very powerful but also supports a variety of options, depending can view official documents
(3) copy data from one server to another MySQL server MySQL
语法:mysqldump -h [ip] -P [port] -u [user_name] -p[password] --opt db_name | mysql -h [ip] -P [port] -u [user_name] -p[password] --compress db_name
--opt: This option is enabled by default . It provides a fast dump operation and generate the dump file, you can quickly reload to MySQL server. --add-drop-table
--add-locks
--create-options
--disable-keys
--extended-insert
--lock-tables
--quick
--set-charset是组合的简写。
--compress: Compress all information sent between the client and the server (if possible). From the beginning of MySQL 8.0.18, this option is not recommended. It removes the MySQL version in the future.
2.mysql execute sql file
Enter the mysql client to perform: Source file_path or \ . File_path command.
3.mysql import bulk data
LOAD DATA complete syntax:
LOW_PRIORITY: If you use the LOW_PRIORITY
modifier, the statement execution will be delayed until no other clients read from the table. This affects only storage engines (for example, use only table-level locking , and ).LOAD DATA
MyISAM
MEMORY
MERGE
CONCURRENT: If supports concurrent insertion condition CONCURRENT
of the MyISAM
table specifies modifiers (i.e., it does not contain a free block in the middle), other threads may be performing retrieving data from the table . Even if no other threads use the table, this modifier will affect bit performance .LOAD DATA
LOAD DATA
LOCAL: If LOCAL
specified, the file is read and sent by the client program on the server to the client host. The file can be provided as a full pathname to specify its exact location. If given as a relative path name, relative to the startup directory is the client program to explain the name.
If LOCAL
not specified, the file must be located on the server host, read directly by the server. Non- LOCAL
load operation reads text files located on the server. For security reasons, this type of operation requires that you have the permission. In addition, non- loaded by the operating limits of the system variable. If the value is non-empty directory name, you will have to load the file must be in the directory. If the variable value is empty (it is not safe), the file server only needs to read.FILE
LOCAL
secure_file_priv
file_name: file path on Windows, the backslash is specified path name with a forward slash or backslash is doubled.
In REPLACE
the IGNORE
conventional process the input row control lines modified copy of a unique key value:
-
If specified
REPLACE
, the input line will replace an existing line. In other words, the primary key or a unique index value is the same as the conventional row. -
If specified
IGNORE
, the conventional copying rows are discarded rows on a unique key. -
If no modifier is specified, the behavior depends on whether or not
LOCAL
to specify a modifier. If notLOCAL
, then when it finds duplicate key error occurs, and ignores the rest of the text file. When using theLOCAL
default behavior andIGNORE
specify the same ; this is because the server was unable to stop transmission of the file during the operation.
PARTITION:
LOAD DATA
Support explicit partition selection, use PARTITION
with one or more options in a comma-separated names partition or subpartition both lists. When using this option, if any line in the file can not be inserted in any partition or sub-partition specified in the list, the statement will fail with the error " find the line with a given set of partitions that do not match." For more information and examples. For use table locks in the partition table storage engine, for example MyISAM
, LOAD DATA
you can not trim any partition lock. This does not apply to use row level locking storage engine tables, for example InnoDB
.
CHARACTER SET: server using the system variable character set of instructions to explain the information in the file. And setting do not affect the interpretation of input. If the character set used by the contents of the input file different from the default value is usually best to use this clause to the character set specified file .character_set_database
SET NAMES
character_set_client
CHARACTER SET
FIELDS: If specified FIELDS
clause, each clause ( TERMINATED BY
, [OPTIONALLY] ENCLOSED BY
, and ESCAPED BY
) is optional, but must be at least specify one clause . These clauses allow parameter contains only ASCII characters.
TERMINATED BY: separators between the fields and the field.
ENCLOSED BY: Fields enclosed, having only from a string data type.
ESCAPED BY: how to read or write special control characters, i.e. the escape character described.
LINES:
STARTING BY: if all input lines have a common prefix that you want to ignore, you can use to skip the prefix and any previous content . If the line does not include the prefix, the entire line is skipped.
TERMINATED BY: separator between each row with each row.
IGNORE number:
该选项可用于忽略文件开头的行.
col_name_or_user_var:默认情况下,如果在
LOAD DATA
语句末尾没有提供列列表 ,则输入行应包含每个表列的字段。如果只想加载某些表的列,请指定列列表。
SET
Clause: Each col_name_or_user_var
value is a column name or user variables. User variables, the SET
clause allows you to execute before the results are allocated to the column to its pre-conversion value.
4.mysql export bulk data
语法:SELECT [col_name [,col_name] ...] INTO OUTFILE 'file_path' [CHARACTER SET charset_name]
[{FIELDS | COLUMNS}
[TERMINATED BY 'string']
[[OPTIONALLY] ENCLOSED BY 'char']
[ESCAPED BY 'char']
]
[LINES
[STARTING BY 'string']
[TERMINATED BY 'string']
]
FROM table_name;
The statement is mainly used to allow you to quickly dump the table to a text file on the server computer. If you create a file to be generated on other host than the server host, usually it can not be used, because they can not write the file path relative to the server for the host's file system.SELECT ... INTO OUTFILE
SELECT ... INTO OUTFILE
However, if the MySQL client software installed on the remote computer, you can use the client command (for example, generated file on the client host). mysql -e "SELECT ..." >
file_name
If the network can be used to map the path on the server file system access files on a remote host location, you can also create files generated on a different host than the server host. In this case, it does not require the target host exists MySQL (or some other MySQL client program).
SELECT ... INTO OUTFILE
Supplement . The write column value is converted to clause specified character set . If there is no such clause, use the character set translation stored value . In fact, there is no character set conversion. If the result set contains multiple columns character set, the output data file will also do so, you may be unable to re-load the correct file.LOAD DATA
CHARACTER SET
binary