How to print out MySQL table structure and content in text format on Mac OS X

Which MySQL editor could show my database table in the following kind of format? I'd also need to display the content in this kind of text format.

 
+-------------+---------------------+------+-----+---------+----------------+
| Field       | Type                | Null | Key | Default | Extra          |
+-------------+---------------------+------+-----+---------+----------------+
| product_id  | int(10) unsigned    | NO   | PRI | NULL    | auto_increment |
| url         | varchar(100)        | NO   | UNI | NULL    |                |
| name        | varchar(50)         | NO   |     | NULL    |                |
| description | varchar(255)        | NO   |     | NULL    |                |
| price       | decimal(10,2)       | NO   |     | NULL    |                |
| visible     | tinyint(1) unsigned | NO   | MUL | 1       |                |
+-------------+---------------------+------+-----+---------+----------------+

Open in new window

leppis75Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun McNicholasSenior Marketing TechnologistCommented:
I use the oracle SQL Developer - it's free you just have to register on the oracle site in order to download it. The registration is free and the tool is free and let's you manage just about everything regarding databases, and is extensible for just about every available database.

Here's a screen grab of the tool's view of a table structure. it's very similar to using Microsoft's Management Studio.

In my configuration I am connected to four different local Microsoft DBs - one web based MS SQL instance and 2 MySql instances - all different versions and locations and can work on all of them at the same time...

Takes a while to figure out how to configure everything but not terribly difficult the learn.
Screen-shot-2010-08-18-at-3.12.2.png
0
leppis75Author Commented:
Thanks for the tip, but can I get it to print the tables out in that kind of text table format, that I'd pasted in my question? The reason why I'm asking is, that I'd like to, after finding the right tool, open another question, where I would copy-paste content from couple of tables in my database.
0
Shaun McNicholasSenior Marketing TechnologistCommented:
in most databases and in any tool with query capability just use this


sp_help tablename

In most tools where you can print the information shown on the screen you can just print this out
0
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

Shaun McNicholasSenior Marketing TechnologistCommented:
If that doesn't work try this as a query - some tools won't output the actual table structure
This returns a text output that you can print...

select * from information_schema.columns where table_name='tablename'
0
Shaun McNicholasSenior Marketing TechnologistCommented:
Sorry for so many comments - I just like to check my advice and I'm discovering options while I look at your issue.
In the Oracle SQL Developer - I just use this query - select * from information_schema.columns where table_name='tablename'
Then in the results pane I right click on the resulting table and I can export the results in about ten different formats including html, xls, csv, text etc... So it should do what you're looking for.

0
leppis75Author Commented:
No, I'm sorry, but I don't think any of this is what I'm looking for. I think, that if I could make the query in my Terminal, I'd get the result I want...

I think I'll give up and just take screenshots of what I need to show. Thanks for trying to help.
0
seenallCommented:
Basic mechanism without PERL - use sed

1) Create a single shell script as follows (e.g. /usr/local/bin/tab2csv.sed")

s/\t/","/g;s/^/"/;s/$/"/;s/\n//g

Don't worry too much about what this is / is not doing until you really want to learn sed

2) now create a variable in your .bashrc file

TAB2CSVSED="sed -f /usr/local/bin/sedtab2csv.sed"

create a sql script (e.g. /home/me/sqlscrs/mytabint.sql)

select table_name, column_name, data_type -- etc
from information_schema.columns
where table_schema = 'mydbuser'
and table_name = 'mytableofinterest';


4) cd /home/me/sqlscrs/ # making life easier

Now - when you run a mysql command line - pipe the output to this simple edit (sed) command
create a SQL Script and catch the output to a file

e.g.
/usr/bin/mysql -u mydbuser -P3306 -h 127.0.0.1 -pmypass -D mydb -A -e "source mytabint.sql" | ${TAB2CSVSED} > mytabdet.csv

cat mytabdet.csv

With the CSV file you can grab what ever you want via a text editor or excel

Mac - being Darwin UNIX - opens up more flexibility if the Shell commands are used

Best
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
seenallCommented:
Hello leppis75

I am really pleased you managed to get this working.  Automation makes life a little easier

All the best
seenall
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.