How do I import an SQL file using the command line in MySQL?
Try:
mysql -u username -p database_name < file.sql
Check MySQL Options.
Note 1: It is better to use the full path of the SQL file file.sql
.
Note 2: Use -R
and --triggers
to keep the routines and triggers of original database. They are not copied by default.
Note 3 You may have to create the (empty) database from MySQL if it doesn't exist already and the exported SQL don't contain CREATE DATABASE
(exported with --no-create-db
or -n
option), before you can import it.
How do I import an SQL file using the command line in MySQL?
Try:
mysql -u username -p database_name < file.sql
Check MySQL Options.
Note 1: It is better to use the full path of the SQL file file.sql
.
Note 2: Use -R
and --triggers
to keep the routines and triggers of original database. They are not copied by default.
Note 3 You may have to create the (empty) database from MySQL if it doesn't exist already and the exported SQL don't contain CREATE DATABASE
(exported with --no-create-db
or -n
option), before you can import it.
How do I import an SQL file using the command line in MySQL?
Try:
mysql -u username -p database_name < file.sql
Check MySQL Options.
Note 1: It is better to use the full path of the SQL file file.sql
.
Note 2: Use -R
and --triggers
to keep the routines and triggers of original database. They are not copied by default.
Note 3 You may have to create the (empty) database from MySQL if it doesn't exist already and the exported SQL don't contain CREATE DATABASE
(exported with --no-create-db
or -n
option), before you can import it.
import .sql file into mysql from mac command line. tried mysql -u root -p db_name path/to/dbfile.sql
You should use the mysql
command in order to import a mysqldump sql file:
mysql -u root -p db_name < ~/Documents/db_name.sql
The mysqlimport
utility is used to insert data from textfiles into the database, it is a wrapper around the LOAD DATA INFILE
sql statement. From mysqlimport documentation:
The mysqlimport client provides a command-line interface to the LOAD
DATA INFILE SQL statement. Most options to mysqlimport correspond
directly to clauses of LOAD DATA INFILE syntax. See Section 13.2.6,
“LOAD DATA INFILE Syntax”.
Importing large sql file to MySql via command line
You can import .sql file using the standard input like this:
mysql -u <user> -p<password> <dbname> < file.sql
Note: There shouldn't space between <-p>
and <password>
Reference: http://dev.mysql.com/doc/refman/5.0/en/mysql-batch-commands.html
Note for suggested edits: This answer was slightly changed by suggested edits to use inline password parameter. I can recommend it for scripts but you should be aware that when you write password directly in the parameter (-p<password>
) it may be cached by a shell history revealing your password to anyone who can read the history file. Whereas -p
asks you to input password by standard input.
Import SQL file into mysql
Finally, i solved the problem. I placed the `nitm.sql` file in `bin` file of the `mysql` folder and used the following syntax.
C:\wamp\bin\mysql\mysql5.0.51b\bin>mysql -u root nitm < nitm.sql
And this worked.
Importing sql file to MySQL
Use the file as input to the mysql
command from the shell command prompt.
$ mysql -h servername -u username -p databasename < filename.sql
You will then be prompted for your password.
If you're already inside the mysql
program, you can use its source
command.
mysql> source filename.sql
How can I import a database with MySQL from terminal?
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.
Import SQL file by command line in Windows 7
Try like this:
I think you need to use the full path at the command line, something like this, perhaps:
C:\xampp\mysql\bin\mysql -u {username} -p {databasename} < file_name.sql
Refer this link also:
http://www.ryantetek.com/2011/09/importing-large-sql-files-through-command-line-when-using-phpmyadminxampp/
Related Topics
Gem Install: Failed to Build Gem Native Extension (Can't Find Header Files)
Insert into a MySQL Table or Update If Exists
Is There Any Rule of Thumb to Construct SQL Query from a Human-Readable Description
Why Does Oracle 9I Treat an Empty String as Null
How to Make SQL Case Sensitive String Comparison on MySQL
Difference Between Single and Double Quotes in Sql
How to Create a Temporary Table in an Oracle Database
Select Group of Rows That Match All Items in a List
SQL Join - Where Clause Vs. on Clause
Calculate a Running Total in MySQL
How to Do the Recursive Select Query in MySQL
Equivalent of Limit and Offset For SQL Server
Difference Between Join and Inner Join
Is There an Oracle SQL Query That Aggregates Multiple Rows into One Row