On this tutorial, I will show you how to create a new MySQL user via command line. Its a good practice to master the MySQL server command line. There will be more tutorial about MySQL but for the first time, I will show you how to create a new user.
Before we go through, it is important to know that this task requires root access to MYSQL Server. Also, MySQL Server must be installed and configured properly. You may have a look at my previous tutorial on how to install and configure MySQL Server on Ubuntu 16.04.
Create a new MySQL User
First, login to the server where MySQL Server is installed. You can also login from other computer using ssh command for example:
Where 184.108.40.206 is your server where MySQL is installed. Now login to MySQL
mysql -u root -p
root@ubuntu-cloud:~# mysql -u root -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 984
Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
OK, now we are inside the MySQL command prompt. To create a new user, use the following command
CREATE USER 'fitri'@'localhost' IDENTIFIED BY '12345678';
mysql> CREATE USER ‘fitri’@’localhost’ IDENTIFIED BY ‘12345678’;
Query OK, 0 rows affected (0.01 sec)
The command will create a new user called fitri with password 12345678.
Now you may grant privileges of any databases to the new user
grant all privileges on *.* to 'fitri'@'localhost';
mysql> grant all privileges on *.* to ‘fitri’@’localhost’;
Query OK, 0 rows affected (0.00 sec)
Now flush the privileges to activate the new user