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?

#1
I have a `.sql` file with an export from `phpMyAdmin`. I want to import it into a different server using the command line.

I have a [Windows Server 2008][1] R2 installation. I placed the `.sql` file on the ***C drive***, and I tried this command

database_name < file.sql

It is not working. I get syntax errors.

- How can I import this file without a problem?
- Do I need to create a database first?

[1]:

[To see links please register here]


Reply

#2
Go to the directory where you have MySQL.

c:\mysql\bin\> mysql -u username -p password database_name <
filename.sql

Also to dump all databases, use the `-all-databases` option, and no databases’ name needs to be specified anymore.

mysqldump -u username -ppassword –all-databases > dump.sql

Or you can use some GUI clients like SQLyog to do this.
Reply

#3
For backup purposes, make a BAT file and run this BAT file using [Task Scheduler][1]. It will take a backup of the database; just copy the following line and paste in [Notepad][2] and then save the .bat file, and run it on your system.

@echo off
for /f "tokens=1" %%i in ('date /t') do set DATE_DOW=%%i
for /f "tokens=2" %%i in ('date /t') do set DATE_DAY=%%i
for /f %%i in ('echo %date_day:/=-%') do set DATE_DAY=%%i
for /f %%i in ('time /t') do set DATE_TIME=%%i
for /f %%i in ('echo %date_time::=-%') do set DATE_TIME=%%i

"C:\Program Files\MySQL\mysql server 5.5\bin\mysqldump" -u username -ppassword mysql>C:/%DATE_DAY%_%DATE_TIME%_database.sql

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#4
Go to the directory where you have the MySQL executable. `-u` for username and `-p` to prompt for the password:

C:\xampp\mysql\bin>mysql -u username -ppassword databasename < C:\file.sql
Reply

#5
I thought it could be useful for those who are using [Mac OS X][1]:

/Applications/xampp/xamppfiles/bin/mysql -u root -p database < database.sql

Replace `xampp` with `mamp` or other web servers.

[1]:

[To see links please register here]

Reply

#6
If you are using [MAMP][1] on Mac OS X, this may be helpful:

/applications/MAMP/library/bin/mysql -u MYSQL_USER -p DATABASE_NAME < path/to/database_sql/FILE.sql

MYSQL_USER is root by default.

[1]:

[To see links please register here]

Reply

#7
1. Open the MySQL command line
2. Type the path of your mysql bin directory and press <kbd>Enter</kbd>
3. Paste your SQL file inside the `bin` folder of mysql server.
4. Create a database in MySQL.
5. Use that particular database where you want to import the SQL file.
6. Type `source databasefilename.sql` and <kbd>Enter</kbd>
7. Your SQL file upload successfully.
Reply

#8
The following steps help to upload `file.sql` to the MySQL database.

Step 1: Upload `file.sql.zip` to any directory and unzip there <br>
**Note**: `sudo apt-get install unzip`
: `sudo apt-get unzip file.sql.zip`<br>
Step 2: Now navigate to that directory. Example: `cd /var/www/html`<br>

Step 3: `mysql -u username -p database-name < file.sql`<br>
Enter the password and wait till uploading is completed.
Reply

#9
The following command works for me from the command line (cmd) on
Windows 7 on [WAMP][1].

d:/wamp/bin/mysql/mysql5.6.17/bin/mysql.exe -u root -p db_name < database.sql

[1]:

[To see links please register here]

Reply

#10
If your folder has multiple SQL files, and you've installed [Git Bash][1] you can use this command to import multiple files:

cd /my-project/data

cat *.sql | /c/xampp/mysql/bin/mysql -u root -p 1234 myProjectDbName

[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

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