Create new mysql user with all privileges

To create a new MySQL user with all privileges, you can use the following command:

CREATE USER 'newuser'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'%';
FLUSH PRIVILEGES;

Let me explain what each line does:

  1. CREATE USER 'newuser'@'%' IDENTIFIED BY 'password';: This line creates a new user named newuser with a password of password. The % wildcard allows the user to connect from any host.
  2. GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'%';: This line grants all privileges to the new user on all databases (*.*). The GRANT statement is used to assign privileges to a user.
  3. FLUSH PRIVILEGES;: This line reloads the grant tables to ensure that the new user's privileges are applied immediately.

Note:

Also, you can use the following command to create a new user with all privileges and specify the host:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
FLUSH PRIVILEGES;

This will create a new user with all privileges only for the localhost host.