To create a new user and grant permissions in MySQL, you can use the following steps:

  1. Connect to the MySQL server as the root user:
mysql -u root -p
  1. Create a new user with a password by using the following command:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
  1. Grant the new user specific permissions on a specific database using the GRANT command. For example, to grant all privileges on the database named "mydb":
GRANT ALL PRIVILEGES ON mydb.* TO 'newuser'@'localhost';
  1. To grant all privileges on all databases
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
  1. To flush the privileges, so the server reloads the grant tables and put new privileges into effect.
FLUSH PRIVILEGES;
  1. Exit MySQL:
exit;

It is important to note that these commands must be executed as the MySQL root user, and the user will only have the granted privileges when connecting from localhost.

أحدث أقدم