How to color the MySQL / MariaDB console

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

  1. 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
  2. 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

colors to mysql console

color mysql console

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.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Gilberto said

    what a good tip!

  2.   Alex said

    It works! Spectacular!
    Thank you!

  3.   WALEX said

    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?