Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 399 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I import an SQL file using the command line in MySQL?

#11
You do not need to specify the name of the database on the command line if the .sql file contains `CREATE DATABASE IF NOT EXISTS db_name` and `USE db_name` statements.

Just make sure you are connecting with a user that has the permissions to create the database, if the database mentioned in the .sql file does not exist.
Reply

#12
Add the [`--force` option][1]:

mysql -u username -p database_name --force < file.sql

[1]:

[To see links please register here]

Reply

#13
Among all the answers, for the problem above, this is the best one:

mysql> use db_name;
mysql> source file_name.sql;
Reply

#14
Providing credentials on the command line is not a good idea. The above answers are great, but neglect to mention

mysql --defaults-extra-file=etc/myhost.cnf database_name < file.sql

Where etc/myhost.cnf is a file that contains host, user, password, and you avoid exposing the password on the command line. Here is a sample,

[client]
host=hostname.domainname
user=dbusername
password=dbpassword


Reply

#15
I think it's worth mentioning that you can also load a **gzipped (compressed)** file with `zcat` like shown below:

<!-- language: bash -->

zcat database_file.sql.gz | mysql -u username -p -h localhost database_name
Reply

#16
To import a single database, use the following command.

mysql -u username -p password dbname < dump.sql

To import multiple database dumps, use the following command.

mysql -u username -p password < dump.sql
Reply

#17
A solution that worked for me is below:

Use your_database_name;
SOURCE path_to_db_sql_file_on_your_local;
Reply

#18
You can try this query.

Export:

mysqldump -u username –-password=your_password database_name > file.sql



Import:

mysql -u username –-password=your_password database_name < file.sql

and detail following this link:

[To see links please register here]

Reply

#19
**In Ubuntu**

mysql -u root -p
CREATE database dbname;
use dbname;
source /home/computername/Downloads/merchantapp.sql
exit;

**In Windows**

Download the SQL file and save it in `C:\xampp\mysql\bin`.

After that, open the command prompt with `C:\xampp\mysql\bin`:

C:\xampp\mysql\bin> mysql -u username -p database_name < file.sql
Reply

#20
### To import a database via the terminal

Navigate to folder where the .sql file is located

Then run the below command:

mysql -u database_user_name -p database_name < sql_file_name.sql

It will ask for a password. Enter the database password. It will take a few seconds to import the data into the database.
Reply



Forum Jump:


Users browsing this thread:
4 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through