“Learn to create new users, assign privileges, and optimize security with MySQL using simple commands and practical examples.”
Code Example:
-- Creating a new user
CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'password';
-- Granting permissions
GRANT SELECT, INSERT, UPDATE ON database_name.* TO 'new_user'@'localhost';
-- Refreshing privileges
FLUSH PRIVILEGES;Explanation:
- Creating a New User:
- CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'password';
- Replace 'new_user' with the desired username and 'password' with a strong password.
- Granting Permissions:
- GRANT SELECT, INSERT, UPDATE ON database_name.* TO 'new_user'@'localhost';
- Adjust privileges (SELECT, INSERT, UPDATE) and specify the target database and user.
- Refreshing Privileges:
- FLUSH PRIVILEGES;
- Ensures changes take effect immediately.
Master the art of user management and access control in MySQL for a robust and secure database environment.
