Home > Database > Mysql Tutorial > How to install and start MySQL in Ubuntu system

How to install and start MySQL in Ubuntu system

PHPz
Release: 2023-04-21 10:14:36
Original
3361 people have browsed it

MySQL is a popular relational database management system that supports multiple operating systems, such as Linux, Windows and Mac OS. In this article, we will introduce how to install and start MySQL in Ubuntu system.

1. Install MySQL

  1. Open the terminal and enter the following command to update the Ubuntu package list:
sudo apt-get update
Copy after login
  1. Then, enter the following command To install MySQL in Ubuntu system:
sudo apt-get install mysql-server
Copy after login
  1. During the installation process, you will be prompted to enter the MySQL root user password. Make sure to set a strong password and record it in a safe place.
  2. After the installation is complete, enter the following command to check whether the MySQL service has been started:
sudo systemctl status mysql
Copy after login

If the MySQL service has been started, "active (running)" will be displayed; otherwise, you The service needs to be started manually.

  1. If the MySQL service does not start successfully, you can use the following command to start the service manually:
sudo systemctl start mysql
Copy after login
  1. To ensure that the MySQL service starts automatically when the system starts, you You can enable it using the following command:
sudo systemctl enable mysql
Copy after login

2. Connect to the MySQL server

  1. After installing and starting MySQL, you can use the following command to connect to the MySQL server:
mysql -u root -p
Copy after login

This command will prompt you for the MySQL root user password. After entering your password, you will enter the MySQL shell.

  1. Once you enter the MySQL shell, you can start operations such as creating databases, tables, and users on the MySQL server.

3. Common MySQL commands

The following are some commonly used MySQL commands:

  1. Create database:
CREATE DATABASE dbname;
Copy after login
  1. Delete database:
DROP DATABASE dbname;
Copy after login
  1. Create table:
CREATE TABLE tablename (column1 datatype, column2 datatype, column3 datatype, ...);
Copy after login
  1. Delete table:
DROP TABLE tablename;
Copy after login
  1. Insert data:
INSERT INTO tablename (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Copy after login
  1. Query data:
SELECT column1, column2, ... FROM tablename WHERE condition;
Copy after login
  1. Update data:
UPDATE tablename SET column1 = value1, column2 = value2, ... WHERE condition;
Copy after login
  1. Delete Data:
DELETE FROM tablename WHERE condition;
Copy after login

4. Summary

MySQL is a relational database management system that is easy to learn, easy to use, safe and reliable. In this article, we introduce how to install and start MySQL in Ubuntu system, and introduce some commonly used MySQL commands. I hope this article will help you understand MySQL.

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

source:php.cn
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