Restoring a mysqldump

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Restoring a mysqldump

Post by hawleyjr »

I'm using the following code to backup my db: (works fine)

Code: Select all

$_dir = dirname($_SERVER['DOCUMENT_ROOT']).'/dbbkup/';

exec('mysqldump --add-drop-table --all --complete-insert -h localhost -u USER_NAME -pPASSWORD DATABASE_NAME > ' . $_dir . date('Y_m_d_His').'.sql');

I'm not trying to restore the db using: (not working properly)

Code: Select all

$fileName = '2005_03_30_135901.sql';

$fileName = dirname($_SERVER['DOCUMENT_ROOT']) . '/dbbkup/'.$fileName;

if(is_file($fileName))/* validate correct file */
	echo 'is a file<BR>'.$fileName;
else
	echo 'is not a file<BR>'.$fileName;
	
	exec('mysql -h localhost -u USER_NAME -pPASSWORD -D DATABASE_NAME < ' . $fileName);
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

hawleyjr wrote:I'm not trying to restore the db using: (not working properly)
If you aren't trying, then why is it giving error... :lol:

Seriously now, does the command you are exec'ing runs properly when you run it via cmdline...:?:
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

n00b Saibot wrote:
hawleyjr wrote:I'm not trying to restore the db using: (not working properly)
If you aren't trying, then why is it giving error... :lol:
lol, that's awesome...

I don't have access to the cmdline. I'm pretty much shooting in the dark.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

you sure the file is in correct path and that you have priviledges to run the mysql command because command looks pretty good to me. perplexing thing, this. :?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

yeah, thats why I put the is_file() function in there. I'll mess around with it more.

thanks.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

question (cuz i'm confused :? ), but are you trying to copy that file to a new directory or restore it back into mysql?...
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

I'm trying to restore the database.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

then all ya need to do is :

Code: Select all

`mysql -u username -p password databasename < file.sql;
make sure you have created the database name beforehand though...and also make sure you have the sql file in the correct location. otherwise you are gonna have to define the actual directory in which it resides.
Post Reply