How to Clear the Screen in MySQL
The main aim of this topic is to demonstrate how to clear the screen of the MySQL console.
Clear the Screen in MySQL
While working on the MySQL console and managing configurations and data, the screen may get too cluttered with the results of previous operations. Cluttering may lead to a messy display which can affect the visualization of future queries as the cluttered display may lead to confusion in navigating through the output.
Consider the following scenario:
C:\Users\Admin>mysql --user=root --password=root
MySQL: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.30 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SELECT * from world.city;
+------+---------------+-------------+----------------------+------------+
| ID | Name | CountryCode | District | Population |
+------+---------------+-------------+----------------------+------------+
| 1 | Kabul | AFG | Kabol | 1780000 |
| 2 | Qandahar | AFG | Qandahar | 237500 |
| 3 | Herat | AFG | Herat | 186800 |
| 4 | Mazar-e-Sharif| AFG | Balkh | 127800 |
| 5 | Amsterdam | NLD | Noord-Holland | 731200 |
| . | . . . . . . . | . . . . . . | . . . . . . . . . . | . . . . . |
| . | . . . . . . . | . . . < OUTPUT REDACTED > . . . | . . . . . |
| . | . . . . . . . | . . . . . . | . . . . . . . . . . | . . . . . |
| 4078 | Nablus | PSE | Nablus | 100231 |
| 4079 | Rafah | PSE | Rafah | 92020 |
+------+---------------+-------------+----------------------+------------+
4079 rows in set (0.07 sec)
mysql>
After executing such a large query, going back up to check on something becomes annoying, especially when looking for a particular result in the middle of the output. It can become difficult to find it amidst all the output.
To overcome this issue, we can clear our screen as we progress to prevent cluttering our screen.
We can clear the MySQL console in plenty of ways, some of which are as follows:
Clear the MySQL Console Using System
Depending on the operating system, the system
followed by the cmdlet used to clear the screen can be used to clear the MySQL console.
Following are examples for both Linux, Mac, and Windows:
Clear the MySQL Console in Linux
You can easily clear the screen on Linux using clear
or reset
.
# Only scrolls down
mysql> system clear
# For clearing both the history and scrollback history
mysql> system reset
Using system clear
, the shell only scrolls down, keeping the old results intact. If we need to remove the scroll, use system reset
.
Clear the MySQL Console in Windows
Similarly, for Windows:
mysql> system cls
Instead of writing system
, we can also use its shortcut \!
.
### Linux
mysql> \! clear
mysql> \! reset
### Windows
mysql> \! cls
Clear the MySQL Console in macOS
On a macOS, you can do the following:
Go to Edit
, click Clear Screen
or use the keyboard shortcut ⌥+Cmd+L.
Clear the MySQL Console in iTerm2
The settings are a bit renamed in iTerm. Instead of Clear Screen
, Clear Buffer
is used.
More specifically, go to Edit
, click Clear Buffer
, or use the keyboard shortcut Cmd+K.
Hello! I am Salman Bin Mehmood(Baum), a software developer and I help organizations, address complex problems. My expertise lies within back-end, data science and machine learning. I am a lifelong learner, currently working on metaverse, and enrolled in a course building an AI application with python. I love solving problems and developing bug-free software for people. I write content related to python and hot Technologies.
LinkedIn