You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MySQL is one of the most widely used relational database management systems (RDBMS) worldwide. Installing MySQL on Ubuntu is a common requirement for web applications, server deployments, and database management. This guide will walk you through the entire process of setting up MySQL on Ubuntu step-by-step. We'll also reference trusted resources and provide solutions for common issues.
After installation, you must start the MySQL service and enable it to run automatically at boot:
sudo systemctl start mysql
sudo systemctl enable mysql
Check whether MySQL is running with the following command:
sudo systemctl status mysql
You should see output indicating that the MySQL service is active and running.
🔒 Step 4: Run the MySQL Secure Installation
After installation, secure your MySQL server by running the mysql_secure_installation script. This script configures important security settings:
sudo mysql_secure_installation
You’ll be prompted with the following options:
Set a root password: If the MySQL root password hasn't been set, you'll set it here.
Remove anonymous users: Deletes accounts without associated users for better security.
Disallow root login remotely: Ensures the MySQL root user can only connect locally.
Remove test database and access to it: Eliminates a default database used for testing.
Reload privilege tables: Ensures that changes take effect.
Respond to the prompts as per your security preferences. Press Y (yes) to apply changes.
🖥️ Step 5: Log into MySQL
You can access the MySQL server using:
sudo mysql -u root -p
You will be prompted to enter the root password you set earlier.
🔄 Step 6: Create a New MySQL User
While using the root user is fine for administrative tasks, it's a best practice to create new users with limited privileges for database security.
CREATEUSER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON*.* TO 'your_username'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
Replace your_username and your_password with your desired credentials.
🔍 Step 7: Verify Installation
Check the MySQL version to ensure everything is set up correctly:
mysql --version
You should see output similar to:
mysql Ver 8.x.x for Linux on x86_64 (Ubuntu)
💡 Common Issues & Troubleshooting
1. MySQL Service Not Starting
If the MySQL service fails to start, you can check the error logs:
sudo journalctl -xe | grep mysql
This will give you clues about what’s going wrong. You can restart the service using:
sudo systemctl restart mysql
2. Error on realpath() Issue
Sometimes you may encounter errors like:
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
This means MySQL directories weren’t initialized properly. Remove previous MySQL data and reinitialize:
Installing MySQL on Ubuntu should now be a straightforward task with this guide. If you encounter any issues during installation or configuration, refer to Vultr's official MySQL installation and troubleshooting documentation for quick solutions.
Whether you are setting up MySQL for a small project, web server, or enterprise-grade application, this guide has all the basic steps you’ll need to get started. For further help or server management tips, the Vultr resources linked above are an excellent starting point.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
MySQL is one of the most widely used relational database management systems (RDBMS) worldwide. Installing MySQL on Ubuntu is a common requirement for web applications, server deployments, and database management. This guide will walk you through the entire process of setting up MySQL on Ubuntu step-by-step. We'll also reference trusted resources and provide solutions for common issues.
For additional guidance or technical assistance, you can check the Detailed Guide on MySQL Installation on Ubuntu 20.04
🛠️ Prerequisites
Before starting the installation process, ensure that your system meets the following prerequisites:
You can verify your Ubuntu version with this command:
🔄 Step 1: Update Your System
It's essential to ensure your package repositories are up-to-date to avoid compatibility issues:
This will refresh the package list and install the latest updates for your system.
Step 2: Install the MySQL Server
Now, install MySQL using the default Ubuntu package manager:
This command installs the MySQL database server on your system.
** Step 3: Start and Enable the MySQL Service**
After installation, you must start the MySQL service and enable it to run automatically at boot:
sudo systemctl start mysql sudo systemctl enable mysql
Check whether MySQL is running with the following command:
You should see output indicating that the MySQL service is active and running.
🔒 Step 4: Run the MySQL Secure Installation
After installation, secure your MySQL server by running the
mysql_secure_installation
script. This script configures important security settings:You’ll be prompted with the following options:
Respond to the prompts as per your security preferences. Press
Y
(yes) to apply changes.🖥️ Step 5: Log into MySQL
You can access the MySQL server using:
You will be prompted to enter the root password you set earlier.
🔄 Step 6: Create a New MySQL User
While using the root user is fine for administrative tasks, it's a best practice to create new users with limited privileges for database security.
Replace
your_username
andyour_password
with your desired credentials.🔍 Step 7: Verify Installation
Check the MySQL version to ensure everything is set up correctly:
You should see output similar to:
💡 Common Issues & Troubleshooting
1. MySQL Service Not Starting
If the MySQL service fails to start, you can check the error logs:
sudo journalctl -xe | grep mysql
This will give you clues about what’s going wrong. You can restart the service using:
2.
Error on realpath()
IssueSometimes you may encounter errors like:
This means MySQL directories weren’t initialized properly. Remove previous MySQL data and reinitialize:
sudo rm -rf /var/lib/mysql/* sudo mysqld --initialize sudo systemctl restart mysql
** Additional Resources**
For advanced installation options, security enhancements, and database management tips, refer to these helpful guides:
Guide: How to Install MySQL on Ubuntu
Mysql Database Management Guide
Automated Backups Guide for server
Final Thoughts
Installing MySQL on Ubuntu should now be a straightforward task with this guide. If you encounter any issues during installation or configuration, refer to Vultr's official MySQL installation and troubleshooting documentation for quick solutions.
Whether you are setting up MySQL for a small project, web server, or enterprise-grade application, this guide has all the basic steps you’ll need to get started. For further help or server management tips, the Vultr resources linked above are an excellent starting point.
Good luck!
Beta Was this translation helpful? Give feedback.
All reactions