Bee
Bee

Reputation: 104

mysql database restoring in JAVA

I can find some commands through which I can restore a table or some tables from backup sql to database.

But If I want to create the full databse from back up sql what will be the procedure?

Please note that the database do not exist in server. I need to create it from the back up files.

Upvotes: 2

Views: 118

Answers (1)

Drew
Drew

Reputation: 24959

I will give you an example from Mysql Workbench, a free download from Oracle/Mysql.

You go into Management / Data Export from the upper left window pane. Select the database. Decide what you want to export, such as Data and Structure, Stored Procedures, Views, etc.

You can export to individual .sql files for each table, or glom them all together compressed. So now you have one or more .sql files.

Alter the top of the .sql that says

`CREATE DATABASE  IF NOT EXISTS `myDbName` ... ;
USE `myDbName`;

Those are lines 1 and 2

Change those to what your new DB name is going to be.

Save .sql file. If more than one .sql file, do the same to all of them.

run those scripts against a server with adequate privileges. For instance, hypothetically, let's say you have a user such as dbAdminUser that came to life with a call like this:

CREATE USER 'dbAdminUser'@'localhost' IDENTIFIED BY 'myPassword';
CREATE USER 'dbAdminUser'@'127.0.0.1' IDENTIFIED BY 'myPassword';
CREATE USER 'dbAdminUser'@'%' IDENTIFIED BY 'myPassword';

GRANT ALL ON *.* TO 'dbAdminUser'@'localhost';
GRANT ALL ON *.* TO 'dbAdminUser'@'127.0.0.1';
GRANT ALL ON *.* TO 'dbAdminUser'@'%';

I see success in the making with the above approach, using dbAdminUser.

Upvotes: 1

Related Questions