Home  >  Article  >  Database  >  How to Install MySQL on Ubuntu

How to Install MySQL on Ubuntu

DDD
DDDOriginal
2024-10-23 12:36:30295browse

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

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

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

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

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

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;
  1. Creating a New User:
CREATE USER 'nama_pengguna'@'localhost' IDENTIFIED BY 'password';
  1. Grant Access Rights:
GRANT ALL PRIVILEGES ON nama_database.* TO 'nama_pengguna'@'localhost';
  1. Applying Changes:
FLUSH PRIVILEGES;

Step 7: Exiting from MySQL

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

EXIT;

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!

Statement:
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