Home >Database >Mysql Tutorial >Discuss the steps to install MySQL in Linux system

Discuss the steps to install MySQL in Linux system

PHPz
PHPzOriginal
2023-04-17 09:48:36860browse

In Linux servers, installing MySQL is a basic configuration task. MySQL is an efficient database that can be installed and run under Linux systems.

In this article, we will discuss the steps and common installation directories to install MySQL in Linux systems.

  1. Installing MySQL

There are many ways to install MySQL on Linux systems, the most common is through a package manager, such as using apt-get on Debian and Ubuntu, Using yum on CentOS and Red Hat.

For example, to install MySQL on Ubuntu, you can type the following command in the terminal:

sudo apt-get update
sudo apt-get install mysql-server

On CentOS 8, you can use the following command to install MySQL:

sudo yum update
sudo yum install mysql-server

  1. MySQL installation directory

On Linux systems, installing MySQL usually stores files in the following directory:

  • /usr/bin
  • /usr/sbin
  • /var The /lib/mysql
  • /etc/mysql

/bin and /sbin directories contain MySQL binaries such as mysql and mysqld. The /var/lib/mysql directory is MySQL’s default data storage directory, and /etc/mysql is the storage directory for MySQL’s default configuration files.

  1. Modify the MySQL installation directory

In some cases, you may need to change the MySQL installation directory to a different directory. For example, if you installed MySQL on an external hard drive or other storage device, or you need to use some custom configuration files.

For this case, you can change the installation directory by specifying the new directory in the my.cnf configuration file or linking the MySQL data directory to the new directory.

First, you need to edit MySQL’s my.cnf configuration file. On Debian and Ubuntu, this file is located in the /etc/mysql directory, and on CentOS and Red Hat, the file is located in the /etc/my.cnf.d directory.

sudo nano /etc/mysql/my.cnf

Then you need to add the following line to specify the new data directory:

[mysqld]
datadir=/ my/mysql/data

For the new directory to take effect, you need to link the MySQL data directory to the new directory. For example, when changing the data directory to /my/mysql/data, you can use the following command:

sudo service mysql stop
sudo mv /var/lib/mysql /my/mysql/
sudo ln -s /my/mysql/data /var/lib/mysql
sudo chown -R mysql:mysql /my/mysql/data
sudo service mysql start

The above command will The /var/lib/mysql directory is moved to the /my/mysql directory and a symbolic link is created in the old location pointing to the new data directory.

  1. Summary

In a Linux system, installing MySQL is a basic configuration task. The MySQL installation directory usually includes the /bin, /sbin, /var/lib/mysql and /etc/mysql directories. If you need to change the MySQL installation directory, you can specify the new directory by editing the my.cnf configuration file, or link the data directory to the new directory.

The above is the detailed content of Discuss the steps to install MySQL in Linux system. 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