MySQL Modify database storage directory method and possible problems in Linux

Source: Internet
Author: User

MySQL version: 5.6.23-enterprise-commercial-advanced, using RPM installation
linux:red Hat Enterprise Linux Server release 6.3 (Santiago)
First, if it is Linux under the RPM package installed MySQL, the modified method is as follows:

The default data file storage directory for MySQL is/var/lib/mysql. The following steps are required if you want to move the directory to/home/data:
  1. Set up the data directory in the home directory
Cd/home
mkdir data
   2. Stop the MySQL service process:
Mysqladmin-u root-p shutdown
  3. Move/var/lib/mysql Entire directory to/home/data
mv/var/lib/mysql/home/data/
This will move the MySQL data file to/home/data/mysql.
   4. Locate the MY.CNF configuration file
If there is no MY.CNF configuration file under the/etc/directory, locate the *.cnf file under/usr/share/mysql/, and copy one of them to/etc/and rename it to MY.CNF). The command is as follows:
[Email protected] mysql]# CP/USR/SHARE/MYSQL/MY-MEDIUM.CNF/ETC/MY.CNF
  5. Edit the MySQL configuration file/etc/my.cnf
To ensure that MySQL works correctly, you need to indicate where the Mysql.sock file is generated. Modify the value in the Socket=/var/lib/mysql/mysql.sock line to the right of the equals sign:/home/mysql/mysql.sock. The operation is as follows:
VI my.cnf (Edit the My.cnf file with VI tool, find the following data to modify)
# The MySQL server
[Mysqld]
Port = 3306
#socket =/var/lib/mysql/mysql.sock (original content, in order to be more secure with "#" Comment this line)
Socket =/home/data/mysql/mysql.sock (plus this line)
   6. Modify MySQL startup script/etc/rc.d/init.d/mysql
Finally, the MySQL startup script needs to be modified/etc/rc.d/init.d/mysql, the path to the right of the equal sign in the Datadir=/var/lib/mysql line is changed to your current actual storage path: Home/data/mysql.
[Email protected] etc]# Vi/etc/rc.d/init.d/mysql
#datadir =/var/lib/mysql (Note this line)
Datadir=/home/data/mysql (plus this line)
   7. Restart MySQL service
/etc/rc.d/init.d/mysql start
or restart Linux with the reboot command

The following is the MySQL Data directory modification appears

Error 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2) Wrong solution:

This example is to move the MySQL data directory to the/home/data/, that is, Mysql.sock is located in the real directory,/home/data/mysql/mysql.sock

ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2)

MySQL has a TCP connection and socket connection, and the above error is generally because MySQL is installed using the RPM method, it will automatically find/var/lib/mysql/mysql.sock this file, is a socket connection method.

Common solutions are as follows:
1.
Create/Modify file/etc/my.cnf file, add on [mysqld]

[Client]
#password =your_password
port=3306
Socket=/home/data/mysql/mysql.sock
#在这里写上你的mysql. Sock the correct position.

2.
Specify an IP address to connect to MySQL using TCP instead of using the local socket method
#mysql-h127.0.0.1-uuser-ppassword

3.
Add a connection for mysql.sock, such as the actual mysql.sock under/home/data/mysql/, then
#ln-S/home/data/mysql/mysql.sock/var/lib/mysql/mysql.sock

[Email protected] lib]# ln-s/opt/data/mysql/mysql.sock/var/lib/mysql/"/var/lib/ Mysql/mysql.sock": No file or directory
Since the/var/lib/mysql entire directory is MV, you need to create a MySQL directory in the/var/lib/directory, and then create a symbolic link.

If it is under the Unbuntu system, use the following method ***********************

Shutting down the database service
Service MySQL Stop
Jianxin Database Directory
mkdir/media/hda11/db

Copy Linux under the original data to the new directory
cp-pr/var/lib/mysql/media/hda11/db/

Modify File/etc/apparmor.d/usr.sbin.mysqld
Gedit/etc/apparmor.d/usr.sbin.mysqld
Put
/var/lib/mysql R,
/var/lib/mysql/** Rwk,

Change into
/media/hda11/db/mysql R,
/media/hda11/db/mysql/** Rwk,

Modify Directory
Gedit/etc/mysql/my.cnf
Such as
DataDir =/var/lib/mysql replaced with DataDir =/media/hda11/db/mysql

Re-open the server
/etc/init.d/apparmor restart

Servcie MySQL Start

====================

from: http://blog.163.com/anonymous_ch/blog/static/206824190201391842558553/

MySQL Modify database storage directory method and possible problems in Linux

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.