It is important to ensure that the user is connected to the server before entering a query into the console. The query below will provide the server version number in use and the current date.
mysql> SELECT VERSION(), CURRENT_DATE;
Note: The functions 'VERSION()' and 'CURRENT_DATE' are case-insensitive. This means that 'version()', 'Version()', 'vERsion()' all mean the same thing. The same goes for 'CURRENT_DATE'.
A SQL query must be followed by a semicolon.
When a query is issued to mysql, it sends the query to the server for execution. Calculate the result and display it. A 'mysql>' will also be printed, indicating that the server is ready to receive another query.
The output after executing the mysql query is presented in table form, that is, rows and columns. The first row contains the names of the columns. The remaining rows are the query results.
Once the query has been executed, 'mysql' will also give you the number of rows returned and the time it took to execute the query. This gives the user a general idea of the server's performance.
MySQL server can also be used to execute multiple statements in a row. This usage has been demonstrated below -
mysql> SELECT VERSION(); SELECT NOW();
The MySQL server determines the end of a query statement by looking for the terminating semicolon rather than the end of the input line. This can be seen in the following query:
mysql> SELECT −> USER() −> , −> VERSION();
In the above query, it is important to note that when it wraps, the prompt changes from 'mysql>' to '−>' because this is a Multi-line query. Since no terminating semicolon was encountered, it outputs '−>', otherwise the query would have been sent to the server for execution.
The above is the detailed content of Enter MySQL query. For more information, please follow other related articles on the PHP Chinese website!