backing up SQL database

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
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

backing up SQL database

Post by psychotomus »

Anyone got any simple code that will back up a SQL database. I could do it myself. First I would need to know how to get all the TABLES from the database with all of there fields. I can then grab all the contents from the table by myself with a select statement.

So how can I grab all the tables from a database and there fields?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Do you have access to the command line? If so you can use mysqldump to get a dump file.

If not, do you have phpmyadmin? That can make a dump file too.

If you have none of that, you will, of course, have to do it manually. The first step would be to call a query "show tables". Then, loop through each table calling a query "SHOW CREATE TABLE [table name]" That will output the query needed to recreate [table name]. You can then go through and read in each row into a CSV.

Do try to find a way to make/get a mysqldump file - it's much much much easier.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

this topic has been talked about a lot.. some recently..

Moving to Databases
Post Reply