Mysql add new user

To add a new user in MySQL, you can use the following command:

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

Here:

For example, to create a new user named 'john' who can connect from any host with the password 'mypassword', you would use the following command:

CREATE USER 'john'@'%' IDENTIFIED BY 'mypassword';

After creating the user, you can grant the user privileges using the GRANT command. For example, to grant the user 'john' all privileges on the database 'mydatabase', you would use the following command:

GRANT ALL PRIVILEGES ON mydatabase.* TO 'john'@'%';

You can also grant specific privileges to the user. For example, to grant the user 'john' the privilege to SELECT, INSERT, UPDATE, and DELETE on the table 'mytable' in the database 'mydatabase', you would use the following command:

GRANT SELECT, INSERT, UPDATE, DELETE ON mydatabase.mytable TO 'john'@'%';

After granting the privileges, you can flush the privileges using the following command:

FLUSH PRIVILEGES;

This will reload the grant tables and make the new user and privileges available.

Note: You can also use the mysql command-line client to create and manage users. For example, you can use the following command to create a new user:

mysql -u root -p<password> -e "CREATE USER 'john'@'%' IDENTIFIED BY 'mypassword';"

Replace <password> with the password for the root user.