MySQL modifies the default data store directory

Source: Internet
Author: User

Today, I installed MySQL on Linux, which is a centos system, and I use Yum to install it.

Yum install mysql-server mysql-devel mysql

There are some problems when modifying the storage directory of the data, recording the steps.

Default data store directory:/var/lib/mysql

My modified storage directory:/data/mysqldata/mysql


MySQL Modify Data directory:


1. Stop MySQL Service
Service Mysqld Stop


2, copy the original data to the new directory, the new directory does not exist please create
Mkdir-p/data/mysqldata/mysql
cp-fr/var/lib/mysql/*/data/mysqldata/mysql


3. Modify Directory Permissions
Chown Mysql:mysql-r/data/mysqldata/mysql


4. Modify the configuration file
Vi/etc/my.cnf

Modify:
Datadir=/data/mysqldata/mysql
Socket=/data/mysqldata/mysql/mysql.sock

Add to:

[MySQL]
Socket=/data/mysqldata/mysql/mysql.sock

Attach my.cnf file

[Mysqld] #datadir =/var/lib/mysqldatadir=/data/mysqldata/mysql#socket=/var/lib/mysql/mysql.socksocket=/data/ mysqldata/mysql/mysql.sockuser=mysql# disabling symbolic-links is recommended to prevent assorted security Riskssymbolic-links=0[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid[mysql] Socket=/data/mysqldata/mysql/mysql.sock



Vi/etc/init.d/mysqld
DataDir "/data/mysqldata/mysql"


5. Prevent SELinux

Chcon-r-T Mysqld_db_t/data/mysqldata/mysql

(If step 6, start the following error, use the fifth step method of processing)

141209 23:52:32 [Warning] Can ' t create test file/data/mysqldata/mysql/localhost.lower-test141209 23:52:32 [Warning] Can ' t create test File/data/mysqldata/mysql/localhost.lower-test/usr/libexec/mysqld:can ' t find file: './mysql/ Plugin.frm ' (errno:13) 141209 23:52:32 [ERROR] Can ' t open the Mysql.plugin table. Please run Mysql_upgrade to create it.


6. Start the MySQL service

Service mysqld Start


MySQL modifies the default data store directory

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.