Home  >  Article  >  Database  >  Detailed examples of DATABASE() and CURRENT_USER() functions in MySQL

Detailed examples of DATABASE() and CURRENT_USER() functions in MySQL

藏色散人
藏色散人Original
2019-03-15 13:36:1710920browse

In this article, we will introduce to you the difference between the DATABASE() and CURRENT_USER() functions in MySQL. We hope it will be helpful to friends in need!

Detailed examples of DATABASE() and CURRENT_USER() functions in MySQL

DATABASE() function

The DATABASE() function in MySQL returns the name of the default or current database. The string or name returned by the DATABASE() function uses the utf8 character set. If there is no default database, the Database function returns NULL.

In versions older than MySQL 4.1.1, database functions were used to return an empty string if there was no default database.

Syntax:

SELECT DATABASE();

DATABASE() function is easy to use and does not accept any parameters. We can easily get the name of the default database using the above syntax on the MySQL console.

Example:

Let us consider that the name of the default database is "Employees". So, to know the name of the default database, you can execute the database function by:

Detailed examples of DATABASE() and CURRENT_USER() functions in MySQL

Output:

'Employees'

CURRENT_USER() function

The CURRENT_USER() function in MySQL is used to return the username and hostname of the MySQL account used by the server to authenticate the current client.

From MySQL 4.1. Initially, the CURRENT_USER() function uses the utf8 character set.

Syntax:

SELECT CURRENT_USER();

The CURRENT_USER() function also does not accept any parameters.

Example:

Let us consider that the username used by the server to authenticate the current client's MySQL account is "root" and the hostname is "localhost". So, to know the username and hostname that the server uses to authenticate the current client's MySQL account, you can execute the CURRENT_USER() function in the following way:

Detailed examples of DATABASE() and CURRENT_USER() functions in MySQL

Output:

'root@localhost'

This article is an introduction to the DATABASE() and CURRENT_USER() functions in MySQL. More mysql tutorials are recommended: "mysql tutorial"

The above is the detailed content of Detailed examples of DATABASE() and CURRENT_USER() functions in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn