CentOS Linux Change the MySQL database directory location

Introduction:
Because MySQL database is too large, installed by default / var disk has no longer accommodate the newly added data, there is no way, can only think of ways to transfer data directory.
Now I tidy up the MySQL transfer from below / var / lib / mysql directory to / home / mysql_data / mysql directory specific operations:
system maintenance  www.osyunwei.com   Reminder: qihang01 original content © Copyright, please indicate source and the original link
1, first we need to shut down MySQL, the command is as follows:
   Service mysqld STOP
2, and then transfer the data, for the period safety, we use the copy command cp, first find mysql original directory
   cd / var / lib
   LS
   run this command then you will see the mysql directory, and then execute the cp command
   cp -a mysql / home / mysql_data / # this put the database is copied to / home / mysql_data went below

  
Note: (- a This parameter must take, or copy over authority is not right.)
  
If the database is large, then the time will be longer, may time out, specifically how to set up ssh not time out of the way, please find their own Relevant information.
3, and then we modify the configuration file, a total of three, I gave the following explanation:
     Modify the first file: back up before modifying /etc/my.cnf /etc/my.cnfbak cp
     vi /etc/my.cnf
     open after modifying the datadir directory is / home / mysql_data / mysql
     the socket into /home/mysql_data/mysql/mysql.sock      # to be safe, you can comment out the original and re-add a line, change the current directory.
================================================== ================================
   modify the second file: cp /etc/init.d/ first backup before modifying /etc/init.d/mysqldbak mysqld
   VI /etc/init.d/mysqld
   Note: the exact position /etc/rc.d/init.d/mysqld, due to this there is a /etc/init.d / etc / rc.d / init.d mapping,
   it can be ordered with the above, is also simple.
   To whichdatadir = / var / lib / mysql row, right-hand side into the path you are now the actual storage path : / Home / mysql_data / MySQL
=================== ================================================== ============
   modify third file: make a backup before modifying cp / usr / bin / mysqld_safe / usr / bin / mysqld_safebak
   vi / usr / bin / mysqld_safe
   here is to modify directory datadir is / Home / mysql_data / MySQL
============================================= =====================================
4, the following need to establish a link mysql.sock:
   LN -s /home/mysql_data/mysql/mysql.sock /var/lib/mysql/mysql.sock
   system operation and maintenance  www.osyunwei.com   reminder: qihang01 original content © All rights reserved Please indicate the source and description link

   
   At this point all changes are completed, the following start MySQL
   Service mysqld Start
   or restart the Linux
   reboot
   if normal start, indicating successfully modified.

Guess you like

Origin www.cnblogs.com/littlehb/p/11430565.html