Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mySQL: Testing connection with query?

I am writing some unit tests to ensure that everything is working as supposed in my application and thought it would be an good idea to write a short test script to ensure that the mySQL connection is working as intended.

Is there any query I can run that will always output something sweet that I can verify the connection upon, without having to think about eventual stored data in the mySQL database?

like image 929
Industrial Avatar asked Feb 10 '11 12:02

Industrial


2 Answers

is there any query I can run that will always output something sweet

This should do it

SELECT 'Something sweet'

Edit
If you don't want something sweet you can always use the built-in functions:

SELECT version()

for more ideas check out the manual:
http://dev.mysql.com/doc/refman/5.1/en/information-functions.html

like image 148
a_horse_with_no_name Avatar answered Sep 20 '22 03:09

a_horse_with_no_name


To get more details you can also use SHOW statement:

SHOW VARIABLES LIKE 'version%';

+---------------------------------+---------------------------+
| Variable_name                   | Value                     |
+---------------------------------+---------------------------+
| version                         | 5.1.6-alpha-log           |
| version_comment                 | Source distribution       |
| version_compile_machine         | i686                      |
| version_compile_os              | suse-linux                |
+---------------------------------+---------------------------+

http://dev.mysql.com/doc/refman/5.1/en/show-variables.html

like image 25
yarson Avatar answered Sep 18 '22 03:09

yarson