Home > Database > Mysql Tutorial > body text

How to Install MySQL on Ubuntu

DDD
Release: 2024-10-23 12:36:30
Original
292 people have browsed it

Cara Install MySQL di Ubuntu

MySQL is one of the most popular and widely used relational database management systems in the world. In this article, we will discuss the steps to install MySQL on the Ubuntu operating system.

Step 1: Update the Package List

Before starting the installation process, it is highly recommended to update your system package list. Open a terminal and run the following command:

sudo apt update
Copy after login

Step 2: Installing MySQL Server

Once the package list is updated, you can proceed with installing MySQL server. Use the following command:

sudo apt install mysql-server
Copy after login

During the installation process, you may be asked to confirm the installation. Type Y and press Enter to continue.

Step 3: Securing MySQL Installation

After the installation is complete, it is important to secure your MySQL installation. You can do this by running MySQL's built-in security script:

sudo mysql_secure_installation
Copy after login

This script will ask for several options, such as:

  • Set a password for the root user.
  • Deleting anonymous users.
  • Prohibits remote root login.
  • Deleting the test database.

We recommend that you choose the option that suits your needs.

Step 4: Checking MySQL Status

After securing the installation, you can check whether the MySQL service is running properly. Use the following command:

sudo systemctl status mysql
Copy after login

If MySQL is running, you will see the status "active (running)".

Step 5: Accessing MySQL

Now you are ready to access MySQL. Run the following command to enter the MySQL console:

sudo mysql -u root -p
Copy after login

You will be asked to enter the password that you set previously.

Step 6: Create a New Database and User (Optional)

After logging into the MySQL console, you can create new databases and users if necessary. Here is an example of how to create a new database and user:

  1. Create Database:
CREATE DATABASE nama_database;
Copy after login
  1. Creating a New User:
CREATE USER 'nama_pengguna'@'localhost' IDENTIFIED BY 'password';
Copy after login
  1. Grant Access Rights:
GRANT ALL PRIVILEGES ON nama_database.* TO 'nama_pengguna'@'localhost';
Copy after login
  1. Applying Changes:
FLUSH PRIVILEGES;
Copy after login

Step 7: Exiting from MySQL

Once finished, you can exit the MySQL console with the command:

EXIT;
Copy after login

Conclusion

You have now successfully installed MySQL on Ubuntu and secured it. You have also learned how to create new databases and users. With these steps, you are ready to start using MySQL for your projects!

If you have any questions or encounter any problems during the installation process, don't hesitate to ask. Good luck!

The above is the detailed content of How to Install MySQL on Ubuntu. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!