Introduction
In this project, you will learn how to access the MySQL database and obtain information about the current logged-in user and the system user.
👀 Preview
MariaDB [(none)]> SOURCE /home/labex/project/currentUser.sql;
+----------------+----------------+
| CURRENT_USER() | SYSTEM_USER() |
+----------------+----------------+
| root@localhost | root@localhost |
+----------------+----------------+
1 row in set (0.000 sec)
🎯 Tasks
In this project, you will learn:
- How to access the MySQL database using the
sudocommand without a password - How to use the
CURRENT_USERandSYSTEM_USERfunctions to retrieve user information - How to save the SQL script to a designated file location
🏆 Achievements
After completing this project, you will be able to:
- Understand how to access the MySQL database and execute SQL statements
- Retrieve information about the current logged-in user and the system user
- Save SQL scripts to a specific file location for future use
Access MySQL and Obtain User Information
In this step, you will learn how to access the MySQL database using the sudo command and obtain information about the current logged-in user and the system user.
- Open a terminal and start the MySQL service using the following command:
sudo service mysql start
- Access the MySQL database using the
sudocommand without any password:
sudo mysql
You should now be in the MySQL prompt, ready to execute SQL statements.
Display Current User and System User Information
In this step, you will write SQL statements to display the current logged-in user and the system user information.
- Open the
currentUser.sqlfile. - Add the following SQL statement:
SELECT CURRENT_USER(), SYSTEM_USER();
This statement will use the CURRENT_USER function to obtain information about the currently logged-in user and the SYSTEM_USER function to obtain information about the system user.
Save the SQL Script
In this final step, you will save the SQL script to the designated file location.
- Run the script in the MySQL prompt using the following command:
MariaDB [(none)]> SOURCE /home/labex/project/currentUser.sql;
This will execute the SQL script and display the current logged-in user and system user information.
The output should look similar to the following:
+----------------+----------------+
| CURRENT_USER() | SYSTEM_USER() |
+----------------+----------------+
| root@localhost | root@localhost |
+----------------+----------------+
1 row in set (0.000 sec)
This output shows that the current logged-in user and the system user are both root@localhost.
Congratulations! You have completed the project and saved the SQL script to the designated location.
Summary
Congratulations! You have completed this project. You can practice more labs in LabEx to improve your skills.



