How to Install MySQL on Ubuntu
Before installing MySQL on Ubuntu, ensure you have an account with administrative (sudo) privileges and a network connection. Once you have these prerequisites, follow the steps below. Remember to press Enter after each command.
- Update your packages:
sudo apt update
Enter your password when prompted. - Upgrade your packages:
sudo apt upgrade
If prompted, pressY
and then Enter. - Install MySQL:
sudo apt install mysql-server
Enter your password if prompted, pressY
and then Enter. - Log in to MySQL Server:
sudo mysql -u root
Or, start MySQL with:sudo systemctl start mysql
MySQL will be installed on your machine. The installation time may vary depending on your internet speed. Once complete, you can check the installation with:
mysql --version
To check if MySQL is running:
sudo systemctl status mysql
Additional Steps for MySQL Configuration
After setting up MySQL on Ubuntu, consider these additional steps for configuration.
Secure Your MySQL Session
By default, there won’t be a password, but you can secure your installation:
sudo mysql_secure_installation
Enter your password, press Y
to confirm, follow the on-screen steps, and choose a password level.
Allow Remote Access
Enable remote access to connect to your databases from another machine:
sudo ufw enable
sudo ufw allow mysql
Launch MySQL at Reboot
To ensure your server runs each time you reboot your system:
sudo systemctl enable mysql
See Users
To view all users on a database:
SELECT User, Host, authentication_string FROM mysql.user;
We hope you find this guide helpful!