Jun Ge’s one-click LNMP tutorial: change the default mysql data to be stored in the data disk

888u

Last update at :2023-12-25,Edit by888u

In fact, it is relatively safer to store data on the data disk. In fact, I am now more interested in separating the website and the database! At present, many cloud hosting providers in mainland China have launched database storage services, but we will not discuss this today! For cloud hosting providers in mainland China such as Alibaba Cloud, Tencent Cloud, Western Digital, Huaxia Xiaoyun, etc., it is generally recommended to buy a data disk, that is, separate the system disk and data disk, and save website files and MySQL databases in the data disk. Even if there is a problem with the system disk or environment, resetting the system disk and reconfiguring the environment will not affect the data disk. After configuring the LNmp environment, the default website directory and database storage directory are both in the system disk, so we need to transfer them to the data disk.

Change 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. Modify:

vi /usr/local/nginx/conf/vhost/domain name.conf

You can open the corresponding virtual host configuration and then modify the website directory in it. Then execute:

cp -a old directory new directory
chown www:www -R new directory

Change the MySQL data storage directory
1. Stop the mysql server:

/etc/init.d/mysql stop

2. Take /storage/mysql/ as an example for the new directory below, and then copy the database of the old directory to the new directory:

cp -R /usr/local/mysql/var/* /storage/mysql/

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

chown mysql:mysql -R /storage/mysql/

4. Modify the configuration file again:

vi /etc/my.cnf

Find the original directory of mysql data /usr/local/mysql/var and change it to:

datadir = /storage/mysql
innodb_data_home_dir = /storage/mysql
innodb_log_group_home_dir = /storage/mysql

5. Start mysql:

/etc/init.d/mysql start

Recommended site search: overseas virtual host space, European server, Wanwang registered domain name, domain name free registration 0 yuan registration, Zhengzhou virtual host, mainland China virtual host, website agent registration, Japanese proxy server ip, foreign virtual space, check IP detailed address,

Jun Ge’s one-click LNMP tutorial: change the default mysql data to be stored in the data disk

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码