lnmp changes the storage directory of the MySQL database

To buy a cloud server now, it is generally recommended to buy a data disk, that is, separate the system disk and the data disk, and save the website files and Mysql database in the data disk. Even if there is a problem with the system disk or the environment, reset the system disk and reconfigure the environment. , Will not affect the data disk.

After configuring the LNMP environment, the default website directory and database storage directory are in the system disk, so we need to transfer them to the data disk.

Change the website file directory
If you are using Junge’s lnmp installation package, the default virtual host configuration environment is in the /usr/local/nginx/conf/vhost/ directory:

vi /usr/local/nginx/conf/vhost/域名.conf

You can open the corresponding virtual host configuration, and then modify the website directory. Then execute: cp -a old directory new directory, chown www:www -R new directory.

Change the MySQL directory
1. Stop the mysql server:

/etc/init.d/mysql stop
or
lnmp mysql stop

2. The following new directory takes /home/data/ as an example, and then copy the database of the old directory to the new directory:

cp -R /usr/local/mysql/ /home/data/

3. Grant the new directory to the mysql user group:

chown mysql:mysql -R /home/data/mysql/

4. Modify the configuration file:

vi /etc/my.cnf

Find [mysqld], modify datadir = /usr/local/mysql/var to datadir = /home/data/mysql/var and save

5. Start mysql:

/etc/init.d/mysql start

Guess you like

Origin blog.csdn.net/qq_39418742/article/details/101430049