MySQL change data directory steps and Error (Error 2002 (HY000)) processing method

Source: Internet
Author: User

1. Turn off the MySQL service:

Service Mysqld Stop

2. Create a new directory
Mkdir-p data

3. Transfer the previous directory to the new data directory


mv/var/lib/mysql//data/

4, edit my.cnf

Vi/etc/my.cnf

Modify the DataDir and socket to a new path

[Mysqld]
Datadir=/data/mysql
Socket=/data/mysql/mysql.sock

5. Modify MySQL startup script/etc/init.d/mysql
Finally, the MySQL startup script needs to be modified/etc/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:/data/mysql

I thought I would be fine after I started the MySQL service.

Service mysqld Start
/etc/init.d/mysql start
However, although the service is not a problem to start, but the MySQL client connection when the error:

[Email protected] data]# mysql-u root-p
Enter Password:
ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2)



Note that you cannot connect to the MySQL server through the socket file/var/lib/mysql/mysql.sock, that is, for the MySQL program, although I transferred the socket file from/var/lib/mysql/mysql.sock to the /data/mysql/mysql.sock I specified in the my.cnf mysqld know, but for MySQL still will be from the default installation directory/var/lib/mysql/find this mysql.sock file, can not find, do not know where to start.

Solution One:

ln–s/data/mysql/mysql.sock/var/lib/mysql/

After the soft connection, restart the MySQL service, again through the MySQL program connection, no problem, can be connected.

[Email protected] lib]# mysql-u root-p
Enter Password:
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 3
Server version:5.0.77 Source Distribution

Copyright (c) and/or, Oracle, its affiliates. All rights reserved.

Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

Mysql>


That means it's the problem here.


Method Two: Actually do not do soft link is also possible, just need to add [MySQL] field in/etc/my.cnf to specify the location of the socket to the location after we transfer

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

Method Three: Modify Permissions

Chown-r mysql:mysql/data/mysql/
chmod 660/data/mysql/test/*

The above methods have been tested and practicable, and we hope to help you to change the catalogue.





MySQL change data directory steps and Error (Error 2002 (HY000)) processing method

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.