Step 1: We will first retrieve the process list that MySQL is executing. The processlist schema stores the list of all the users logged in and data related to each of the operations performed by users on that database at that particular instant when the query was fired. In that case, if we want to fetch the list of the users currently logged in to your MySQL server can be done by querying on the processlist table of information_schema. There is a possibility that there are multiple users of the MySQL database server, and many users can access the system simultaneously. Checking all the currently logged-in users The functions USER() and CURRENT_USER() can retrieve and fetch the current database user.ģ. You can achieve this by taking the following steps:Įxplanation: The above-returned result of the CURRENT_USER() function is in the format of the user’s name and then symbol that the host further follows. Step 2: One more method is available to retrieve the current user: the current_user() function. Step 1: You can use the following query to accomplish that:Įxplanation: The above function returns the current user’s name, then the host that, in our case, is %, and then the database server’s address. MySQL provides us with the function user() that can be used to retrieve the database’s current user. Most of the columns of the user table that store the values like boolean, i.e., either true or false, have the datatype of an enum having values ‘Y’ that stands for true and ‘N’ that specifies false, i.e., enum(‘N’,’ Y’) datatype that informs whether the particular privilege is assigned to the user or not. Then, in that case, you can choose privilege-related columns as done in the following SELECT query:Įxplanation: Other columns can be retrieved, whichever you want, using the select query. Step 4: Suppose you want to retrieve assigned privilege-related information of the users. ![]() To retrieve more information about users, we can add the columns we want to retrieve in the select query as follows: ![]() Step 3: To retrieve the data from the user table of the MySQL database, you first need to login to MySQL using MySQL -u root pg command if you are using MySQL from the command line through the terminal or if you are using an IDE, enter your credentials or editor such as sqlyog of workbench.Īn alternative to using the above select query, you can first fire the command to select the MySQL database and then fire the following choose query that will produce the same output as above: Step 2: We will first retrieve the names of all the users from the user table using the following SELECT query:Įxplanation: We can see that four users are present for my database server. If you are currently using MySQL as your chosen database, you can utilize the following method:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |