DEV Community

Cover image for Import database to docker with terminal
mohammad hassani
mohammad hassani

Posted on

3 2

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 your .sql file to var/lib/docker/volumes/blog_blogmysql/_data

in terminal:

cp DATABASE.sql var/lib/docker/volumes/blog_blogmysql/_data
Enter fullscreen mode Exit fullscreen mode

// 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
Enter fullscreen mode Exit fullscreen mode

// Replace CONTAINERNAME to your container name like site_mysql_1

3) Bring up mysql

now open mysql in terminal:

mysql -uroot -p DATABASENAME
Enter fullscreen mode Exit fullscreen mode
  • if you dont have database in container you can use
mysql -uroot -p
Enter fullscreen mode Exit fullscreen mode

and then:

CREATE DATABASE DATABASENAME;
Enter fullscreen mode Exit fullscreen mode

// 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

that's it!

if you have another way, leave a message :)

Be happy! ;)

buy me a coffee

API Trace View

Struggling with slow API calls?

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more β†’

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post