en
  English
Phone :  +370 (5) 204-1903
Email :  sales@1gbits.com
  1. Dedicated server
  2. Blog
  3. How to remove anonymous users from MySQL and MariaDB

How to remove anonymous users from MySQL and MariaDB

If you are a tech professional, you must know about relational databases. Both MySQL and MariaDB belong to this category. You have to execute several commands to perform some functions in both cases. 

Security Tutorials Dec 22, 21 by Nisal N 3 min Read
How to remove anonymous users from MySQL and MariaDB

If you are a tech professional, you must know about relational databases. Both MySQL and MariaDB belong to this category. You have to execute several commands to perform some functions in both cases. 

We are here to explain the method to remove an anonymous user from MySQL and MariaDB! Let’s begin!

How to remove anonymous users from MySQL or MariaDB?

When you install MySQL, there is a default root user and an anonymous user, both with a blank password. Blank passwords are highly insecure. You must set a password for the root user and remove the anonymous user for security purposes. 

Additionally, this anonymous user account permits anyone to connect with MySQL Server without the user account. The primary purpose of this account is for testing, and it shall be removed at a later stage. 

To remove the anonymous user from MySQL or MariaDB, type in the following command:

Open the terminal on your device and follow these steps.

Step 1: As the root user, open MySQL.

$ mysql -u root -p

OR

$ sudo mysql

Step 2: Now, use the DROP USER command as given below:

mysql> DROP USER 'abc’@'localhost';

After you execute this command, MySQL raises a QUERY OK. You will notice that the user is not available in your database anymore.

Additionally, here are some steps if you wish to create a user in MySQL or MariaDB!

How to create a user in MySQL or MariaDB?

The create user statement helps develop new accounts and enables authentication, password management properties, etc., for the new accounts. 

To create a MySQL user account, execute the following command:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'user_password';

Additionally, if you wish to establish a connection as a user with any host, you can use the ‘%’ wildcard. Here is the usage:

CREATE USER 'newuser'@'%' IDENTIFIED BY 'user_password';

Lastly, you can also grant privileges to a user account by following the below-stated commands in various instances.

To grant the privileges on a particular database: 

GRANT ALL PRIVILEGES ON database_name.* TO 'database_user'@'localhost';

To grant multiple privileges on a specific database:

GRANT SELECT, INSERT, DELETE ON database_name.* TO database_user@'localhost’;

To grant privileges to a user account in all the databases:

GRANT ALL PRIVILEGES ON *.* TO 'database_user'@'localhost';

Conclusion 

The world of MySQL, an open-source relational DBMS, lets you execute plenty of commands for different purposes. It helps you to create various user accounts and grant privileges according to the requirement. This article assists you to understand some of the basic commands that further helps you to remove an anonymous user as well as create a user. 

We hope that the information will halt all your ambiguities related to the topic. Keep learning, keep practising!

author img

Nisal N

Computers has always fascinated me since I was a kid and here we are. I love travelling for 2 reasons: the first one to see a new part of the world and second (the most important one) to experience the rich culture hidden among the country and people. I'm pretty good at cooking but very poor when it comes to baking.

Leave A Comment