Before entering queries on the console, it is important to ensure that the user is connected to the server. The below query would give the version number of the server being used, and the current date.
mysql> SELECT VERSION(), CURRENT_DATE;
Note: The function ‘VERSION()’ and ‘CURRENT_DATE’ are case−insensitive. This means ‘version()’, ‘Version()’, ‘vERsion()’, all mean the same. Same goes with ‘CURRENT_DATE’
An SQL query is followed by a semi-colon.
When a query is issued to mysql, it sends the query to the server for execution. The results are computed and displayed. Another ‘mysql>’ also gets printed, indicating that the server is ready for one more query.
The output after executing the mysql query is in tabular form, i.e rows and columns. The first row contains the name of the columns. The remaining rows are the query results.
Once the query is executed, ‘mysql’ also gives the number of rows that were returned, the amount of time taken to execute the query. This gives the user a rough idea about the performance of the server.
MySQL server can also be used to execute multiple statement in a single line. It has been shown below −
mysql> SELECT VERSION(); SELECT NOW();
The ‘mysql’ server determines the end of the query statement by looking for the terminating semicolon, not the end of an input line. It can be seen in the following query −
mysql> SELECT −> USER() −> , −> VERSION();
In the above query, it is important to see that the prompt changed from ‘mysql>’ to ‘−>’ when it went to the next line, since this is a multi−line query. The terminating semi−colon was not encountered, hence it gave out a ‘−>’, else the query would have been sent to the server to get executed.