MySQL: Testing connection with query?


Use any predefined function with select query or you can print some words with the select query in order to test connection with query.

The syntax is as follows.

SELECT yourValue;

The select query with predefined function is as follows.

The syntax is as follows.

SELECT anyPredefinedFunctionName();

Now you can implement the above syntax in order to test connection with query.

Case 1 -The query is as follows.

mysql> select "This is MySQL" as Display;

The following is the output.

+---------------+
| Display       |
+---------------+
| This is MySQL |
+---------------+
1 row in set (0.00 sec)

Case 2 -The query is as follows.

mysql> select 10*3 as MultiplicationResult;

The following is the output

+---------------------+
| MultiplicationResult|
+---------------------+
| 30                  |
+---------------------+
c1 row in set (0.00 sec)

Here is the select query to know the connection id which is predefined function.

Case 1 -The query is as follows

mysql> select connection_id() as ConnectionId;

The following is the output

+--------------+
| ConnectionId |
+--------------+
| 8            |
+--------------+
1 row in set (0.00 sec)

Case 2 -Here is the predefined function database() to know the current database name.

The query is as follows

mysql> select database();

The following is the output

+------------+
| database() |
+------------+
| sample     |
+------------+
1 row in set (0.00 sec)

Updated on: 30-Jul-2019

681 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements