Linux Centos Migration MySQL data location

Source: Internet
Author: User

Linux Centos Migration MySQL data location

The database is now migrated due to an increase in traffic that causes the disk space on the system disk (20G) to be fully occupied. Mysqlis through yum the installation.

centos6.5mysql5.1

yumInstalled mysql Services

View mysqlThe installation path

Execute QuerySQL

'%dir% ';

datadiris the data path

Transfer operations
  • New mysql Data Catalog

    mkdir/data/mysqldata 
  • Stop MySQL Service

    Service Mysqld Stop

    Enter the password and wait for it to stop

  • /var/lib/mysqlcopy the entire directory to/data/mysqlData

    /var/lib/mysql /data/mysqldata/     
  • Modify a my.cnf file

    Cp/etc/my. cnf/etc/my. cnf.bakvim/etc/my. cnf  

    The file contents are as follows, need to be modified datadir , socket corresponding directories

    [mysqld]default-character-set=utf8#datadir=/var/lib/mysqldatadir=/Data/mysqldata/mysql # # # #socket =/var/lib/mysql/mysql.socksocket=/var/lib/mysql/mysql.sock ####user=mysql# disabling symbolic-links is recommended to Prevent assorted security riskssymbolic-links=0[mysqld_safe]log-error=/ var/log/mysqld.logpid-file=/< Span class= "Hljs-keyword" >var/run/mysqld/mysqld.pid [MySQL] default-character-set=utf8[client] default-character-set=utf8    
  • Modify MySQL startup script/etc/init.d/mysqld

    Vim/etc/init.d/mysqld
修改文件中`datadir`路径
"/data/mysqldata/mysql"

Because it is necessary to modify the '/usr/lib64/mysql/mysql_config ' file through the ' Yum ' installation

/usr/lib64/mysql/mysql_config

Modify Content

#ldata ='/var/lib/mysql ' ldata='/data/mysqldata/mysql '#socket ='/var/lib/mysql/mysql.sock ' socket= '/data/mysqldata/mysql/mysql.sock '    
    • Modify Permissions

      [Root@samplemysql: mysql/data/mysqldata/mysql     
Restart MySQL Service
Service mysqld Restart

Execute a querysql

'%dir% ';

datadirthe found path has changed and can run normally sql , proving that the data can be obtained normally.

Summarize

This operation is on the test server operation, the mood is still very tense, if need to operate the database on the line, must be cautious, must be cautious, must be cautious. Be sure to pay attention to backups. This migration is guaranteed to be completed in 20 minutes, thus reducing the loss.

Note: Warning:

: Warning: yum Modify/usr/lib64/mysql/mysql_config file as required by installation

Linux Centos Migration MySQL data location

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.