0

I need to extract the mysql version in a bash script on CentOS 6 for a minimum requirements check

Example:

# mysql -V
mysql  Ver 14.14 Distrib 5.5.43, for Linux (x86_64) using readline 5.1
# mysql -V 
mysql  Ver 14.14 Distrib 5.6.24, for Linux (x86_64) using  EditLine wrapper

Should I use something like mysql -V| grep ...?

Hyppy
  • 15,608
  • 1
  • 38
  • 59
vasek
  • 13
  • 1
  • 1
  • 3

2 Answers2

3

For the above two examples, if you want the "14.14" string:

mysql -V | awk '{print $3}'

If want the "5.x.x" string:

mysql -V | awk '{print $5}'

I can't guarantee that the strings will be in the same format across major versions, though. Also, this could probably also be performed with sed and some clever regexing.

If you want a check against installed RPMs, then you could go with:

rpm -qi mysql | grep Version | awk '{print $3}'
Hyppy
  • 15,608
  • 1
  • 38
  • 59
  • # rpm -qi mysql package mysql is not installed but # mysql -V|awk '{ print $5 }'|awk -F\, '{ print $1 }' 5.6.24 – vasek May 19 '15 at 14:35
1

[!520]#

mysql --version|awk '{ print $5 }'|awk -F\, '{ print $1 }'

Output is :

5.5.41
PersianGulf
  • 602
  • 8
  • 21
Satalink
  • 188
  • 1
  • 7