Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to best display in Terminal a MySQL SELECT returning too many fields?

I'm using PuTTY to run:

mysql> SELECT * FROM sometable; 

sometable has many fields and this results in many columns trying to be displayed in the terminal. The fields wrap onto the next line so it is very hard to line up column titles with field values.

What solutions are there for viewing such data in terminal?

I don't have nor want access to phpMyAdmin - or any other GUI interfaces. I'm looking for command-line solutions such as this one: Save MySQL Query results into text or CVS file

like image 405
Chris Jacob Avatar asked May 29 '09 06:05

Chris Jacob


People also ask

How will you limit a MySQL query to display only top 10 rows?

To select first 10 elements from a database using SQL ORDER BY clause with LIMIT 10. Insert some records in the table using insert command. Display all records from the table using select statement. Here is the alternate query to select first 10 elements.

How do I limit rows in MySQL select?

In MySQL the LIMIT clause is used with the SELECT statement to restrict the number of rows in the result set. The Limit Clause accepts one or two arguments which are offset and count. The value of both the parameters can be zero or positive integers.

How do I select multiple records in MySQL?

To select multiple values, you can use where clause with OR and IN operator.

How do I select multiple columns in MySQL?

To select multiple columns from a table, simply separate the column names with commas! For example, this query selects two columns, name and birthdate , from the people table: SELECT name, birthdate FROM people; Sometimes, you may want to select all columns from a table.


1 Answers

Terminate the query with \G in place of ;. For example:

SELECT * FROM sometable\G 

This query displays the rows vertically, like this:

*************************** 1. row ***************************                  Host: localhost                    Db: mydatabase1                  User: myuser1           Select_priv: Y           Insert_priv: Y           Update_priv: Y           ... *************************** 2. row ***************************                  Host: localhost                    Db: mydatabase2                  User: myuser2           Select_priv: Y           Insert_priv: Y           Update_priv: Y           ... 
like image 104
Rytmis Avatar answered Oct 22 '22 20:10

Rytmis