If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > how to read sql file in excel format ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-03-12, 23:17
pooja2010 pooja2010 is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
how to read sql file in excel format ?

Hello all,

I have an sql file, but I want to read it in the form of an excel sheet. Do you have any suggestions, how can i convert sql into excel or any such readable format ? Or are there any free tools which does the same ?

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 01-04-12, 03:21
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
what does "read it in the form of an excel sheet" mean?

can we see the first few lines of the sql file please
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-04-12, 07:03
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
I think the easiest way of reading in some type of tabular form would be to apply the SQL file into a database and then using "mysql --html" run a select statement against this. The result of this is your data in HTML table format which can be viewed with a browser. You can then even from the browser copy the table and apply it into an Excel spreadsheet.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #4 (permalink)  
Old 01-04-12, 07:40
pooja2010 pooja2010 is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
I thank you both for your reply..

I am totally new to databases.
I actually have a dump sql file (filename.sql) with me, which I am trying to import it in mysql database. I have found the following command for it.

mysql < filename.sql

The goal is, after importing, i would be able to see the tables and I somehow want it all in the form of excel sheet or csv format. And so, as Ronan suggested, I would then try using "mysql --html" and run the select statements (i still need to try and figure out after that, how it works though).

But for now, the above command to import the dump file shows me an error all the time. It says I need to check the syntax with every version of the mysql. I am using 5.5.19.0, and refering to its manual as well and the above command is as per that. I still dont understand why do I get errors. Or sometimes it says, "database file not found".
Or am i missing something?

I apologize if this seems to be a very small and silly query? But i am just stuck with it.
Reply With Quote
  #5 (permalink)  
Old 01-04-12, 07:48
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
What happens if you type in mysql by itself? Do you still get the error message? If yes can you copy and paste in here so we can take a look?
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #6 (permalink)  
Old 01-04-12, 09:07
pooja2010 pooja2010 is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
If I type only "mysql", it still gives me the same message, with the following error:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql' at line 1
Reply With Quote
  #7 (permalink)  
Old 01-04-12, 09:31
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
Are you sure that your mysql server is running? If it is then it sounds like you have some SQL that is automatically executed when you run the mysql command. This is usually configured in your local copy of my.cnf.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #8 (permalink)  
Old 01-04-12, 09:46
pooja2010 pooja2010 is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
It is running, because I am able to run other normal commands like SHOW, CREATE, SELECT, etc. I also just checked with another laptop, with the same version of mySQL. But it shows me the same error when I type "mysql" or "mysql < filename.sql"

Could you may be tell me how can I solve or configure this ? I would try it out then.
Reply With Quote
  #9 (permalink)  
Old 01-04-12, 10:15
TonyF123 TonyF123 is offline
Registered User
 
Join Date: May 2008
Posts: 17
looks like your at the mysql prompt already so try

source filename.sql
Reply With Quote
  #10 (permalink)  
Old 01-04-12, 11:00
pooja2010 pooja2010 is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
It works with this finally.. I thank you so much.. It was just a very long file.

And now, just last thing i would again bother you with..
I want to get it in a file in the form of tables or the excal sheet as I said (xls or csv), so that it gets easy to read.
I guess i need to write select statements for each table and put one by one in a file ? And If yes, could you only tell me the command to put them all in a file.
Reply With Quote
  #11 (permalink)  
Old 01-04-12, 11:40
TonyF123 TonyF123 is offline
Registered User
 
Join Date: May 2008
Posts: 17
SELECT
field1
,field2
,field3
FROM
table_name
INTO OUTFILE 'out.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'


Replacing field1, field2 etc., with the field names in your table and table_name with the name of your table.
Reply With Quote
  #12 (permalink)  
Old 01-04-12, 23:43
pooja2010 pooja2010 is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
Thanks a lot again.. i get it now..
Reply With Quote
  #13 (permalink)  
Old 01-05-12, 00:59
pooja2010 pooja2010 is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
I thought I would figure out this thing by myself and also tried different commands for it. But again I think it would be best to ask you, when I couldn't find.

The command which you gave surely works for every individual table. But I have a list of around 90 tables in my database. Is there a way to extract all of them at once in the csv file ?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On