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

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

藏色散人
Release: 2019-03-15 13:36:17
Original
10998 people have browsed it

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();
Copy after login

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'
Copy after login

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();
Copy after login

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'
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template