Import database to docker with terminal

Hey, this is Mohammad Hassani 😃

if you are developing with Linux and wanna import database to docker with terminal you can use this tutorial…

It’s just 4 steps

1) copy database to _data folder:

first of all you should copy you…


This content originally appeared on DEV Community and was authored by mohammad hassani

Hey, this is Mohammad Hassani 😃

if you are developing with Linux and wanna import database to docker with terminal you can use this tutorial...

It's just 4 steps

1) copy database to _data folder:

first of all you should copy your .sql file to var/lib/docker/volumes/blog_blogmysql/_data

in terminal:

cp DATABASE.sql var/lib/docker/volumes/blog_blogmysql/_data

// Replace DATABASE to your database file name

2) execute docker

now your database is ready to import, in this step execute docker in terminal,
(docker desktop is not supported in Linux but you can install dockstation for Linux, they are similar. and then you can execute there)

also in terminal:

docker exec -it CONTAINERNAME bash

// Replace CONTAINERNAME to your container name like site_mysql_1

3) Bring up mysql

now open mysql in terminal:

mysql -uroot -p DATABASENAME
  • if you dont have database in container you can use
mysql -uroot -p

and then:

CREATE DATABASE DATABASENAME;

// Replace DATABASENAME to your database name

4) source .sql file

ok! everything is set now and ready to go...
in terminal:

source var/lib/mysql/DATABASE.sql

it maybe take some time depends on your .sql file size and your computer.

better way

  • you can use this code instead of step 3 and 4:
mysql --init-command="set autocommit=0" DATABASENAME < var/lib/mysql/DATABASE.sql

that's it!

if you have another way, leave a message :)

Be happy! ;)

buy me a coffee


This content originally appeared on DEV Community and was authored by mohammad hassani


Print Share Comment Cite Upload Translate Updates
APA

mohammad hassani | Sciencx (2022-01-08T19:33:04+00:00) Import database to docker with terminal. Retrieved from https://www.scien.cx/2022/01/08/import-database-to-docker-with-terminal/

MLA
" » Import database to docker with terminal." mohammad hassani | Sciencx - Saturday January 8, 2022, https://www.scien.cx/2022/01/08/import-database-to-docker-with-terminal/
HARVARD
mohammad hassani | Sciencx Saturday January 8, 2022 » Import database to docker with terminal., viewed ,<https://www.scien.cx/2022/01/08/import-database-to-docker-with-terminal/>
VANCOUVER
mohammad hassani | Sciencx - » Import database to docker with terminal. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/08/import-database-to-docker-with-terminal/
CHICAGO
" » Import database to docker with terminal." mohammad hassani | Sciencx - Accessed . https://www.scien.cx/2022/01/08/import-database-to-docker-with-terminal/
IEEE
" » Import database to docker with terminal." mohammad hassani | Sciencx [Online]. Available: https://www.scien.cx/2022/01/08/import-database-to-docker-with-terminal/. [Accessed: ]
rf:citation
» Import database to docker with terminal | mohammad hassani | Sciencx | https://www.scien.cx/2022/01/08/import-database-to-docker-with-terminal/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.