I. wsl-2 II. ubuntu III. mysql fresh installation
- Login to mysql as root
# wsl
sudo service mysql start # start mysql service
sudo mysql -u root # login to mysql console as root (you don't need password on fresh installation)
- CREATE NEW USER IN THE SQL CONSOLE mysql>
--MYSQL
CREATE USER 'deepesh'@'localhost' IDENTIFIED BY 'pASScODE123xyz';
Note: Replace 'pASScODE123xyz' with your password.
- Grant Priviledges for the new USER mysql>
GRANT ALL PRIVILEGES ON * . * TO 'deepesh'@'localhost';
Important: Provides all admininstrative privileges to user 'deepesh' for all databases and tables. On a complex organizational structure, you can also edit these values for precise user access, eg, access to only certain databases for users.
- FLUSH THE PRIVILEGES mysql>
FLUSH PRIVILEGES;
- Exit and Restart mysql>
exit
bash
sudo service msyql restart
- Log in with the new id bash
# Replace deepesh with the new user
sudo mysql -u deepesh -p
-
Now you should be able to manage your database with the new users
-
Some useful mysql commands
mysql>
-- List all users
SELECT user FROM mysql.user;
-- Delete a user
DELETE FROM mysql.user WHERE user="deepesh";
-- Don't forget to flush the database privileges when adding/editing/removing user
FLUSH PRIVILEGES;
-- Output: Query OK, 0 rows affected (0.01 sec)