How to create user in MySQL Server - MySQL DBA Tutorial

How to create User in MySQL Server


To create user in MySQL , you can use mysql command line or we can use Graphical tools such as MySQL Workbench. 

Syntax:


MySQL > Create User 'UserName'@'Server' IDENTIFIED BY 'YourPassword';


Let's say if you need to create user Aamir with password =Aamir$Password, you will be using below statement.

MySQL > Create user 'Aamir'@'localhost' Identified by ' Aamir$Password';


Notice that when I created the user , I provided @'localhost' that means the user Aamir can access MySQL server only from the same machine where MySQL server is installed. 
In case , the user would like to connect to MySQL server from another machine, we have to provide the ip of that machine. Let's say if the ip of machine from which user Aamir would like to connect to MySQL is 10.0.0.5 then our create statement will look below.



MySQL > Create user 'Aamir'@'10.0.0.5' Identified by ' Aamir$Password';                          


To check if the user has been created successfully, we can run below statement in MySQL.
MySQL > Select host, user  from mysql.user; 


How to create user in MySQL Server on Windows and on Linux

3 comments: