40

Is there a way to set a color scheme for the mysql client? It might sound trivial, but I'd like to be able to set some level of colors for terminal client.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Cory Collier
  • 883
  • 1
  • 10
  • 20
  • 2
    What terminal are you using? Or are you using Windows cmd.exe? This isn't really a mysql question. – Nick Dixon Dec 21 '09 at 14:20
  • 1
    I'm using a Mac, regular Terminal. Though I could be using any terminal really. My thought was that maybe there was something like a .vimrc file for the mysql client. So, yeah it is a mysql question ;) – Cory Collier Dec 21 '09 at 14:38
  • Did you give any of these options a try? Did any of them work for you? – Matt Curtis May 14 '10 at 07:14
  • 1
    It is a MySQL question. I just wondered about this too. I'm tired of the monochrome output of the MySQL client. It would be so much better in colours. Thought I'd check here first, the command line MySQL client doesn't have a color output option it seems. –  Nov 22 '10 at 11:15
  • 1
    fwiw, color is quite the opposite of trivial, especially if (like me) you've got a couple of 4k monitors on your desk and you need to visually process a lot of info that's coming at you all at once. – Jeff May 29 '18 at 07:11

9 Answers9

58

I've spent much time trying to solve that question. It took me nearly a year to solve it :) There is nice option in mysql config called "pager".

I've just published my configs for mysql client and grc (availiable in most nix dists). Check it out on github! https://github.com/nitso/colour-mysql-console

enter image description here

Ostin
  • 1,511
  • 1
  • 12
  • 25
  • 3
    awesome! works a treat on osx (just `brew install grc` first). this makes me very happy :) – Darragh Enright Jan 23 '13 at 16:31
  • I followed the installation manual, but I did not find config files. "Copy both config files into your home directory" – Houssem ZITOUN Aug 19 '16 at 09:00
  • @HoussemZitoun config files are: [.my.cnf](https://github.com/nitso/colour-mysql-console/blob/master/.my.cnf) and [.grcat](https://github.com/nitso/colour-mysql-console/blob/master/.grcat) – Ostin Aug 19 '16 at 09:48
12

Here is pretty much awesome tool https://github.com/dbcli/mycli

Besides syntax highlight it offers completion.

enter image description here

n1_
  • 4,227
  • 4
  • 34
  • 35
4

You could use rlwrap if you just want a colour prompt:

% rlwrap --prompt-colour='1;34' mysql

Note: contrary to convention, rlwrap spells colour with a U.

If you want everything in colour, check out acoc - Arbitrary Command Output Colourer. Not sure if it works with interactive programs, you might need to extend it or write your own.

Matt Curtis
  • 23,168
  • 8
  • 60
  • 63
  • "color" is just the American way to spell it. – Neil Jul 07 '10 at 16:00
  • It seems you have to do: `rlwrap -a -p'RED' mysql` to get it working properly. Without the -a the prompt doesn't get coloured. – Neil Jul 07 '10 at 17:31
  • 3
    @Neil: Sure, "colour" is how Australians spell it when writing, but most developers use "color" by convention for things like this because it avoids all sorts of unnecessary confusion. – Matt Curtis Jul 13 '10 at 00:17
  • IMHO you should lead with the acoc answer (which is why I upvoted you). Additionally, the link to rlwrap seems to be timing out. – Jeff May 29 '18 at 06:56
  • @Jeff thanks for the tip. rlwrap is easier to find on different platforms than acoc. It gets the silver medal though, that’s pretty good right? – Matt Curtis Jun 19 '18 at 13:36
1

Recently I have started to use the MySQL client inside an independent vim session with conque. You get syntax highlighting and some other extra features from Vim, like nowrap, search, horizontal scrolling, etc.

With :set wrap:

enter image description here

With :set nowrap:

enter image description here

If you like Vim I would give it a go:

  1. Install conque.
  2. Create a new .vimsql (I like a different vimrc for this).
  3. Tune it to start conque and mysql by default.
  4. Tune it to have some good key mappings for mysql.
  5. alias mysqlcool="vim -u ~/.vimsql" (or whatever :))

You can have a look at the vimrc I'm using.

DavidEG
  • 5,857
  • 3
  • 29
  • 44
0

Mysql text client is really basic, if you need something more advanced, you could try MySQL Query Browser, which is a GUI client.

0

Look up the program GRC on MacPorts.

I'm currently working on getting it running to colorize all of my terminal output. It uses regex to parse everything, so it really comes down to how much regex do you feel like writing.

Brandon
  • 1,956
  • 18
  • 18
0

For colorizing everything you need nothing but a simple echo.
Since mysql has:

system    (\!) Execute a system shell command.

you can easily:

mysql_colorize_prompt_1

But if you want only the prompt be in color use rlwrap

mysql_colorize_prompt_2

And if you want to colorize the result of command you can use grc
It is a script that I think read the underline stdout, stderr and then colorize it. You can configure it. And since it uses to match the result, in configure file you should write regex

here is some screen-shot


More detail about ANSI color:

How to change the output color of echo in Linux

Shakiba Moshiri
  • 21,040
  • 2
  • 34
  • 44
0

Add this to your ~/.profile [or ~/.bashrc]

export MYSQL_PS1="$(echo -e '\033[1;32mmysql \d> \033[0m')"
bluszcz
  • 4,054
  • 4
  • 33
  • 52
Steve
  • 1
  • 1
-2

You should set color scheme for your terminal emulator or console window.

  • ehh, I already have a color scheme setup for my terminal. I'm looking for stuff specific to Mysql. For example, if every other row was a diff color, or if the prompt was a diff color, or the headers were a diff color. See where I'm driving here? – Cory Collier Dec 21 '09 at 14:45