To create a new user and grant permissions in MySQL, you can use the following steps:
-
Connect to the MySQL server:
mysql -u root -p
-
Create a new user:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
-
Grant the necessary permissions to the user. For example, to grant the user all permissions for the database
mydatabase
, you can use the following command:GRANT ALL PRIVILEGES ON mydatabase.* TO 'newuser'@'localhost';
-
If you want to grant the user permissions for all databases, use the following command:
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
-
If you want to grant specific permissions, you can use the
GRANT
command followed by the specific privileges you want to grant. For example:GRANT SELECT, INSERT, UPDATE ON mydatabase.* TO 'newuser'@'localhost';
-
If you want to grant the user access from a remote host, you can specify the hostname or IP address in place of
localhost
. -
Flush the privileges to apply the changes:
FLUSH PRIVILEGES;
-
Exit the MySQL prompt:
EXIT;
If you are looking for consultation, fill the Contact Form below.
Know thyself, know thy enemy. A thousand battles, a thousand victories.
Haluk YAMANER
Founder @ Future Software UAE
Founder @ Future Linux
Click here for more about me »