MySQL: checking connection with query?

I am writing some unit tests to ensure that everything works as intended in my application, and thought it would be nice to write a short test script to make sure mySQL connection works as intended.

Is there any query that I can run that always displays something sweet that I can test the connection without thinking about the possible stored data in the mySQL database?

+6
mysql unit-testing testing
source share
4 answers

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

It 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 guide:
http://dev.mysql.com/doc/refman/5.1/en/information-functions.html

+17
source share

For more information, you can also use the 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

+1
source share

Most db drivers have a ping () method, where they have a mechanism that does exactly what your peers offer.

However, showing variables and choosing from nothing exposes anything of common sense, except for the database mechanism, the storage can be omitted, indexes can be damaged, errors are everywhere.

+1
source share

The best answer can be found here:

(Just post this since I dropped this link first after a Google request and this can be misleading).

0
source share

All Articles