# 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:
- Login as root:
bash
mysql -u root -p
You will be prompted to enter the root password.
- Switch to the MySQL database:
sql
USE mysql;
- 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.
- 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.
- 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.