LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 04: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, 05:18 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
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, 05: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, 05:50 PM   #4
Doug G
Member
 
Registered: Jul 2013
Posts: 749

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, 07:02 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
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 07:12 PM. Reason: Sentence structure, additional comments, typos
 
Old 08-04-2015, 07: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, 11:18 AM   #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



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 06:40 AM
sql how to enter .mode column from command line donnied Programming 1 03-03-2009 07:05 PM
Email Client in Linux using command line only preddibear Linux - Newbie 5 10-01-2006 01:17 PM
PostgreSQL: executing a .SQL file from command line? J_Szucs Linux - Software 0 09-24-2003 11:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:20 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
Open Source Consulting | Domain Registration