Import and Export Databases in MySQL Docker Container

2019/05/03 Deployment

导入数据

$ docker exec -it mysqltest2 bash
root@28ddb46a15b8:/#
root@28ddb46a15b8:/# mysql -uroot -p123456
mysql> select host,user,plugin,authentication_string from mysql.user;
mysql> ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';(自己修改数据库密码)
mysql> FLUSH PRIVILEGES;

#copy data to /docker/mysql/data/
root@28ddb46a15b8:/# mysql -uroot -p < employees.sql

导入导出命令

# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql

# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
docker exec -i mysql_container mysql -uroot -psecret mysql < db.sql
docker exec -i container_name mysql -uroot dbname < data.sql;

Reference

Search

    Table of Contents