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:27

mysql -u <username> -p <database name> < <dump file path>

-u - for username

-p - to prompt the password

mysql -u root -p mydb < /home/db_backup.sql

else you can pass password preceded by -p but for the security reasons it is not suggestible

查看更多
做个烂人
3楼-- · 2019-01-05 07:29

How to load from command line

Explanation:

  1. First create a database or use an existing database. In my case, I am using an existing database

  2. Load the database by giving <name of database> = ClassicModels in my case and using the operator < give the path to the database = sakila-data.sql

  3. By running show tables, I get the list of tables as you can see.

Note : In my case I got an error 1062, because I am trying to load the same thing again.

查看更多
地球回转人心会变
4楼-- · 2019-01-05 07:32

Directly from var/www/html

mysql -u username -p database_name < /path/to/file.sql

From within mysql:

mysql> use db_name;
mysql> source backup-file.sql
查看更多
唯我独甜
5楼-- · 2019-01-05 07:34

Assuming you're on a Linux or Windows console:

Prompt for password:

mysql -u <username> -p <databasename> < <filename.sql>

Enter password directly (not secure):

mysql -u <username> -p<PlainPassword> <databasename> < <filename.sql>

Example:

mysql -u root -p wp_users < wp_users.sql

mysql -u root -pPassword123 wp_users < wp_users.sql

See also:

4.5.1.5. Executing SQL Statements from a Text File


Note: If you are on windows then you will have to cd (change directory) to your MySQL/bin directory inside the CMD before executing the command.

查看更多
登录 后发表回答