how to import a database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amin3d
Forum Newbie
Posts: 5
Joined: Tue Oct 07, 2008 4:00 pm

how to import a database

Post by amin3d »

Hello every one.
These days i have faced to big problem . it is g database my database. My database type is mysql and it is so big. i want to know how can i import a database except using Phpmyadmin and things that i must say about my condition are my database is on myftp and the extension of it is .gz and my server is Linux and dont access to shell to use its command for importing database.
Thanks
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: how to import a database

Post by onion2k »

You need shell access, or you need to get someone who has shell access to do it for you. Running a large scale SQL dump through a browser is a bit impractical.

Or, alternatively, you could break the SQL file up into smaller chunks.. they are just text files really so you split them into smaller bits and run them one by one. Though that really depends how big it is.. if your database is gigabytes in size that's still a bit impractical.
amin3d
Forum Newbie
Posts: 5
Joined: Tue Oct 07, 2008 4:00 pm

Re: how to import a database

Post by amin3d »

Thanks for reply .Could you tell me how to split my database in small part and say me after splitting how to import with phpmyadmin?
Thanks
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: how to import a database

Post by onion2k »

No.

I could easily, but there was less than 10 minutes between my post and your reply, so you clearly haven't bothered to think about it at all. If you aren't going to put any effort into finding a solution to your problem then I see no reason why I should.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: how to import a database

Post by VladSun »

A little hack to gain sheell-like access ;)

Create a php file in your web root directory:

Code: Select all

<?php
echo system("gunzip /full/path/to/database_backup.gz -c | `which mysql` -u YOUR_DB_USERNAME -pYOUR_DB_PASSWORD DATABSE_NAME 2>&1");
?>
and by using your www browser browse it ONCE.
If there are any errors they will be displayed in your browser - fix'em and retry.

After finishing the import - remove this file.

PS: Please, notice there is NO white space between -p and YOUR_DB_PASSWORD - this is how it SHOULD be.
There are 10 types of people in this world, those who understand binary and those who don't
amin3d
Forum Newbie
Posts: 5
Joined: Tue Oct 07, 2008 4:00 pm

Re: how to import a database

Post by amin3d »

it was a great help. now let me know how to import it with specific charachter encoding such as utf-8 or the same as that.
Regardes
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: how to import a database

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
amin3d
Forum Newbie
Posts: 5
Joined: Tue Oct 07, 2008 4:00 pm

Re: how to import a database

Post by amin3d »

thanks for above link. here is a problem i dont know how to add or set Default Character Set and Collation in that command .For example add utf-8 and utf8_unicode_ci collation.
Please help me.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: how to import a database

Post by VladSun »

Read the man-page ;)
o --default-character-set=charset_name

Use charset_name as the default character set. See Section 8.1, "The
Character Set Used for Data and Sorting".
There are 10 types of people in this world, those who understand binary and those who don't
amin3d
Forum Newbie
Posts: 5
Joined: Tue Oct 07, 2008 4:00 pm

Re: how to import a database

Post by amin3d »

I've read it. But my problem is how to use them . because i've got some errors like below.
/usr/bin/mysql: unknown option '-d' /usr/bin/mysql: unknown option '-d'
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: how to import a database

Post by VladSun »

I know -D, not -d ...
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply