Home >Database >Mysql Tutorial >How to install Linux mysql service

How to install Linux mysql service

PHPz
PHPzOriginal
2023-04-21 14:13:2211699browse

In the Linux operating system, MySQL is a popular relational database management system that can be installed and used on different platforms. This article will introduce how to install and configure the MySQL service in the Linux operating system.

1. Install MySQL

  1. In the Linux system, we first need to confirm whether we have installed the MySQL service. You can check it with the following command:

sudo service mysql status

If MySQL is not installed in the system, it will prompt that the MySQL service is not running, otherwise the running status of MySQL will be displayed.

  1. If it is not installed, you need to install MySQL first. You can use the following command to install on the Ubuntu system:

sudo apt-get install mysql-server

You can use the following command to install on the CentOS system:

sudo yum install mysql-server

At this point, the system will automatically download and install the MySQL service package.

  1. After the installation is complete, you can run the following command again to check the MySQL running status:

sudo service mysql status

2. Configure MySQL

  1. After MySQL is installed, some basic configuration needs to be done. You can use the following command to connect to the MySQL service:

mysql -u root -p

After connecting, you need to enter the password of the MySQL root user to enter the MySQL management interface.

  1. Generally, we need to create a new MySQL user. You can create it by following the steps below:

a. Enter the following command at the MySQL command line:

CREATE USER 'New user'@'localhost' IDENTIFIED BY 'Password';

Among them, the new user represents the user name you want to create, and the password is the password you set.

b. Authorize the database that new users can access:

GRANT ALL PRIVILEGES ON database name.* TO 'new user'@'localhost';

Among them, database Name the database you want to authorize.

  1. After the database configuration is completed, you need to restart the MySQL service to make it take effect. You can use the following command to complete this step:

sudo service mysql restart

At this time, the MySQL service has been installed and a new MySQL user has been successfully configured.

3. Using MySQL

In Linux systems, you can use the command line or MySQL GUI tools such as phpMyAdmin to manage MySQL databases.

  1. Using the command line

In the command line, you can use the following command to connect to the MySQL service:

mysql -u username-p

The username is the MySQL user name you created, and then enter the password to enter the MySQL management interface.

  1. Using GUI tools

If you are not familiar with the command line environment, you can also choose to use the MySQL GUI tool to manage the MySQL database. For example, phpMyAdmin is a popular MySQL management interface. You can use the following command to install phpMyAdmin:

sudo apt-get install phpmyadmin

After the installation is complete, you can enter the phpMyAdmin management interface by entering http://localhost/phpmyadmin in a web browser .

Database management can be easily performed through these tools. Such as creating a new database, creating a new data table, inserting data and other operations.

Summary

Installing and configuring the MySQL service in the Linux operating system is a basic task. In this article, we introduced how to install the MySQL service, perform some basic configurations on it, and finally introduced how to use the command line or the MySQL GUI tool to manage the MySQL database. Through these basic operations, you can easily manage data and improve work efficiency.

The above is the detailed content of How to install Linux mysql service. 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