Logo

dev-resources.site

for different kinds of informations.

How to Install MySQL on Ubuntu

Published at
12/31/2024
Categories
ubuntu
linux
installation
mysql
Author
s3cloudhub
Categories
4 categories in total
ubuntu
open
linux
open
installation
open
mysql
open
Author
10 person written this
s3cloudhub
open
How to Install MySQL on Ubuntu

Image description

If you’re looking to set up MySQL on your Ubuntu machine, you’re in the right place! MySQL is one of the most popular relational database management systems, and installing it on Ubuntu is a straightforward process. Whether you’re developing locally or setting up a production server, follow these simple steps to get MySQL up and running on your Ubuntu system.

Step 1: Update Your System

Before installing MySQL, it’s always a good idea to update your system to ensure all the packages are up to date. Open your terminal and run the following command:

sudo apt update
Enter fullscreen mode Exit fullscreen mode

This command will refresh the package list from the repositories. You can also upgrade the existing packages:

sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

Step 2: Install MySQL Server

Once your system is updated, you can install the MySQL server package. Run the following command:

sudo apt install mysql-server
Enter fullscreen mode Exit fullscreen mode

This command installs the latest version of MySQL from Ubuntu’s official repository. During installation, it may prompt you for your sudo password, so be sure to enter it.

Step 3: Secure MySQL Installation

After MySQL is installed, it’s crucial to secure your installation by running a built-in script. This script will help remove insecure default settings. To run the script, use the command:

sudo mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode

You’ll be asked a series of questions:

Set a root password (if not already set during installation).
Remove insecure default settings (e.g., sample users, test databases).
Disable remote root login.
Remove the test database.
It’s highly recommended to answer “Y” to most of the questions to improve your MySQL installation’s security.

Step 4: Check MySQL Status

Once the installation is complete, you can check whether MySQL is running with the following command:

sudo systemctl status mysql
Enter fullscreen mode Exit fullscreen mode

You should see output indicating that the MySQL service is active and running. If it’s not running, you can start it with:

sudo systemctl start mysql
Enter fullscreen mode Exit fullscreen mode

You can also enable MySQL to start on boot by using:

sudo systemctl enable mysql

Step 5: Log in to MySQL

To access the MySQL shell, use the following command:

sudo mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

Enter the root password you set during the installation. Once logged in, you’ll be presented with the MySQL command prompt, where you can start creating databases, tables, and managing users.

Step 6: Create a New Database (Optional)

Now that you’re logged in, let’s create a new database for your projects. Run the following SQL commands:

CREATE DATABASE mydatabase;
Enter fullscreen mode Exit fullscreen mode

To verify the database was created, use the command:

SHOW DATABASES;
Enter fullscreen mode Exit fullscreen mode

You should see your new database listed.

Conclusion

Congratulations! You’ve successfully installed MySQL on your Ubuntu machine. You’re now ready to start using MySQL for your applications or projects. Always remember to secure your database and back up your data regularly to avoid any unforeseen issues. If you need to learn more about MySQL, there are plenty of resources available to dive deeper into advanced database management techniques.

ubuntu Article's
30 articles in total
Favicon
Configurar servidor de archivos local con Ubuntu y Samba
Favicon
How to install Jenkins in ubuntu
Favicon
Update WSL Ubuntu password
Favicon
Change keyboard to Spanish distribution on Ubuntu Server
Favicon
How to Automate CI/CD Pipelines with GitHub Actions
Favicon
Critical Section Problem: Process Synchronization
Favicon
Reader Writer Problem: Process Synchronization
Favicon
Protection and Security: Operating System
Favicon
Storage Management: Operating System
Favicon
Getting Cilium to work on Ubuntu Cloud Image
Favicon
Process Management: Operating System
Favicon
KillPy: The Tool to Clean Up Your Python Virtual Environments 🧹🐍
Favicon
Introduction to Operating System
Favicon
Comprehensive Guide: Setting Up Gestures on Linux (Debian-Based Distributions)
Favicon
Ubuntu Linux Commands Categorized
Favicon
How to Set Up OpenShift Local (CRC) on Ubuntu: A Developer's Guide
Favicon
Fixing OpenVPN Connection Issues in Ubuntu 24.04
Favicon
How to Install MySQL on Ubuntu
Favicon
How to read ip addr output on Linux
Favicon
Enhancing Outdoor Adventures: How Technology Brings You Closer to Nature
Favicon
Memory Management: Operating System
Favicon
How to Change the Background in Ubuntu Terminal
Favicon
How to Install Wireshark on Ubuntu
Favicon
Process Synchronization and Deadlock: Operating System
Favicon
Implementasi Infrastruktur Jaringan Virtual dengan Protokol OSPF
Favicon
วิธีติดตั้งและกำหนดค่าเบื้องต้นสำหรับเซิร์ฟเวอร์ DNS บน Ubuntu 22.04 LTS แบบง่าย ๆ
Favicon
How to Fix No Internet Connection in Digital Ocean's Droplet
Favicon
การทำ HTTPS ด้วย Certbot และ Nginx บน Ubuntu Server
Favicon
Short: User Data file for Ubuntu based AWS ec2 instance with docker and docker compose.
Favicon
How to Change Your Password Securely

Featured ones: