Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting data from MySQL docker container

I use the official MySQL docker image, and I am having difficulty exporting data from the instance without errors. I run my export like this:

docker run -it --link containername:mysql --rm mysql sh -c 
    'exec mysqldump 
        -h"$MYSQL_PORT_3306_TCP_ADDR" 
        -P"$MYSQL_PORT_3306_TCP_PORT" -uroot 
        -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" 
     dbname'
| gz > output.sql.gz

However, this results in the warning:

"mysqldump: [Warning] Using a password on the command line interface can be insecure."

As the first line of the outputted file. Obviously this later causes problems for any other MySQL processes which are used to consume the data.

Is there any way to suppress this warning from the mysqldump client?

like image 972
DMCoding Avatar asked Jan 13 '16 17:01

DMCoding


4 Answers

A little late to answer but this command saved my day.

docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
like image 200
priteshbaviskar Avatar answered Oct 23 '22 20:10

priteshbaviskar


I realise that this is an old question, but for those stumbling across it now I put together a post about exporting and importing from mysql docker containers: https://medium.com/@tomsowerby/mysql-backup-and-restore-in-docker-fcc07137c757 It covers the "Using a password on the command line interface..." warning and how to bypass it.

like image 22
tomsowerby Avatar answered Oct 23 '22 21:10

tomsowerby


Run Following command on terminal

docker exec CONTAINER_id /usr/bin/mysqldump -uusername --password=yourpassword databasename> backup.sql

Replace the

  1. CONTAINER_id. username, yourpassword

with specific to your configuration.

To get Container Id :

docker container ls
like image 4
Ankur Garg Avatar answered Oct 23 '22 21:10

Ankur Garg


To eliminate this exact warning you can pass password in MYSQL_PWD environment variable or use other connection method - see http://dev.mysql.com/doc/refman/5.7/en/password-security-user.html

docker run -it --link containername:mysql --rm mysql sh -c 
    'export MYSQL_PWD="$MYSQL_ENV_MYSQL_ROOT_PASSWORD"; exec mysqldump 
        -h"$MYSQL_PORT_3306_TCP_ADDR" 
        -P"$MYSQL_PORT_3306_TCP_PORT" -uroot 
     dbname'
| gz > output.sql.gz
like image 3
Vasfed Avatar answered Oct 23 '22 22:10

Vasfed