I was given a MySQL database file that I need to restore as a database on my Windows Server 2008 machine.
I tried using MySQL Administrator, but I got the following error:
The selected file was generated by
mysqldump and cannot be restored by
this application.
How do I get this working?
If the database you want to restore doesn't already exist, you need to create it first.
On the command-line, if you're in the same directory that contains the dumped file, use these commands (with appropriate substitutions):
C:\> mysql -u root -p
mysql> create database mydb;
mysql> use mydb;
mysql> source db_backup.dump;
It should be as simple as running this:
mysql -u <user> -p < db_backup.dump
If the dump is of a single database you may have to add a line at the top of the file:
USE <database-name-here>;
If it was a dump of many databases, the use statements are already in there.
To run these commands, open up a command prompt (in Windows) and cd to the directory where the mysql.exe executable is (you may have to look around a bit for it, it'll depend on how you installed mysql, i.e. standalone or as part of a package like WAMP). Once you're in that directory, you should be able to just type the command as I have it above.
You simply need to run this:
mysql -p -u[user] [database] < db_backup.dump
If the dump contains multiple databases you should omit the database name:
mysql -p -u[user] < db_backup.dump
To run these commands, open up a command prompt (in Windows) and cd to the directory where the mysql.exe executable is (you may have to look around a bit for it, it'll depend on how you installed mysql, i.e. standalone or as part of a package like WAMP). Once you're in that directory, you should be able to just type the command.
mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
look here - step 3: this way you dont need the USE statement
When we make a dump file with mysqldump, what it contains is a big SQL script for recreating the databse contents. So we restore it by using starting up MySQL’s command-line client:
mysql -uroot -p
(where root is our admin user name for MySQL), and once connected to the database we need commands to create the database and read the file in to it:
create database new_db;
use new_db;
\. dumpfile.sql
Details will vary according to which options were used when creating the dump file.
Run the command to enter into the DB
# mysql -u root -p
Enter the password for the user Then Create a New DB
mysql> create database MynewDB;
mysql> exit
And make exit.Afetr that.Run this Command
# mysql -u root -p MynewDB < MynewDB.sql
Then enter into the db and type
mysql> show databases;
mysql> use MynewDB;
mysql> show tables;
mysql> exit
Thats it ........ Your dump will be restored from one DB to another DB
Or else there is an Alternate way for dump restore
# mysql -u root -p
Then enter into the db and type
mysql> create database MynewDB;
mysql> show databases;
mysql> use MynewDB;
mysql> source MynewDB.sql;
mysql> show tables;
mysql> exit
If you want to view the progress of the dump try this:
pv -i 1 -p -t -e /path/to/sql/dump | mysql -u USERNAME -p DATABASE_NAME
You'll of course need 'pv' installed. This command works only on *nix.
I got it to work following these steps…
Open MySQL Administrator and connect to server
Select "Catalogs" on the left
Right click in the lower-left box and choose "Create New Schema"
MySQL Administrator http://img204.imageshack.us/img204/7528/adminsx9.th.gif enlarge image
Name the new schema (example: "dbn")
MySQL New Schema http://img262.imageshack.us/img262/4374/newwa4.th.gif enlarge image
Open Windows Command Prompt (cmd)
Windows Command Prompt http://img206.imageshack.us/img206/941/startef7.th.gif enlarge image
Change directory to MySQL installation folder
Execute command:
mysql -u root -p dbn < C:\dbn_20080912.dump
…where "root" is the name of the user, "dbn" is the database name, and "C:\dbn_20080912.dump" is the path/filename of the mysqldump .dump file
MySQL dump restore command line http://img388.imageshack.us/img388/2489/cmdjx0.th.gif enlarge image
Enjoy!
As a specific example of a previous answer:
I needed to restore a backup so I could import/migrate it into SQL Server. I installed MySql only, but did not register it as a service or add it to my path as I don't have the need to keep it running.
I used windows explorer to put my dump file in C:\code\dump.sql. Then opened MySql from the start menu item. Created the DB, then ran the source command with the full path like so:
mysql> create database temp
mysql> use temp
mysql> source c:\code\dump.sql
You can try SQLyog 'Execute SQL script' tool to import sql/dump files.
Using a 200MB dump file created on Linux to restore on Windows w/ mysql 5.5 , I had more success with the
source file.sql
approach from the mysql prompt than with the
mysql < file.sql
approach on the command line, that caused some Error 2006 "server has gone away" (on windows)
Weirdly, the service created during (mysql) install refers to a my.ini file that did not exist. I copied the "large" example file to my.ini
which I already had modified with the advised increases.
My values are
[mysqld]
max_allowed_packet = 64M
interactive_timeout = 250
wait_timeout = 250
./mysql -u <username> -p <password> -h <host-name like localhost> <database-name> < db_dump-file
You cannot use the Restore menu in MySQL Admin if the backup / dump wasn't created from there. It's worth a shot though. If you choose to "ignore errors" with the checkbox for that, it will say it completed successfully, although it clearly exits with only a fraction of rows imported...this is with a dump, mind you.
One-liner command to restore the generated SQL from mysqldump
mysql -u <username> -p<password> -e "source <path to sql file>;"
Assuming you already have the blank database created, you can also restore a database from the command line like this:
mysql databasename < backup.sql
You can also use the restore menu in MySQL Administrator. You just have to open the back-up file, and then click the restore button.
If you are already inside mysql prompt and assume your dump file dump.sql, then we can also use command as below to restore the dump
mysql> \. dump.sql
If your dump size is larger set max_allowed_packet value to higher. Setting this value will help you to faster restoring of dump.
How to Restore MySQL Database with MySQLWorkbench
You can run the drop and create commands in a query tab.
Drop the Schema if it Currently Exists
DROP DATABASE `your_db_name`;
Create a New Schema
CREATE SCHEMA `your_db_name`;
Open Your Dump File
Click the Open an SQL script in a new query tab icon and choose your db dump file.
Then Click Run SQL Script...
It will then let you preview the first lines of the SQL dump script.
You will then choose the Default Schema Name
Next choose the Default Character Set utf8 is normally a safe bet, but you may be able to discern it from looking at the preview lines for something like character_set.
Click Run
Be patient for large DB restore scripts and watch as your drive space melts away! 🎉
Local mysql:
mysql -u root --password=YOUR_PASS --database=YOUR_DB < ./dump.sql
And if you use docker:
docker exec -i DOCKER_NAME mysql -u root --password=YOUR_PASS --database=YOUR_DB < ./dump.sql
Related
I am running WAMP on Windows 7 and accessing MySQL command line to do some MySQL work. I cannot get the commands for dumping a specific table working (note: I already selected the db with USE db_name):
This works perfectly fine for doing a full db dump:
mysql> mysqldump -u root -p db_name > output_db_name.sql
But I cannot dump a specific table like so:
mysql> mysqldump -u root -p db_name table_name > output_table_dump.sql
Goes to
->
->
I tried many variations and I can't get it to output.
If you are not experienced with a command-line environment, you should use MySQL Workbench. It's a free GUI application that runs on Windows, Mac, and Linux.
To dump a given table in a given database, you can choose the "Data Export" function, and then select individual databases and tables.
The GUI runs mysqldump for you. The output is that of mysqldump, so it's 100% compatible with any way you could produce the dump at the command-line.
This question already has answers here:
How do I rename a MySQL database (change schema name)?
(46 answers)
Closed 8 years ago.
I created a database with the name of hrms. Now I need to change database name to sunhrm. But, It is disabled in MySQL workbench. Can I do that on the Linux server itself?
In case you need to do that from the command line, just copy, adapt & paste this snippet:
mysql -e "CREATE DATABASE \`new_database\`;"
for table in `mysql -B -N -e "SHOW TABLES;" old_database`
do
mysql -e "RENAME TABLE \`old_database\`.\`$table\` to \`new_database\`.\`$table\`"
done
mysql -e "DROP DATABASE \`old_database\`;"
I don't think you can do this. Basic answers will work in many cases, and in others cause data corruptions. A strategy needs to be chosen based on heuristic analysis of your database. That is the reason this feature was implemented, and then removed. [doc]
You'll need to dump all object types in that database, create the newly named one and then import the dump. If this is a live system you'll need to take it down. If you cannot, then you will need to setup replication from this database to the new one.
If you want to see the commands that could do this, #satishD has the details, which conveys some of the challenges around which you'll need to build a strategy that matches your target database.
It's possible to copy database via mysqldump command without storing dump into file:
mysql -u root -p -e "create database my_new_database"
mysqldump -u root -p original_database | mysql -u root -p my_new_database
mysql -u root -p -e "drop database original_database"
You can create a new database exactly as the previous database existed and then drop the old database when you're done. Use the mysqldump tool to create a .sql backup of the database via mysqldump orig_db > orig_db.sql or if you need to use a username and password then run mysqldump -u root -p orig_db > orig_db.sql. orig_db is the name of the database you want to "rename", root would be the user you're logging in as and orig_db.sql would be the file created containing the backup. Now create a new, empty database with the name you want for the database. For example, mysql -u root -p -e "create database new_db". Once that's done, then run mysql -u root -p new_db < orig_db.sql. new_db now exists as a perfect copy of orig_db. You can then drop the original database as you now have it existing in the new database with the database name you wanted.
The short, quick steps without all the above explanation are:
mysqldump -u root -p original_database > original_database.sql
mysql -u root -p -e "create database my_new_database"
mysql -u root -p my_new_database < original_database.sql
mysql -u root -p -e drop database originl_database
Hope this helps and this is a reliable means to accomplish it without using some ad-hoc method that will corrupt your data and create inconsistencies.
You can do it by RENAME statement for each table in your "current_db" after create the new schema "other_db"
RENAME TABLE current_db.tbl_name TO other_db.tbl_name
Source Rename Table Syntax
In short no. It is generally thought to be too dangerous to rename a database. MySQL had that feature for a bit, but it was removed. You would be better off using the workbench to export both the schema and data to SQL then changing the CREATE DATABASE name there before you run/import it.
I used following method to rename the database
take backup of the file using mysqldump or any DB tool eg heidiSQL,mysql administrator etc
Open back up (eg backupfile.sql) file in some text editor.
Search and replace the database name and save file.
Restore the edited SQL file
If your DB contains only MyISAM tables (do not use this method if you have InnoDB tables):
shut down the MySQL server
go to the mysql data directory and rename the database directory (Note: non-alpha characters need to be encoded in a special way)
restart the server
adjust privileges if needed (grant access to the new DB name)
You can script it all in one command so that downtime is just a second or two.
For impatient mysql users (like me), the solution is:
/etc/init.d/mysql stop
mv /var/lib/mysql/old_database /var/lib/mysql/new_database
/etc/init.d/mysql start
First backup the old database called HRMS and edit the script file with replace the word HRMS to SUNHRM. After this step import the database file to the mysql
Another way to rename the database or taking image of the database is by using Reverse engineering option in the database tab. It will create a ERR diagram for the database. Rename the schema there.
after that go to file menu and go to export and forward engineer the database.
Then you can import the database.
I don't know much about MySQL at all. But I am trying to reverse engineer a MySQL database using Visio. I know what steps I should take to do this, but I can't get my database to show in the 'Databases' section (as below):
How do I create the MySQL database using the .SQL file and get it to show up in this list? I have tried this code:
mysql -u username -p password database_name < filename.sql
using my own credentials of course. But that doesn't seem to work. In what folder should the .SQL file be placed if this statement is to work?
1) Create a file "filename.sql"
2) Create a database in your DB in which you want to import this file.
3) From command-prompt/terminal, move to the directory where you have created a "filename.sql".
4) Run the command: mysql -u username -p password database_name < filename.sql. (You can also give the proper path of your file and run this command from anywhere). It might be the case that you don't have a password set for MySQL. If so, mysql -u username database_name < filename.sql will also work.
In your case if you have created a database with name ojs and also created a file with name ojs.sql in C: drive then run the following command:
Edit: Put the path inside quotes.
mysql -u username -p password ojs < "C:\ojs.sql"
There is another way of importing tables in mysql. You can do it this way as well:
1) Connect your database
2) Type command "use ojs;"
3) Type command "source C:/ojs.sql"
Most MySQL SQL files that create databases create the database 'on-the-fly', so you typically needn't do anything except:
log-in
mysql -u [username] -p[password]
(Note: make sure you do NOT include a space (' ') character between the -p and the [password].
MySQL will think that [password] is the name of the database you want to connect to.
The 'general' log-in (above) does not assume you want to connect to any particular schema.)
source the file (do not use quotes around filename)
mysql> source [database_creation_file].sql
you can simply do it using mysql workbench
1> create a new query tab
2> CREATE DATABASE database_name;
3> USE database_name;
4> open the filename.sql file and execute it ctrl + shift + enter
5> all the tables in the filename.sql are created
To create a MySQL database using a SQL file, you can follow these steps:
Log in to your MySQL server using the mysql command-line tool and the appropriate credentials.
Use the CREATE DATABASE command to create a new database with the desired name:
CREATE DATABASE database_name;
Use the USE command to switch to the newly created database:
USE database_name;
Use the SOURCE command to import the SQL file into the database:
SOURCE path/to/sql/file;
The database will now be created and populated with the data from the SQL file. You can verify this by running some SQL queries against the database.
It's important to note that this process assumes that the SQL file contains valid SQL statements compatible with the version of MySQL you are using. If the SQL file contains any errors or unsupported statements, they will be displayed in the mysql command-line tool, and the import process will be interrupted.
I have a database called nitm. I haven't created any tables there. But I have a SQL file which contains all the necessary data for the database. The file is nitm.sql which is in C:\ drive. This file has size of about 103 MB. I am using wamp server.
I have used the following syntax in MySQL console to import the file:
mysql>c:/nitm.sql;
But this didn't work.
From the mysql console:
mysql> use DATABASE_NAME;
mysql> source path/to/file.sql;
make sure there is no slash before path if you are referring to a relative path... it took me a while to realize that! lol
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.
If you are using wamp you can try this. Just type use your_Database_name first.
Click your wamp server icon then look for MYSQL > MSQL Console then run it.
If you dont have password, just hit enter and type :
mysql> use database_name;
mysql> source location_of_your_file;
If you have password, you will promt to enter a password. Enter you password first then type:
mysql> use database_name;
mysql> source location_of_your_file;
location_of_your_file should look like C:\mydb.sql
so the commend is mysql>source C:\mydb.sql;
This kind of importing sql dump is very helpful for BIG SQL FILE.
I copied my file mydb.sq to directory C: .It should be capital C: in order to run
and that's it.
In windows, if the above suggestion gives you an error (file not found or unknown db) you may want to double the forward slashes:
In the mysql console:
mysql> use DATABASE_NAME;
mysql> source C://path//to//file.sql;
Ok so, I'm using Linux but I think this holds true for Windows too.
You can do this either directly from the command prompt
> mysql -u <user name> -p<password> <database name> < sqlfilename.sql
Or from within the mysql prompt, you can use:
mysql>source sqlfilename.sql
But both these approaches have their own benefits in the results they display.
In the first approach, the script exits as soon as it encounters an error. And the better part, is that it tells you the exact line number in the source file where the error occurred. However, it ONLY displays errors. If it didn't encounter any errors, the scripts displays NOTHING. Which can be a little unnerving. Because you're most often running a script with a whole pile of commands.
Now second approach (from within the mysql prompt) has the benefit that it displays a message for every different MySQL command in the script. If it encounters errors, it displays the mysql error message but continues on through the scripts. This can be good, because you can then go back and fix all the errors before you run the script again. The downside is that it does NOT display the line numbers in the script where the errors were encountered. This can be a bit of a pain. But the error messages are as descriptive so you could probably figure out where the problem is.
I, for one, prefer the directly-from-OS-command line approach.
If you are using xampp
C:\xampp\mysql\bin\mysql -uroot -p nitm < nitm.sql
You are almost there
use
mysql> \. c:/nitm.sql;
You may also access help by
mysql> \?
For localhost on XAMPP. Open a cmd window and type
cd C:\xampp\mysql\bin
mysql.exe -u root -p
Attention! No semi-colon after -p
Enter your password and type
use database_name;
to select the database you need.
Check if your table is there
show tables;
Import from your sql file
source sqlfile.sql;
I have put my file on C:\xampp\mysql\bin location in order to don't mix up with locations of sql file.
Try:
mysql -u username -p database_name < file.sql
Check MySQL Options.
Note: It is better to use the full path of the SQL file file.sql.
Don't forget to use
charset utf8
If your sql file is in utf-8 :)
So you need to do:
cmd.exe
mysql -u root
mysql> charset utf8
mysql> use mydbname
mysql> source C:\myfolder\myfile.sql
Good luck ))
In Linux I navigated to the directory containing the .sql file before starting mysql. The system cursor is now in the same location as the file and you won't need a path. Use source myData.sql where my date is replaced with the name of your file.
cd whatever directory
mysql - p
connect targetDB
source myData.sql
Done
from the command line (cmd.exe, not from within mysql shell) try something like:
type c:/nite.sql | mysql -uuser -ppassword dbname
Does your dump contain features that are not supported in your version of MySQL? You can also try to remove the starting (and ending) MySQL commented SET-statements.
I don't know if your dump comes from a Linux version of MySQL (line endings)?
I have installed my wamp server in D: drive so u have to go to the following path from ur command line->(and if u have installed ur wamp in c: drive then just replace the d: wtih c: here)
D:\>cd wamp
D:\wamp>cd bin
D:\wamp\bin>cd mysql
D:\wamp\bin\mysql>cd mysql5.5.8 (whatever ur verserion will be displayed here use keyboard Tab button)
D:\wamp\bin\mysql\mysql5.5.8>cd bin
D:\wamp\bin\mysql\mysql5.5.8\bin>mysql -u root -p password db_name < "d:\backupfile.sql"
here root is user of my phpmyadmin
password is the password for phpmyadmin so if u haven't set any password for root just nothing type at that place,
db_name is the database (for which database u r taking the backup)
,backupfile.sql is the file from which u want ur backup of ur database and u can also change the backup file location(d:\backupfile.sql) from to any other place on your computer
mysql>c:/nitm.sql;
That would write the output of the mysql command to 'nitm.sql;' (What's the ';' supposed to do?) Assuming you've got a copy of the original file (before you overwrote it) then:
mysql < c:/nitm.sql
Export Particular DataBases
djimi:> mysqldump --user=root --host=localhost --port=3306 --password=test -B CCR KIT >ccr_kit_local.sql
this will export CCR and KIT databases...
Import All Exported DB to Particular Mysql Instance (You have to be where your dump file is)
djimi:> mysql --user=root --host=localhost --port=3306 --password=test < ccr_kit_local.sql
In Windows OS the following commands works for me.
mysql>Use <DatabaseName>
mysql>SOURCE C:/data/ScriptFile.sql;
No single quotes or double quotes around file name. Path would contain '/' instead of '\'.
For those of you struggling with getting this done trying every possible answer you can find on SO. Here's what worked for me on a VPS running Windows 2012 R2 :
Place your sql file wherever the bin is for me it is located at C:\Program Files\MySQL\MySQL Server 8.0\bin
Open windows command prompt (cmd)
Run C:\Program Files\MySQL\MySQL Server 8.0\bin > mysql -u [username] -p
Enter your password
Run command use [database_name];
Import your file with command source C://Program Files//MySQL//MySQL Server 8.0//bin//mydatabasename.sql
It did it for me as everything else had failed. It might help you too.
I was given a MySQL database file that I need to restore as a database on my Windows Server 2008 machine.
I tried using MySQL Administrator, but I got the following error:
The selected file was generated by
mysqldump and cannot be restored by
this application.
How do I get this working?
If the database you want to restore doesn't already exist, you need to create it first.
On the command-line, if you're in the same directory that contains the dumped file, use these commands (with appropriate substitutions):
C:\> mysql -u root -p
mysql> create database mydb;
mysql> use mydb;
mysql> source db_backup.dump;
It should be as simple as running this:
mysql -u <user> -p < db_backup.dump
If the dump is of a single database you may have to add a line at the top of the file:
USE <database-name-here>;
If it was a dump of many databases, the use statements are already in there.
To run these commands, open up a command prompt (in Windows) and cd to the directory where the mysql.exe executable is (you may have to look around a bit for it, it'll depend on how you installed mysql, i.e. standalone or as part of a package like WAMP). Once you're in that directory, you should be able to just type the command as I have it above.
You simply need to run this:
mysql -p -u[user] [database] < db_backup.dump
If the dump contains multiple databases you should omit the database name:
mysql -p -u[user] < db_backup.dump
To run these commands, open up a command prompt (in Windows) and cd to the directory where the mysql.exe executable is (you may have to look around a bit for it, it'll depend on how you installed mysql, i.e. standalone or as part of a package like WAMP). Once you're in that directory, you should be able to just type the command.
mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
look here - step 3: this way you dont need the USE statement
When we make a dump file with mysqldump, what it contains is a big SQL script for recreating the databse contents. So we restore it by using starting up MySQL’s command-line client:
mysql -uroot -p
(where root is our admin user name for MySQL), and once connected to the database we need commands to create the database and read the file in to it:
create database new_db;
use new_db;
\. dumpfile.sql
Details will vary according to which options were used when creating the dump file.
Run the command to enter into the DB
# mysql -u root -p
Enter the password for the user Then Create a New DB
mysql> create database MynewDB;
mysql> exit
And make exit.Afetr that.Run this Command
# mysql -u root -p MynewDB < MynewDB.sql
Then enter into the db and type
mysql> show databases;
mysql> use MynewDB;
mysql> show tables;
mysql> exit
Thats it ........ Your dump will be restored from one DB to another DB
Or else there is an Alternate way for dump restore
# mysql -u root -p
Then enter into the db and type
mysql> create database MynewDB;
mysql> show databases;
mysql> use MynewDB;
mysql> source MynewDB.sql;
mysql> show tables;
mysql> exit
If you want to view the progress of the dump try this:
pv -i 1 -p -t -e /path/to/sql/dump | mysql -u USERNAME -p DATABASE_NAME
You'll of course need 'pv' installed. This command works only on *nix.
I got it to work following these steps…
Open MySQL Administrator and connect to server
Select "Catalogs" on the left
Right click in the lower-left box and choose "Create New Schema"
MySQL Administrator http://img204.imageshack.us/img204/7528/adminsx9.th.gif enlarge image
Name the new schema (example: "dbn")
MySQL New Schema http://img262.imageshack.us/img262/4374/newwa4.th.gif enlarge image
Open Windows Command Prompt (cmd)
Windows Command Prompt http://img206.imageshack.us/img206/941/startef7.th.gif enlarge image
Change directory to MySQL installation folder
Execute command:
mysql -u root -p dbn < C:\dbn_20080912.dump
…where "root" is the name of the user, "dbn" is the database name, and "C:\dbn_20080912.dump" is the path/filename of the mysqldump .dump file
MySQL dump restore command line http://img388.imageshack.us/img388/2489/cmdjx0.th.gif enlarge image
Enjoy!
As a specific example of a previous answer:
I needed to restore a backup so I could import/migrate it into SQL Server. I installed MySql only, but did not register it as a service or add it to my path as I don't have the need to keep it running.
I used windows explorer to put my dump file in C:\code\dump.sql. Then opened MySql from the start menu item. Created the DB, then ran the source command with the full path like so:
mysql> create database temp
mysql> use temp
mysql> source c:\code\dump.sql
You can try SQLyog 'Execute SQL script' tool to import sql/dump files.
Using a 200MB dump file created on Linux to restore on Windows w/ mysql 5.5 , I had more success with the
source file.sql
approach from the mysql prompt than with the
mysql < file.sql
approach on the command line, that caused some Error 2006 "server has gone away" (on windows)
Weirdly, the service created during (mysql) install refers to a my.ini file that did not exist. I copied the "large" example file to my.ini
which I already had modified with the advised increases.
My values are
[mysqld]
max_allowed_packet = 64M
interactive_timeout = 250
wait_timeout = 250
./mysql -u <username> -p <password> -h <host-name like localhost> <database-name> < db_dump-file
You cannot use the Restore menu in MySQL Admin if the backup / dump wasn't created from there. It's worth a shot though. If you choose to "ignore errors" with the checkbox for that, it will say it completed successfully, although it clearly exits with only a fraction of rows imported...this is with a dump, mind you.
One-liner command to restore the generated SQL from mysqldump
mysql -u <username> -p<password> -e "source <path to sql file>;"
Assuming you already have the blank database created, you can also restore a database from the command line like this:
mysql databasename < backup.sql
You can also use the restore menu in MySQL Administrator. You just have to open the back-up file, and then click the restore button.
If you are already inside mysql prompt and assume your dump file dump.sql, then we can also use command as below to restore the dump
mysql> \. dump.sql
If your dump size is larger set max_allowed_packet value to higher. Setting this value will help you to faster restoring of dump.
How to Restore MySQL Database with MySQLWorkbench
You can run the drop and create commands in a query tab.
Drop the Schema if it Currently Exists
DROP DATABASE `your_db_name`;
Create a New Schema
CREATE SCHEMA `your_db_name`;
Open Your Dump File
Click the Open an SQL script in a new query tab icon and choose your db dump file.
Then Click Run SQL Script...
It will then let you preview the first lines of the SQL dump script.
You will then choose the Default Schema Name
Next choose the Default Character Set utf8 is normally a safe bet, but you may be able to discern it from looking at the preview lines for something like character_set.
Click Run
Be patient for large DB restore scripts and watch as your drive space melts away! 🎉
Local mysql:
mysql -u root --password=YOUR_PASS --database=YOUR_DB < ./dump.sql
And if you use docker:
docker exec -i DOCKER_NAME mysql -u root --password=YOUR_PASS --database=YOUR_DB < ./dump.sql