Export Data from MySQL by mysqldump
how to export data from the mysql
use mysqldump
Just for the mysql/mariadb using:
1 | docker container run -it --rm mysql:8 bash -c "echo -e '[mysqldump]\nuser=aurora\npassword=aurora' > ~/.my.cnf && \ |
For the SQLite compatibility:
1 | docker container run -it --rm mysql:8 bash -c "echo -e '[mysqldump]\nuser=aurora\npassword=aurora' > ~/.my.cnf && \ |
Explanation in Details
docker container run -it --rm mysql:8 bash -c
:
mysql:8
is the image name and tag-it
is to run the container in interactive mode--rm
is to remove the container after it is stoppedbash -c
is to run the command in the container
The left is a combined command to create a .my.cnf
file and run mysqldump
command.
echo -e '[mysqldump]\nuser=aurora\npassword=aurora' > ~/.my.cnf
is to create a.my.cnf
file at$HOME
with the content1
2
3[mysqldump]
user=aurora
password=aurora--compact
is to use the compact format, which aims to remove the Comment Syntax, the/*!
and*/
are removed--no-create-info
is to skip theCREATE TABLE
statement, because the statement is not compatible with SQLite--skip-add-locks
is to skip theLOCK TABLES
statement, because the statement is not compatible with SQLite--complete-insert
is to use theINSERT INTO
statement with the column names-h
is to specify the db hostyour_database_name
is the database nametable1 table2 table3 table4
are the exported table names, separated by space; if not specified, all tables will be exported> exported.sql
is to redirect the output to a file namedexported.sql
, at the host current directory