You can create a new user and grant all privileges on a specific database in MySQL using the following steps:
- Log in to your MySQL server as a user with administrative privileges using the following command
sudo mysql -u root -p
This will prompt you to enter the MySQL root password. - Create a new user by running the following SQL command:
CREATE USER 'shahid'@'localhost' IDENTIFIED BY 'password';
Replacenew_user
with the desired username andpassword
with the desired password. - Grant all privileges on the
shahid
database to the new user by running the following SQL command:GRANT ALL PRIVILEGES ON shahid.* TO 'new_user'@'localhost';
This will grant all privileges on theshahid
database to the usernew_user
from thelocalhost
host. - Reload the privileges by running the following SQL command:
FLUSH PRIVILEGES;
This will reload the privileges and make the changes take effect immediately.
If any syntax error then run! these commands
CREATE USER ‘shahid’@’localhost’ IDENTIFIED BY ‘shahidpassword321!!!@#’;
GRANT ALL PRIVILEGES ON *.* TO ‘shahid’@’localhost’;
FLUSH PRIVILEGES;