LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-03-2015, 05:40 PM   #1
schedar
LQ Newbie
 
Registered: Apr 2015
Location: Poland
Distribution: Centos 7
Posts: 16

Rep: Reputation: Disabled
Linux command line SQL client


Hi,

I was just wondering if there is any tool or a way to display tables in Linux console so that they are not messed up like this:

MariaDB [test]> select * from tabeleczka;
+------+------------+---------------+-----------------+--------------------
---------------------+
| lp | name | surname | age | jklvgjkdrlxhgxkldgh
xkldgjkklgdxjfgkldfg |
+------+------------+---------------+-----------------+--------------------
---------------------+
| 1 | bozydarnik | jkojglsjgsdjg | stopiecdziesiat | fjaklsegjsklghsdkjg
haskjghasdgasg |
+------+------------+---------------+-----------------+--------------------
---------------------+




i would like to achieve something that actually looks like a table. Is it possible?
 
Old 08-03-2015, 06:18 PM   #2
Habitual
LQ Addict
 
Registered: Jan 2011
Posts: 7,685
Blog Entries: 10

Rep: Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080
Sure, don't use it from the mysql > prompt and issue something similar to
Code:
mysql -u<user> -p -e "select * from <dbname>.tabeleczka;"
 
Old 08-03-2015, 06:30 PM   #3
schedar
LQ Newbie
 
Registered: Apr 2015
Location: Poland
Distribution: Centos 7
Posts: 16

Original Poster
Rep: Reputation: Disabled
Hey, I've got the same result by invoking the command from shell directly.
 
Old 08-03-2015, 06:50 PM   #4
Doug G
Member
 
Registered: Jul 2013
Posts: 658

Rep: Reputation: Disabled
It looks funky because the lines wrap. Try using the \G switch which causes each column to be on it's own line.

I don't know if there is a switch in mysql to stop line breaks, although I imagine it's your linux terminal that's wrapping the lines.
 
Old 08-03-2015, 08:02 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,032
Blog Entries: 1

Rep: Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118Reputation: 2118
You are displaying a ~114 character width table in an 80 character wide terminal... something has to wrap!

You could run the query from a shell as Habitual says then pipe it through a formatting script of your own making, or turn the corner with \G per Doug G, to get some desired formatting. Alternatively, you could write a script to fetch and iterate the result and write it in formatting of your choice.

But MySQL/MariaDB is all about the data, you have to structure the query itself to return the data formatted or pipe it through a formatting filter.

Last edited by astrogeek; 08-03-2015 at 08:12 PM. Reason: Sentence structure, additional comments, typos
 
Old 08-04-2015, 08:34 AM   #6
wesaus32
LQ Newbie
 
Registered: Jul 2015
Location: Michigan, USA
Distribution: Ubuntu Mate, Debian 8.0, LFS 7.7
Posts: 20

Rep: Reputation: Disabled
Is it possible to output that to a file and read it from there or would that be counter-intuitive??
 
Old 08-04-2015, 12:18 PM   #7
schedar
LQ Newbie
 
Registered: Apr 2015
Location: Poland
Distribution: Centos 7
Posts: 16

Original Poster
Rep: Reputation: Disabled
To the file, nice.
Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: What is a good command-line IRC client on Linux LXer Syndicated Linux News 0 01-28-2015 07:40 AM
sql how to enter .mode column from command line donnied Programming 1 03-03-2009 08:05 PM
Email Client in Linux using command line only preddibear Linux - Newbie 5 10-01-2006 02:17 PM
PostgreSQL: executing a .SQL file from command line? J_Szucs Linux - Software 0 09-25-2003 12:49 AM


All times are GMT -5. The time now is 07:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration