How to Install MySQL on Ubuntu Server 22.04

Learn how to install MySQL on Ubuntu Server 22.04 with this comprehensive guide from EcoStack Cloud. Follow our step-by-step instructions to set up MySQL efficiently and securely on your server.

mysql ubuntu
Small
VPS
2
vCPU
4 GB
Memory
40 GB
NVMe Disk
2048 GB
Traffic
10.90
/month
* Up to 12GB RAM, 120GB NVMe Disk Space and 1Gbit/s Network Speed
### Tutorial: How to Install MySQL on Ubuntu Server 22.04 #### Step 1: Update Your System First, ensure your package index is up-to-date. ```bash sudo apt update sudo apt upgrade -y ``` #### Step 2: Install MySQL Server Install MySQL server using the package manager. ```bash sudo apt install mysql-server -y ``` #### Step 3: Secure MySQL Installation Run the security script that comes with MySQL. This script will prompt you to set up a root password and remove insecure default settings. ```bash sudo mysql_secure_installation ``` You will be prompted with several security-related questions. It's generally a good idea to answer "Y" (yes) to all questions to enhance the security of your MySQL server. #### Step 4: Start MySQL Service Ensure that the MySQL service is running. ```bash sudo systemctl start mysql ``` You can also enable MySQL to start at boot time. ```bash sudo systemctl enable mysql ``` #### Step 5: Verify MySQL Installation To verify that MySQL is installed and running, log in to the MySQL shell. ```bash sudo mysql -u root -p ``` You should see the MySQL prompt if everything is set up correctly. You can exit the MySQL shell by typing `exit`. #### Step 6: Configure MySQL (Optional) For advanced configurations, you can edit the MySQL configuration file located at `/etc/mysql/mysql.conf.d/mysqld.cnf`. ```bash sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf ``` After making changes, restart MySQL to apply the new settings. ```bash sudo systemctl restart mysql ``` #### Step 7: Create a New MySQL User (Optional) It's a good practice not to use the root account for regular database operations. Create a new MySQL user with appropriate privileges. 1. Log in to the MySQL shell. ```bash sudo mysql -u root -p ``` 2. Create a new user and grant privileges. ```sql CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES; ``` 3. Exit the MySQL shell. ```sql exit ``` Congratulations! You have successfully installed MySQL on your Ubuntu Server 22.04. For more tutorials and cloud solutions, visit EcoStack Cloud. ---


Created with ❤ at Estonia
EcoStack Technology OÜ