Home > Database > Mysql Tutorial > How to install mysql in a specified directory

How to install mysql in a specified directory

PHPz
Release: 2023-04-21 14:04:09
Original
2453 people have browsed it

MySQL is a popular open source relational database management system. When you install MySQL, by default it will be installed into the operating system's default directory. However, in actual work, sometimes it is necessary to install MySQL into a specified directory. In this article, we will discuss how to install MySQL to a specified directory in a Linux system.

1. Preparation

Before installing MySQL, you need to install the necessary dependency packages. On a Linux system, you can use the following command to install the necessary dependency packages:

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install libncurses-dev
sudo apt-get install libtool
Copy after login

2. Download MySQL

Before installing MySQL, you need to download it from the official website of MySQL (https://dev .mysql.com/downloads/mysql/) to download the latest version of MySQL. After downloading, you need to unzip the MySQL source code package. The command is as follows:

tar zxvf mysql-*.tar.gz
Copy after login

You may need to replace the * sign to match the MySQL version you downloaded.

3. Configure MySQL

After decompressing the MySQL source code package, you need to use the following command to enter the MySQL source code directory:

cd mysql-*
Copy after login

Then run the following command to configure MySQL:

./configure --prefix=/usr/local/mysql
Copy after login

This command installs MySQL into the /usr/local/mysql directory. If you want to install MySQL to a different directory, replace the directory path in the above command.

Next, we need to run the following command:

make
sudo make install
Copy after login

This command will start compiling the MySQL source code and install it into the specified directory.

4. Configure MySQL environment variables

After installing MySQL, we need to add the installation directory to the system's environment variables. This can be achieved by editing the ~/.bashrc file:

nano ~/.bashrc
Copy after login

Please add the following to the end of the file:

export PATH=$PATH:/usr/local/mysql/bin
Copy after login

Then press CTRL X, then Y, and finally Enter to save the file and exit nano editor.

Then run the following command for the changes to take effect:

source ~/.bashrc
Copy after login

Now you can verify that the MySQL environment variable was added successfully. Just run the following command:

mysql
Copy after login

If the MySQL command line interface can be opened normally, it means that MySQL has been successfully installed into the specified directory.

Summary

It is very simple to install MySQL to a specified directory on a Linux system. Just follow the steps above. If you need to install MySQL on other platforms, please refer to the official MySQL documentation.

The above is the detailed content of How to install mysql in a specified directory. 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