tags:

views:

229

answers:

2

Hi ,

I am having real issues with a .db file its around 20gb in size with three tables and the rest data.

I am on a mac so i am having to use some crappy apps but it wont open in Access.

Does any one know what software will produce a .db file and what software will allow me to open it and export it as a CSV or MySQL file ?

Also if the connection was interrupted during transit could this effect the file ?

+2  A: 

Since mac is BSD-based now, try opening a terminal and executing the command file /path/to/large/db -- it should tell you at least what file type the DB is, and from there you can determine what program to use to open it. It might be MySQL, might be PostGreSQL, might be SQLite -- file will tell you.

Example:

$ file a.db
a.db: SQLite 3.x database

$ file ~/.kde/share/apps/amarok/mysqle/amarok/tracks.{frm,MYD,MYI}
~/.kde/share/apps/amarok/mysqle/amarok/tracks.frm: MySQL table definition file Version 10
~/.kde/share/apps/amarok/mysqle/amarok/tracks.MYD: data
~/.kde/share/apps/amarok/mysqle/amarok/tracks.MYI: MySQL MISAM compressed data file Version 1

So it's SQLite v3? Then try

sqlite3 /path/to/db

and you can perform pretty much standard SQL from the CLI. At the CLI, you can type .tables to list all the tables in that DB. -- Or if you prefer a GUI, there are a few options listed in this question. Accepted answer was SQLite manager for Firefox.

Then you could drop tables or delete as you see fit.

Here's an example of dumping a csv to stdout:

$ sqlite3 -separator ',' -list a.db "SELECT * FROM t"
3,4
3,5
100,200

And to store it to a file -- the > operator redirects output to a file you name:

$ sqlite3 -separator ',' -list a.db "SELECT * FROM t" > a.csv
$ cat a.csv # puts the contents of a.csv on stdout
3,4
3,5
100,200

-separator ',' indicates that fields should be delimited by a comma; -list means to put row data on the same line, using the delimiter; a.db indicates which db to use; and "SELECT * FROM t" is just the SQL command to execute.

Mark Rushakoff
Its a SQlite Version 3 , What is the best way to open a 20gb .db file on a mac ?I would not been to bothered if I had to cut it up 3 times for each table.
Oliver Bayes-Shelton
So how could I issue the command to copy the .db file to a CSV ?
Oliver Bayes-Shelton
Sorry to be a pain, I got this "Unknown-00-1f-5b-c7-49-5c:~ MacHome$ sqlite3 -separator ',' -list /Users/MacHome/Desktop/tpb/tpb.db "SELECT * FROM cat"100,Audio101,Audio > Music102,Audio > Audio books103,Audio > Sound clips104,Audio > FLAC199,Audio > OtherETC ETC"Does this mean it is complete if so were has it placed the CSV ?
Oliver Bayes-Shelton
That just wrote the csv to your console - see edited post for how to redirect to a file.
Mark Rushakoff
Do I have to wait for the first command to be processed then continue with "$ cat a.csv # puts the contents of a.csv on stdout3,43,5100,200" ?
Oliver Bayes-Shelton
No, the cat command just shows it to the terminal. You could open it with whatever program you want after it's been saved. Go do some research on using the terminal -- Google will have much information for you.
Mark Rushakoff
Mark , When I execute the last command you told me I am missing the headers of each table is there a reason for this ?
Oliver Bayes-Shelton
Pass the `-header` option on the command line to turn headers on. More info if you run `sqlite3 --help`.
Mark Rushakoff
Where would I put it in the following command "$ sqlite3 -separator ',' -list a.db "SELECT * FROM t" > a.csv"?
Oliver Bayes-Shelton
It should be `sqlite3 -header -separator ',' -list a.db "SELECT * FROM t" > a.csv`
Mark Rushakoff
A: 

I'm not a Mac user but if it's a SQLite file I've heard great things about Base.

Alix Axel
It crashed every time I try to use it do you think that might because I havent paid for it ?
Oliver Bayes-Shelton
No, lol. It's probably a memory overflow due to the big size of your database. Try searching for alternatives @ alternativeto.net
Alix Axel
Alix Axel
If I only wanted to make it a CSV so I can then shrink it and put it into MySQL could Terminal do it for me ? every piece of software seems to struggle and crashes
Oliver Bayes-Shelton
It most surely can, however I've never done it before and I suggest you google about it: http://www.google.com/search?q=dump+sqlite+to+csv
Alix Axel