Change the default mysql data stored on the data disk in Centos

Source: Internet
Author: User
Tags memory usage readline centos

Change the website file directory

If you are using the lnmp installation package of June, 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 modify the website directory. Then execute:

Cp-a old directory New Directory
Chown www: New www-R Directory
Change the MySQL data storage directory

1. Stop the mysql server:

/Etc/init. d/mysql stop

2. Take the new directory/storage/mysql/as an example, and copy the database in the old directory to the new directory:

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

3. Assign 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 mysql data directory/usr/local/mysql/var and modify it:

Datadir =/storage/mysql
Innodb_data_home_dir =/storage/mysql
Innodb_log_group_home_dir =/storage/mysql
5. Start mysql:
/Etc/init. d/mysql start

[Note]: Alibaba Cloud and Tencent ECS have two hard disks, one system disk and one data disk. By default, the data disk is not mounted, therefore, in addition to the system and environment software installed on the system disk, website data is also in the system disk, but the data disk is vacant and cannot take advantage of its space and distinguish between the benefits of system and data management.

How can I store website data on a data disk?
If you use the common LNmp one-click installation package to install the system environment, the default website root directory is/home/wwwroot.

There are two methods

1. Mount the file directly to the/home/wwwroot directory.
Follow the Alibaba Cloud official tutorial to create the directory # mkdir/home/wwwroot.
Replace/mnt with/home/wwwroot.


After completing these operations, install the LNmp one-key package.
2. The software is installed on the system disk, but the website data is stored on the data disk.
The LNmp is still installed in the system disk, and the data disk attaching of the Alibaba Cloud server is also based on the original operation.
You only need to change the default directory to/mnt when adding a website.
There are two advantages:
1. More data disk space can be used
2. Reinstalling the system or environment does not affect Website Data. Formatting the data disk does not affect website data.
* In addition, you can divide the data disk into another partition and mount one partition to the Database Directory, such as/usr/local/mysql. The same method is used.
* If the website has been created on the system disk, is there a way to migrate it to the data disk? Can the data disk be loaded to the home directory when the site is in the home directory?
Of course, you can first move the files in the/home directory to another directory, then mount the data disk to/home, and then move the data back.

[What if the mysql innodb database engine is not installed before lnmp is installed ?]

1. If you choose to install a mysql-5.5.37, you only need to modify the/etc/my. cnf configuration file.
First, let's take a look at how the centos. sh installation script determines whether to install innodb:
If [$ installinnodb = "y"]; then
Sed-I's: # innodb: g'/etc/my. cnf
Sed-I's:/usr/local/mysql/data:/usr/local/mysql/var: g'/etc/my. cnf
Else
Sed '/skip-external-locking/I \ default-storage-engine = MyISAM \ nloose-skip-innodb'-I/etc/my. cnf
Fi

According to the above command, we can modify/etc/my. cnf:

A. Locate loose-skip-innodb and comment out:

Default-storage-engine = MyISAM
# Loose-skip-innodb
Skip-external-locking

B. Search for innodb and cancel the note before innodb:

# Uncomment the following if you are using InnoDB tables
Innodb_data_home_dir =/usr/local/mysql/var
Innodb_data_file_path = ibdata1: 10 M: autoextend
Innodb_log_group_home_dir =/usr/local/mysql/var
# You can set .. _ buffer_pool_size up to 50-80%
# Of RAM but beware of setting memory usage too high
Innodb_buffer_pool_size = 16 M
Innodb_additional_mem_pool_size = 2 M
# Set .. _ log_file_size to 25% of buffer pool size
Innodb_log_file_size = 5 M
Innodb_log_buffer_size = 8 M
Innodb_flush_log_at_trx_commit = 1
Innodb_lock_wait_timeout = 50
Restart mysql to enable the innodb engine:

2. If you have unfortunately selected a lower version of mysql 5.1.73 and have not installed innodb, you have to recompile mysql. Of course, you can also upgrade mysql, you can also install innodb, but it is generally not recommended to upgrade and install innodb.

Let's take a look at the original compiled script of centos. sh:

Cd mysql-5.1.73/
If [$ installinnodb = "y"]; then
. /Configure -- prefix =/usr/local/mysql -- with-extra-charsets = complex -- enable-thread-safe-client -- enable-character er -- with-mysqld-ldflags =-all -static -- with-charset = utf8 -- enable-thread-safe-client -- with-big-tables -- with-readline -- with-ssl -- with-embedded-server -- enable-local -infile -- with-plugins = innobase
Else
. /Configure -- prefix =/usr/local/mysql -- with-extra-charsets = complex -- enable-thread-safe-client -- enable-character er -- with-mysqld-ldflags =-all -static -- with-charset = utf8 -- enable-thread-safe-client -- with-big-tables -- with-readline -- with-ssl -- with-embedded-server -- enable-local -infile
Fi
Make & make install

We need to re-compile mysql. Note that re-compilation will cause loss of original data. Please back up the data first:

Cd mysql-5.1.73/
. /Configure -- prefix =/usr/local/mysql -- with-extra-charsets = complex -- enable-thread-safe-client -- enable-character er -- with-mysqld-ldflags =-all -static -- with-charset = utf8 -- with-big-tables -- with-readline -- with-ssl -- with-embedded-server -- enable-local-infile -- with-plugins = innobase
Make & make install

Note: in June's script, this parameter -- enable-thread-safe-client appears twice. Remove one manually.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.