Installation and Configuration of MySQL on Ubuntu 24.04
1. Update System Repositories
Before installing MySQL, make sure the system repositories are up to date:
sudo apt updateCopied!
2. Install MySQL Server
Run the following command to install MySQL Server:
sudo apt install mysql-server -yCopied!
3. Verify the Installed Version
Check that MySQL has been installed correctly by verifying its version:
mysql --versionCopied!
Expected output:
mysql Ver 8.0.37-0ubuntu0.24.04.1 for Linux on x86_64 ((Ubuntu))
4. Enable MySQL to Start on System Boot
To make MySQL start automatically with the system, enable it with:
sudo systemctl enable mysqlCopied!
5. Start the MySQL Service
Start the MySQL service:
sudo systemctl start mysqlCopied!
6. Check the Service Status
Verify that the server is running:
sudo systemctl status mysqlCopied!
MySQL Security Configuration
7. Run the Secure Installation Script
Use the following command to start the secure MySQL configuration:
sudo mysql_secure_installationCopied!
This will ask a few questions, and their answers are:
- VALIDATE PASSWORD component: Enter Y to enable password validation.
- Password Validation Policy: Enter 2 to enable strong passwords.
- New password: Enter a strong password for the root user.
- Remove anonymous users?: Enter Y.
- Disallow root login remotely?: Enter Y.
- Remove test database and access to it?: Enter Y.
- Reload privilege tables now?: Enter Y.
8. Restart the MySQL Service
Apply the changes by restarting MySQL:
sudo systemctl restart mysqldCopied!
Database and User Management
9. Access the MySQL Client
Access the MySQL console as the root user:
sudo mysql -u root -pCopied!
10. Create a Database
Create a new database called glintu:
CREATE DATABASE glintu;Copied!
11. Create a User
Create a user named "usuario" with the password "password":
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';Copied!
12. Grant Privileges
Grant all privileges to the user for the created database:
GRANT ALL PRIVILEGES ON glintu.* TO 'user'@'localhost';Copied!
Confirm the changes:
FLUSH PRIVILEGES;Copied!
14. View Databases
SHOW DATABASES;Copied!
15. Use the Created Database
USE glintu;Copied!
16. Create a Table
CREATE TABLE tabla_glintu ( \ id INT AUTO_INCREMENT PRIMARY KEY, \ name VARCHAR(255) NOT NULL, \ description TEXT, \ email VARCHAR(255), \ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP \ );Copied!
17. Insert Data into a Table
INSERT INTO tabla_glintu (name, description, email) VALUES \ ('First', 'Description First.','first@email.com'), \ ('Second', 'Description Second.','second@email.com'), \ ('Third', 'Description Third.','third@email.com'), \ ('Fourth', 'Description Fourth.','fourth@email.com');Copied!
18. View Data from the Table
SELECT * FROM tabla_glintu;Copied!
Conclusion
Congratulations! You now have MySQL installed, configured, and ready to manage databases and users on your Ubuntu 24.04 system. From here, you can continue exploring advanced MySQL features to tailor it to your specific needs.