How can I import a database with MySQL from termin

2019-01-05 06:40发布

How can I import a database with mysql from terminal?

I cannot find the exact syntax.

标签: mysql import
16条回答
太酷不给撩
2楼-- · 2019-01-05 07:09

Preferable way for windows:

  1. Open the console and start the interactive MySQL mode

  2. use <name_of_your_database>;

  3. source <path_of_your_.sql>

查看更多
SAY GOODBYE
3楼-- · 2019-01-05 07:09

From Terminal:

mysql -uroot -p --default-character-set=utf8 database_name </database_path/database.sql
查看更多
祖国的老花朵
4楼-- · 2019-01-05 07:09

In Ubuntu, from MySQL monitor, you have already used this syntax:

mysql> use <dbname> -> The USE statement tells MySQL to use dbname as the default database for subsequent statements

mysql> source <file-path>

for example:

mysql> use phonebook;

mysql> source /tmp/phonebook.sql;

Important: make sure the sql file is in a directory that mysql can access to like /tmp

查看更多
戒情不戒烟
5楼-- · 2019-01-05 07:09

The simplest way to import a database in your MYSQL from the terminal is done by the below-mentioned process -

mysql -u root -p root database_name < path to your .sql file

What I'm doing above is:

  1. Entering to mysql with my username and password (here it is root & root)
  2. After entering the password I'm giving the name of database where I want to import my .sql file. Please make sure the database already exists in your MYSQL
  3. The database name is followed by < and then path to your .sql file. For example, if my file is stored in Desktop, the path will be /home/Desktop/db.sql

That's it. Once you've done all this, press enter and wait for your .sql file to get uploaded to the respective database

查看更多
倾城 Initia
6楼-- · 2019-01-05 07:11

in the terminal type

mysql -uroot -p1234; use databasename; source /path/filename.sql
查看更多
趁早两清
7楼-- · 2019-01-05 07:13

I usually use this command to load my SQL data when divided in files with names : 000-tableA.sql, 001-tableB.sql, 002-tableC.sql.

for anyvar in *.sql; do <path to your bin>/mysql -u<username> -p<password>  <database name> < $anyvar; done

Works well on OSX shell.

查看更多
登录 后发表回答