How to create User in MariaDB and MySQL on Linux


 

While working with MariaDB/Mysql Server, We need to create standard user to use define database and tables by using the following command, We can achieve the this. 


In this post, We will create user in MariaDB/Mysql database server on linux.

 

Step 1: Login MariaDB/Mysql Shell

 

You need to login MariaDB/Mysql Shell by using the given command.

mysql -u root -p

 

Step 2: Create a Database

 

To create new database use the following command if you want to use your existing database so then you can skip this step.

CREATE DATABASE 'DATABASE_NAME_HERE';

 

Step 3: Verify the Created Database

 

After execution the command, You need to verify it by following command.

SHOW DATABASES;

 

Step 4: Add the User

 

You need to use the given command to add or create a user with MariaDB/Mysql  database server and you need to assign specific Database or all the database.

CREATE USER 'USER_NAME_HERE' IDENTIFIED BY 'PASSWORD_HERE';

Grant all privileges to a user on a specific database.
GRANT ALL privileges ON `mydb`.* TO 'myuser'@localhost;

Step 5: Grant Permission

 

Grant permissions to access and use the MySQL server on all the databases, Use the following command for the same.

GRANT USAGE ON *.* TO 'MYUSER_HERE'@localhost IDENTIFIED BY 'MYPASSWORD_HERE';

Step 6: Allow Network

 

To allow access to MySQL server from any other computer on the network, execute the given command for the same.

GRANT USAGE ON *.* TO 'myuser'@'%' IDENTIFIED BY 'MYPASSWORD_HERE';

Step 7: Apply Changes

  

You need to FLUSH PRIVILEGES  command to apply new changes in MariaDB/Mysql server.

FLUSH PRIVILEGES;

 

Step 8: Verify the User

 

Verify your new user has the right permissions by using the given command or the same.
SHOW GRANTS FOR 'myuser'@localhost;

 

Conclusion

We have successfully created user with MariaDB server on Ubuntu 20.04 server.

 

How to create User in MariaDB and MySQL on Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top