64

I need to check if mysql is installed on a ubuntu server. Is there a way to determine if mySql has been installed ? Thanks.

8 Answers 8

92

You can use tool dpkg for managing packages in Debian operating system.

Example

dpkg --get-selections | grep mysql if it's listed as installed, you got it. Else you need to get it.

4
  • can you tell me that location where it get installed in ubuntu ? Commented Dec 10, 2015 at 23:29
  • 1
    Ask a separate question and I'll be happy to help
    – hd1
    Commented Dec 11, 2015 at 0:08
  • 1
    Not sure this is working in the latest Kubuntu 17.1?. In this screenshot it shows it's not installed (shows 'install', not 'installed'). As a test I tried to install the PHP extension, and it shows it's already installed: i.imgur.com/RsczcPc.png Commented May 3, 2018 at 23:30
  • This answer is plain wrong - perhaps you only have mysql-client installed? Or just mysql-common? Or perhaps even libqt5sql5-mysql or lua-dbi-mysql-dev? Commented Jun 25, 2019 at 10:51
24

"mysql" may be found even if mysql and mariadb is uninstalled, but not "mysqld".

Faster than rpm -qa | grep mysqld is:

which mysqld
17

Multiple ways of searching for the program.

Type mysql in your terminal, see the result.

Search the /usr/bin, /bin directories for the binary.

Type apt-cache show mysql to see if it is installed

locate mysql

3
  • The apt-cache cmd doesn't seem to work (or at least not on the latest Kubuntu 17.1): i.imgur.com/NFOyPUl.png Commented May 3, 2018 at 23:24
  • Add an asterisk after "mysql": apt-cache show mysql*
    – JohnP2
    Commented Jan 22, 2022 at 18:30
  • Actually, I think it doesn't work, either -- it shows some cached information, but not what is installed
    – JohnP2
    Commented Jan 22, 2022 at 18:48
8

With this command:

 dpkg -s mysql-server | grep Status
3

Lots of answers. It should have been a simple command. Just type mysql --version on your terminal and hit enter.

3

In an RPM-based Linux, you can check presence of MySQL like this:

rpm -qa | grep mysql

For debian or other dpkg-based systems, check like this:

dpkg -l mysql-server libmysqlclient*dev*
1
  • While this may solve the OP's problem, a few words of explanation would make this answer even better for the current and future readers of this problem.
    – Thom
    Commented May 6, 2015 at 11:40
2
# mysqladmin -u root -p status

Output:

Enter password:
Uptime: 4  Threads: 1  Questions: 62  Slow queries: 0  Opens: 51  Flush tables: 1  Open tables: 45  Queries per second avg: 15.500

It means MySQL serer is running

If server is not running then it will dump error as follows

# mysqladmin -u root -p status

Output :

mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

So Under Debian Linux you can type following command

# /etc/init.d/mysql status
0
1

Try executing mysql or mysql -- version on terminal.

It will prompt version otherwise Command Not Found

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.