How to Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs

# mysql -u root -p

mysql> use mysql;

mysql>INSERTINTO user (Host,User,Password) VALUES(‘%’,’username’,PASSWORD(‘password’));

mysql> flush privileges;

To create a new user in MySQL, you can follow these steps:

  1. Login as root:
    bash
    mysql -u root -p

    You will be prompted to enter the root password.

  2. Switch to the MySQL database:
    sql
    USE mysql;
  3. Create the new user:
    sql
    CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'password';

    Replace ‘new_user’ with the desired username and ‘password’ with the desired password.

  4. Update privileges:
    sql
    GRANT ALL PRIVILEGES ON *.* TO 'new_user'@'localhost';

    This grants all privileges to the user on all databases and tables. If you want to grant specific privileges or limit access to specific databases or tables, you can modify the query accordingly.

  5. Flush privileges to apply changes:
    sql
    FLUSH PRIVILEGES;

    This ensures that the changes take effect immediately.

Remember to replace ‘new_user’ and ‘password’ with your desired username and password. Also, be cautious with granting privileges; only provide the necessary permissions to ensure security.