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:
CREATE USER 'newuser'@'%' IDENTIFIED BY 'password';
: This line creates a new user namednewuser
with a password ofpassword
. The%
wildcard allows the user to connect from any host.GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'%';
: This line grants all privileges to the new user on all databases (*.*
). TheGRANT
statement is used to assign privileges to a user.FLUSH PRIVILEGES;
: This line reloads the grant tables to ensure that the new user's privileges are applied immediately.
Note:
- Make sure to replace
newuser
andpassword
with the desired username and password for your new user. - Be careful when granting all privileges to a user, as it can pose a security risk if not used properly.
- If you want to grant privileges only on a specific database, you can modify the
GRANT
statement toGRANT ALL PRIVILEGES ON database_name.* TO 'newuser'@'%';
.
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.