There are few ways you can create a new user for a MySQL DB.
- Using grant command to create a new user and assign privileges to access a DB.
- Use the create user mysql command followed by grant command to set access privileges.
- Directly editing the mysql DB using insert, update etc (which is a bit complex)
Create USER
For creating user following command is used
CREATE USERuser[IDENTIFIED BY [PASSWORD] 'password']
The above command creates a new user, but who has no access to any DB. In order to grant prermissions to access any DB, we need to use the grant command.
Grant Command
GRANT ALL ON *.* TO 'someuser'@'somehost';
The above will grant ALL the permission (select, insert, updat, delet etc) to someuser at somehost. If you would like to set a user from a particular IP to access the DB, you can use like
GRANT ALL ON *.* TO 'someuser'@'IPADDRESS';
The following command will give only select and insert privileges to someuser at somehost
GRANT SELECT, INSERT ON *.* TO 'someuser'@'somehost';