I have file.sql, and I want to restore it. I found this command:
mysql -u username -p database_name < file.sql
Where should I put 'file.sql' in file system? I'm using Windows and XAMPP. Thank you.
*) The dump file is 3GB++
you should navigate to dump file location and run mysql -u username -p database_name < file.sql
for example if your file is at c drive you can open terminal type cd \ (this will go to root folder if your windows is installed on c dirve) and run the above command
Related
I wrote a sql script to create a clean database (one.sql), I did this on CMD and it works,
cd MYSQL\path1\bin
mysql -u userID -ppassword -h host -P port < path2\one.sql > path2\test.log
it gives me the test.log file and database on the sql server was updated
And I tried to do the same thing using batch file,
#echo off
c:
cd "MYSQL\path1\bin"
mysql -u userID -ppassword -h host -P port < path2\one.sql > path2\test.log
pause
from the CMD prompt, it seems working, but no test.log file generated, and the new database in my sql server was not created.
I ran bat file by double clicking it in its folder.
Any suggestions?
Thank you
I am working on Linux (Ubuntu), and I want to export the whole schema from .sh file to .sql in order to open it in MySQL Workbench - but how can I do it?
I have tried with mysqldump but it doesn't work, I wrote this command after opening .sh database, but I am not sure if it has some influence.
Command line in terminal:
mysql> mysqldump -uuser -ppassword db > db.sql
And it doesn't work - MySQL syntax error displays after that
Here .sh means a script file extension in which you will write your commands and .sql means a backup/dump file.
Example
Execute below command on linux prompt-
sudo vi backup_script.sh
It will open a blank file you can write your script here like -
cd /root/backup/
mysqldump -uroot -proot123 mydb > /root/backup/mydb.sql
Now save this file by Esc + : + wq
Note: backup folder should exist in root else you can create by below command-
mkdir /root/backup
Now you can execute backup_script.sh by below command-
sh backup_script.sh
It wil take your mydb database backup at /root/backup/ path.
1.Install mysql-client which includes mysqldump
user#local:~$ sudo apt-get install mysql-client-5.1
2. backup database
user#local:~$ mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
3. if you need you can import
user#local:~$ mysql -u root -p[root_password] [database_name] < dumpfilename.sql
I have created a dump file for my database and now I want to put that
file on my server to get its access. I will copy that .sql file on my
server, but I don't know how to access that dump file using commands.
Assuming you are using command line
cd /path/where/sql/file/is
And then
mysql -u username -p database_name < file.sql
If you don't have the mysql bin in your PATH you might want to run
/path/to/mysql/bin/mysql -u username -p database_name < file.sql
Or temporarily put the file.sql in the mysql bin directory (not recommended)
Another possible scenario is to point to the file in the filesystem like this
mysql -u username -p database_name < /path/where/sql/file/is/file.sql
If you're on windows you might wanna change the forward slashes to backslashes.
If you want to restore MySQL database on remote-server, then very first thing is that, the .sql file is not necessarily present on server.
We can restore the backup right from our development machine(using mysql.exe of local machine), provided that you have MySQL user having MySQL Server remote access.
Use "-h" option while restoring the backup. "-h" implies hostname where MySQL Database Server is present. It can be in local network or on remote server.
mysql -h www.yourserver.com -u username -p database_name < file.sql
Or with IP Address (use actual IP Address of your Database Server)
mysql -h 112.112.112.112 -u username -p database_name < file.sql
And if you do not have remote-access enabled user, then you need to upload .sql file to remote-server and restore it by putting host-name as localhost. Like,
mysql -h localhost -u username -p database_name < file.sql
Hope it helps, thanks.
Question:
Please can anyone tell me, How to import mysql database through command prompt
Note:
I am beginner in mysql database
For Import Database in Phpmyadmin using cmd with process
C:>cd xampp
C:\xampp>cd mysql
C:\xampp\mysql>cd bin
Go to directory where you have mysql. -u - for username -p - to prompt the password
mysql -u username -ppassword databasename < file.sql
Note:It is better to use full path of the the sql file file.sql
To import database from dump file (in this case called filename.sql) use:
mysql -u username -p password database_name < filename.sql
If you are on Windows you will need to open CMD and go to directory where mysql.exe is installed. If you are using WAMP server then this is usually located in:
C:\wamp\bin\mysql\mysql5.1.36\bin (*note the version of mysql might be different)
So you will:
cd C:\wamp\bin\mysql\mysql5.1.36\bin
and then execute one of the above commands.
Try This
mysql -u username -p[******] database_name < mysqlfile.sql
For more details for export and import database please click here.
I'm currently trying to make a copy of a site to run locally, and i'm having some difficulty in downloading a dump of the mySQL database using PhpMyAdmin. (In that it doesn't work). I was wondering (and I suspect) if there is an sql command I can execute that would dump out the database to a location that I can download it via FTP.
I've found the following:
mysqldump --opt --user=root --password password > /home/backup/db.sql
but the page says that this will only run via shell, and I don't have shel access to the server. Can anyone help?
mysqldump -u root -p -T/path/ database
Simple Three steps Export mysql DB
**step1 :** run windows command prompt
**step2 :** make where yours wamp mysql stored directory ex E:\wamp\bin\mysql\mysql5.5.24\bin
**step 3 :**
E:\wamp\bin\mysql\mysql5.5.24\bin> mysqldump -u UserName -p PassWord dbname >c:\dbname.sql
PERFORM MySQL DATABASE DUMP:
Having registered mysql.exe in the Paths of Environment Variables (On
Windows Os)
Open windows console
Type the following Query:
mysqldump [Your database Name] -u root -p > C:/[Your Destination Directory ]/[ new Backup Database Name.sql ]
You will be prompted for a database user password
Enter Password:*******
when the dump is over...the directory will go back to the current
user session in Windows console
For this to work well, replace all parameters in square braces "[ ]" with your own values without the square braces
Open the Command prompt from MySQL bin folder (Make sure you have Read/Write Access)
Use the below mysqldump command
mysqldump -h [hostname] -u [username] -p [your database] > [your destination path][your filename.extn]
Ex: mysqldump -h localhost -u root -p test_DB > D:\MySQL\Dumps\test_file.sql
***WARNING : In case, if your custom path has any spaces in between, the above query will throw an error.
Invalid Path Description
To avoid Invalid Path Description, Give your path in double-quotes.
Ex : mysqldump -h localhost -u root -p test_DB > D:\MySQL\"Dumps from ABC"\test_file.sql
What are you looking for is Sypex Dumper 2. It exports (backups) your database directly to disk, so you can download the backup via ftp. It is written on php, supports large databases and has a very nice interface.
You can go to the directory where you want store the file, then execute de mysqldump command.
~/Desktop$ sudo /Applications/XAMPP/xamppfiles/bin/mysqldump -u root -p publicaciones > publicaciones.sql
PD. Use sudo to grant full permissions.
PD. If you have your PATH setup, don`t need use the full route to your MySql commands.