Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use DATABASE () and CURRENT_USER () functions in MySQL

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use DATABASE () and CURRENT_USER () function in MySQL. It has certain reference value, and friends who need it can refer to it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

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 older versions than MySQL 4.1.1, if there is no default database, the database function is used to return an empty string.

Syntax:

SELECT DATABASE ()

The 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's consider that the default database name is "Employees". Therefore, to know the name of the default database, you can perform database functions in the following ways:

Output:

'Employees'

CURRENT_USER () function

The CURRENT_USER () function in MySQL returns the user name and hostname of the MySQL account that the server uses to authenticate the current client.

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

Syntax:

SELECT CURRENT_USER ()

The CURRENT_USER () function also takes no arguments.

Example:

Let's consider that the user name used by the server to authenticate the MySQL account of the current client is "root" and the hostname is "localhost". Therefore, to know the user name and hostname that the server uses to authenticate the MySQL account of the current client, you can execute the CURRENT_USER () function in the following ways:

Output:

Root@localhost' Thank you for reading this article carefully. I hope it will be helpful for everyone to share how to use the DATABASE () and CURRENT_USER () functions in MySQL. At the same time, I also hope that you will support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report