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.

installation Article's
30 articles in total
Favicon
How to Install MySQL on Ubuntu
Favicon
Granite Worktops
Favicon
Bathroom Worktops
Favicon
Kitchen Worktops
Favicon
EdgeDB bare metal Installation and Configuration Script
Favicon
Step by Step Guide: How to Install Grafana on Ubuntu 24.04
Favicon
Anyone tried installing Docker on Ubuntu 24.04 ?
Favicon
How to Install Ubuntu 24.04 on Proxmox VE
Favicon
How to Install WordPress on Ubuntu 24.04 with Nginx and MariaDB
Favicon
How to install Python in Windows 11?
Favicon
Why Window Replacement is Key for Efficiency and Security
Favicon
Anaconda Installation and Virtual Environments: A Comprehensive Guide for Windows, Linux, and macOS
Favicon
How to Install or Download MongoDB 7 on Windows 10/11 | Step by Step Guide for Localhost
Favicon
How to install Python on Windows
Favicon
PYTHON INSTALLATION (IDLE & COLLAB Execution Test)
Favicon
How to install Python Libraries in Visual Studio Code
Favicon
Top 10 React js interview questions.
Favicon
pfSense Quickstart
Favicon
Outdoor LED display installation requirements and precautions
Favicon
Important details that are easily overlooked during LED module installation
Favicon
Install Java 17 On Linux in 2 Ways: Step-By-Step Guide
Favicon
Day 2: Setting Sail with Docker - Your First Steps in Installation and Setup
Favicon
Creating a Home Theater Experience with Soundproof Curtains
Favicon
Fixing RabbitMQ Startup issues
Favicon
DIY vs. Professional Installation: WiFi Access Points Compared
Favicon
Install Docker on Ubuntu 18.04
Favicon
Apache Kafka: Quickstart: Binary Deployment in Windows
Favicon
Installing Laravel Passport - A Comprehensive Guide
Favicon
Running Apache AGE using docker
Favicon
How to fix sudo docker compose - compose is not a docker command

Featured ones: