The CREATE USER
statement creates new MySQL accounts. It enables account authentication properties to be established.
To create the new user on MySQL, enter the command CREATE USER
<USERNAME> and Replace <USERNAME> with the name of your user.
Contents
Step 1: Login to MySQL:
To begin, sign into MySQL with the following command:
1 2 |
[user@localhost $] mysql -u root -p Enter password: |
Enter the administrator password you set up during installation.
Step 2: Create MySQL User :
We’ll create a user with the name TestUser , and the password TestUser.
1 2 3 4 5 |
mysql> mysql> CREATE USER 'TestUser'@'localhost' IDENTIFIED BY 'TestUser' ; +--------------------------------+ 4 rows in set (0.01 sec)mysql> mysql> |
Step 3: Create your database:
1 2 3 |
mysql> CREATE USER 'TestUser'@'localhost' IDENTIFIED BY 'test123' ; Query OK, 0 rows affected (0.01 sec)mysql> mysql> |
To give the new user proper permissions, work through our tutorial on granting permissions to MySQL user’s via the command line.
Step 4: View a List of MySQL Users :
Viewing a full list of MySQL users, including the host they’re associated with, can be done with the following select statement:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
mysql> SELECT User,Host FROM mysql.user; +------------------+-------------------+ | User | Host | +------------------+-------------------+ | root | 127.0.0.1 | | root | ::1 | | TestUser | localhost | | debian-sys-maint | localhost | | root | localhost | +------------------+-------------------+ 6 rows in set (0.00 sec) mysql> mysql> |
Conclusion
IIn this post, i have explained how to Create a MySQL User on Linux via Command Line.
If you have any questions or feedback, feel free to leave a comment.
As always, if you found this post useful, then click like and share it 🙂