MySQL is a great database manager that is used all over the world. There are a lot of features that make it a good-to-go program. If we use it in a systematic manner, it might provide the best of what it can. It is easy to use and very simple to understand.
In order to increase security measures, creating a user is the easiest and effective way to protect the data. You can set permissions limit so as to secure your files from malicious attacks. There are a lot of other things that you can do with MySQL along with creating and showing users with desired permissions.
By the end of this article, we will show you how you can show the users in MySQL using Linux. As you can create a lot of users but need to manage them in the future. So, you should always know the commands and code to manage and do different things on MySQL.
Show all users in MySQL using Linux
Without any further adieu, We are going to share the easiest method that you can use for showing the users in MySQL. We assume that you must have all the privileges to show the users from your database. Follow these steps and enjoy showing all the users in MySQL using Linux.
Login through SSH
Firstly, you need to login to your server using SSH. All you have to do is run this command in any of your SSH client/terminals. Make sure to replace the user-name with your username and your-server with your server details like IP, port, or domain.
Check for Root Privileges on your account
You need to check for the root privileges on your account. Once you are logged in to your server using ssh, you need to check if the particular account has root privileges. In order to do that, run this command to check if your account has root access.
sudo mysql -u root -p
Enter MySQL Root Password
Now, you need to enter the password for MySQL root access. This is a different password from your server root password. Make sure you are using the right MySQL root password at the right time.
Once you enter the password, you must be redirected to the MySQL Console. So, if you have successfully entered the right password for MySQL root access, you will be in the MySQL console. From the MySQL console, you can enter the commands,
Show Users in MySQL
Now you can run the command to show users in your MySQL client. All you have to do is simply copy the command from below and paste it in the console. You will get the list of users on your MySQL database.
mysql> SELECT user FROM mysql.user;
This command will extract the details of users that were created in MySQL till the time. If you want, you can add the host details as well if you see any duplicate users from different hosts from the same server. For that follow the next optional step.
Filtering Host Column (Optional)
You might need to filter out the host if you have multiple hosts on the same server. All you have to do is just add the column for the host in the command that we have used earlier. Copy the command from below and paste it in the console.
mysql> SELECT user,host FROM mysql.user;
This will tell you the details about the host of the user. Simply, there will be an additional column for the host along with the user info from your user table. You can simply check whichever user you want to see.
Why do you need to create Users in MySQL?
This is a valid question. Why do you actually need to create users in MySQL? Well, the world is changing, hackers are too! But, We don’t want to leave a single chance from our end for any attack on our database. As you must have known, there is a root user on the MySQL database, which has all the admin privileges. It is not relevant to use the root user for every other task.
The Admin access should be with the owner only. The other person in the team should have a separate account with limited access. Thus, It will create a hierarchy between the permissions and will ultimately protect the utmost later of the database. Hackers would always go for accessing the default root user in order to harm the database/website.
There are multiple things that you can make sure are checked for your database management. You should create users according to the permissions divided in a systematic manner. Just in case, an account is compromised, you still have some hope with the other accounts. Giving all the permission to a single account is like giving away all you’ve got.
Thus, Creating specific users having arranged permissions will ensure the security along with helping you to manage different tasks at once. This is the reason, people generally prefer making users in MySQL instead of having a single root user with all the admin privileges.
This was all about how you can show users in MySQL using Linux. We told you the commands that you can use in the console directly. There is no need to have additional software/applications. All you need to have is the access, ssh client, Linux system(obviously).
If you are facing any issue, let us know through the comments. We are happy to help you if you are stuck at any of the steps on the above method. Please share your feedback/suggestions or any other method that you feel is easier and we would love to include it to the list.
Also, if the method worked for you, share your experience on showing the users in MySQL through Linux. That’s it. Follow us on social media platforms and share this with your friends. We hope that you got what you wanted.