Home > Database > Mysql Tutorial > body text

Install mysql under linux

PHPz
Release: 2023-05-08 11:30:37
Original
2558 people have browsed it

MySQL is a very common relational database in Linux. For developers and system administrators, installing and configuring MySQL is one of the most important tasks in their daily work. This article will introduce how to install MySQL on the Linux operating system.

1. Install MySQL

To install MySQL on Linux, you can use the operating system's own package manager. Various Linux operating systems have different package managers. This article will cover the two most popular package managers - yum and apt-get.

Use yum to install MySQL:

  1. Open a terminal window and use administrator privileges or root user to install MySQL.

sudo yum -y install mysql-server

  1. The system will automatically download and install the MySQL server and its dependent packages.
  2. After the installation is complete, start the MySQL service.

sudo systemctl start mysqld

Install MySQL using apt-get:

  1. Open a terminal window and use administrator rights or Use root user to install MySQL.

sudo apt-get install mysql-server

  1. The system will automatically download and install the MySQL server and its dependent packages.
  2. After the installation is complete, start the MySQL service.

sudo systemctl start mysql

2. Configure MySQL

After the MySQL installation is completed, some configurations are required. Below we will introduce how to configure MySQL.

  1. Set the MySQL root user password.

By default, the MySQL root user does not have a password, so you need to set a password for the root user first to protect the database.

sudo mysql_secure_installation

This command will prompt you to set the password for the root user. After following the instructions and setting a new password, you will be asked several security questions, such as removing anonymous users, disabling root user remote access, etc. In order to enhance the security of MySQL, it is recommended that you answer "yes" to both.

  1. Log in to MySQL.

You can use the following command to log in to MySQL.

sudo mysql -u root -p

This command will prompt you to enter the password of the root user. After confirmation, you can log in to MySQL.

  1. Create new user.

In MySQL, it is not recommended to use the root user in the application. Instead, a new user should be created for the application. Here are the commands on how to create a new user.

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

Among them, newuser is the username of the new user, and localhost is the host where the new user is located Name or IP address, password is the password of the new user.

  1. Authorize new users.

After creating a new user, you need to authorize it. For example, the following command will grant the new user all operation permissions on all databases.

GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';

If you want to authorize new users to operate only on specific databases or tables, then A database or table needs to be specified.

  1. Exit MySQL.

After you complete all MySQL operations, you can enter the following command to exit MySQL.

exit

3. Conclusion

Installing MySQL on a Linux system may seem difficult, but in fact, as long as you follow the instructions, it It's very easy. Whether you are a developer or a system administrator, it is very important to learn how to install and configure MySQL well. It is recommended that you understand the basic knowledge and syntax of MySQL before using it so that you can use it better.

The above is the detailed content of Install mysql under linux. 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