Spex3
    

Basic Database Administration in MySQL 🛠️📊


    

    

Basic Database Administration in MySQL 🛠️📊
Database administration involves managing, optimizing, and securing databases to ensure efficient performance and reliability.

1️⃣ Creating & Managing Users 👤🔐
MySQL allows creating multiple users with specific privileges.

✅ Create a New User

 
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';


✅ Grant Permissions to a User

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
Use ALL PRIVILEGES for full access or specific permissions like SELECT, INSERT, UPDATE.


✅ View User Privileges

SHOW GRANTS FOR 'username'@'localhost';


✅ Remove a User

DROP USER 'username'@'localhost';


2️⃣ Backups & Restoring Data 💾
Keeping database backups is crucial to prevent data loss.

✅ Backup a Database (Using mysqldump)

mysqldump -u root -p database_name > backup.sql


✅ Restore a Database


mysql -u root -p database_name < backup.sql


3️⃣ Monitoring & Performance Optimization 🚀
Keeping the database fast and efficient is key.

✅ Check Running Processes


SHOW PROCESSLIST;


Helps detect slow or stuck queries.

✅ Optimize a Table

OPTIMIZE TABLE table_name;


Reorganizes data storage for better performance.

✅ Analyze Index Usage



SHOW INDEX FROM table_name;


Ensures indexes are used efficiently.

4️⃣ Securing a Database 🔒
✅ Change the Root Password


ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';


✅ Prevent Unauthorized Access

REVOKE ALL PRIVILEGES ON database_name.* FROM 'username'@'localhost';


✅ Disable Remote Root Login (For Security)
Edit MySQL configuration (my.cnf or my.ini) and set:


bind-address = 127.0.0.1


🎯 Summary
Task Command/Action
Create User CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
Grant Permissions GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
Backup Database mysqldump -u root -p database_name > backup.sql
Restore Database mysql -u root -p database_name < backup.sql
Optimize Table OPTIMIZE TABLE table_name;
Check Running Queries SHOW PROCESSLIST;
Change Root Password ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';


    Date: 2025-03-29 00:00:00.000000