MySQL
MySQL Installation and User Management Guide
MySQL Installation and User Management Guide¶
MySQL Installation¶
Install MySQL Server
sudo apt install mysql-server
Secure MySQL Installation
sudo mysql_secure_installation
Start and Enable MySQL Service
# Start MySQL service
sudo systemctl start mysql
# Enable MySQL to start on boot
sudo systemctl enable mysql
# Check MySQL service status
sudo systemctl status mysql
User Management¶
Create New User
CREATE USER 'new_username'@'localhost' IDENTIFIED BY 'password';
Check User Privileges
SHOW GRANTS FOR 'awoogroup'@'localhost';
Granting Privileges¶
Grant All Privileges on Specific Database
GRANT ALL PRIVILEGES ON database_name.* TO 'new_username'@'localhost';
Grant All Privileges on All Databases
If you want to grant all privileges on all databases, you can use the wildcard *:
GRANT ALL PRIVILEGES ON *.* TO 'new_username'@'localhost';
Grant Database Creation Privilege
GRANT CREATE ON *.* TO 'awoogroup'@'localhost';
Grant Specific Privileges (Basic)
GRANT CREATE, DROP, ALTER, SELECT, INSERT, UPDATE, INDEX, DELETE, REFERENCES
ON *.* TO 'awoogroup'@'localhost';
Grant Comprehensive Privileges
GRANT CREATE, ALTER, DROP, INSERT, SELECT, UPDATE, DELETE, INDEX, REFERENCES,
CREATE TEMPORARY TABLES, LOCK TABLES
ON *.* TO 'awoogroup'@'localhost';
This command grants the following privileges to the 'awoogroup' user:
- CREATE: Create databases and tables
- DROP: Delete databases and tables
- ALTER: Modify table structure
- SELECT: Read data from tables
- INSERT: Add new data to tables
- UPDATE: Modify existing data
- DELETE: Remove data from tables
- INDEX: Create and drop indexes
- REFERENCES: Create foreign keys
- CREATE TEMPORARY TABLES: Create temporary tables
- LOCK TABLES: Lock tables for read/write
Change User Password¶
Modern MySQL (5.7.6+)
ALTER USER 'antoree.api'@'localhost' IDENTIFIED BY 'new_password';
Legacy MySQL (older versions)
SET PASSWORD FOR 'antoree.api'@'localhost' = PASSWORD('new_password');
Apply Changes¶
Reload Privileges After making any privilege changes, reload the grant tables:
FLUSH PRIVILEGES;
Notes¶
- Replace
new_usernamewith your desired username - Replace
passwordwith a secure password - Replace
database_namewith your specific database name - Always use strong passwords for database users
- Be cautious when granting
ALL PRIVILEGES ON *.*as it gives superuser access - Run
FLUSH PRIVILEGES;after making privilege changes to ensure they take effect immediately