Home >Database >Mysql Tutorial >How to install mysql in a specified directory
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
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
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-*
Then run the following command to configure MySQL:
./configure --prefix=/usr/local/mysql
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
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
Please add the following to the end of the file:
export PATH=$PATH:/usr/local/mysql/bin
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
Now you can verify that the MySQL environment variable was added successfully. Just run the following command:
mysql
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!