公告
财富商城
积分规则
提问
发文
2019-01-05 06:40发布
倾城 Initia
How can I import a database with mysql from terminal?
I cannot find the exact syntax.
mysql -u <username> -p <database name> < <dump file path>
-u - for username
-u
-p - to prompt the password
-p
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
Explanation:
First create a database or use an existing database. In my case, I am using an existing database
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
<name of database> = ClassicModels
<
database = sakila-data.sql
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.
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
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.
cd
最多设置5个标签!
mysql -u <username> -p <database name> < <dump file path>
-u
- for username-p
- to prompt the passwordmysql -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
Explanation:
First create a database or use an existing database. In my case, I am using an existing database
Load the database by giving
<name of database> = ClassicModels
in my case and using the operator<
give the path to thedatabase = sakila-data.sql
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.
Directly from var/www/html
From within mysql:
Assuming you're on a Linux or Windows console:
Prompt for password:
Enter password directly (not secure):
Example:
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.