In this tutorial we will learn to How to color the MySQL / MariaDB console according to the configuration you want, highlighting by data type and others. For this we are going to share a default configuration and the steps to make it run.
How does MySQL / MariaDB console coloring work?
The Mysql client supports the use of predefined locator for data output. So we can configure grcat (Generic Colouriser) to process mysql output. Grcat reads the supplied configuration file, parses the output according to regexp, and adds colors. The grc manual can be viewed with the command man grc
o here.
How to color MySQL / MariaDB console?
To color the MySQL or MariaDB console we must follow the following steps:
Install MySQL or MariaDB
Obviously having MySQL or MariaDB installed.
Install grc
Grc is a tool that allows us to color our output files. (We can install it on Debian and Derivatives with: $ sudo apt-get install grc
).
Create .grcat files and .my.cnf
- Create a file .grcat in our home directory that will allow us to place the configuration of the colors that we want to show:
$ cd ~ $ gedit .grcat
In the created file we must place the following code:
#Default color for words #regexp = [\ w., \: \ -_ /] + regexp =. + Colors = green - #Color of table borders regexp = [+ \ -] + [+ \ - ] | [|] colors = red - #data between () and '' regexp = \ ([\ w \ d, '] + \) colors = white - # numeric regexp = \ s [\ d \.] + \ s * ($ | (? = \ |)) colors = yellow - #date regexp = \ d {4} - \ d {2} - \ d {2} colors = cyan - #time regexp = \ d {2} : \ d {2}: \ d {2} colors = cyan - #IP regexp = (\ d {1,3} \.) {3} \ d {1,3} (: \ d {1,5} )? colors = cyan - #schema regexp = `\ w +` colors = yellow - #email regexp = [\ w \. \ -_] + @ [\ w \. \ -_] + colors = magenta - #Row delimiter when \ G regexp = [*] +. + [*] + count = stop colors = white - #Column names when \ G regexp = ^ \ s * \ w +: colors = white is used
- Create a file .my.cnf in our home directory:
$ cd ~ $ gedit .my.cnf
In the created file we must place the following code:
[mysql] pager = grcat ~ / .grcat
Run our MySQL / MariaDB client
mysql -u <user> -p -h <hostname>
Start enjoying
A little trick that will give life to our Mysql / MariaDB console and that can be configured to your liking, I cannot miss the opportunity to thank Alexei Kalinin for your interesting information.
what a good tip!
It works! Spectacular!
Thank you!
Hola!
First of all Thank you !!
It works perfect, I did not know the grc command
One question and forgive the daring, this could also be done for the output of the console commands in general? for example the ls?