- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Execute MySQL query from the terminal without printing results?
Let us first create a table −
mysql> create table DemoTable709 (Amount int); Query OK, 0 rows affected (0.62 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable709 values(100); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable709 values(560); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable709 values(7800); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable709 values(1020); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable709;
This will produce the following output -
+--------+ | Amount | +--------+ | 100 | | 560 | | 7800 | | 1020 | +--------+ 4 rows in set (0.00 sec)
Following is the query to execute MySQL query from the terminal without printing results −
mysql> set @TotalAmount=(select sum(Amount) from DemoTable709); Query OK, 0 rows affected (0.00 sec)
If you want to see the result, you can use below query −
mysql> select @TotalAmount;
This will produce the following output -
+--------------+ | @TotalAmount | +--------------+ | 9480 | +--------------+ 1 row in set (0.05 sec)
- Related Articles
- Populating a table from query results in MySQL?
- Order MySQL results without identifier?
- How can I check how much time MySQL query, without printing it on the console, is taking?
- Run SQL file in MySQL database from terminal?
- How to concatenate MySQL distinct query results into a string?
- Query results that have less than X characters in MySQL?
- How to chunk results from a custom query in Laravel?
- How can you execute functions with multiple arguments at a terminal?
- MySQL query to group results by date and display the count of duplicate values?
- Add results from several COUNT queries in MySQL?
- Django query count in terminal for debugging
- How can I enable MySQL slow query log without restarting MySQL?
- Can we return query results in same order as the values in MySQL `IN(…)` statement?
- Select results from the middle of a sorted list in MySQL?
- Get a fixed number of results in descending order using a MySQL query

Advertisements