to create new user in MySQL follow below steps:
Create new MySQL User
CREATE USER 'demo'@'localhost' IDENTIFIED BY 'dem0123';
Once the user is created, you will need to set permissions to grant access to database. Here I will first create a testdb
to create new database to set permissions.
Create new database
CREATE DATABASE testdb;
Assign permissions to database
GRANT ALL PRIVILEGES ON testdb.* TO 'demo'@'localhost';
Update changes by executing below command:
FLUSH PRIVILEGES;
Drop user
DROP USER 'demo'@'localhost';
Validate permissions
SHOW GRANTS FOR 'demo'@'localhost';
Output:
+----------------------------------------------------------------+
| Grants for demo@localhost |
+----------------------------------------------------------------+
| GRANT USAGE ON *.* TO `demo`@`localhost` |
| GRANT ALL PRIVILEGES ON `testdb`.* TO `demo`@`localhost` |
+----------------------------------------------------------------+
2 rows in set (0.00 sec)
Allowing remote access for MySQL 8
server
In mysql 8 in centos 8 server, edit /etc/my.cnf
file and add following line at the end and save:
bind-address = 0.0.0.0
You can reference this tutorial here for any further details.
Create user
CREATE USER 'demo'@'10.1.1.%' IDENTIFIED BY 'password';
Grant privileges
GRANT ALL ON testdb.* TO 'demo'@'10.1.1.%';
FLUSH PRIVILEGES;