数据目录更改后,mysql不连接

我更改了/etc/my.cnf中的数据目录。

datadir=/data/mysql socket=/data/mysql/mysql.sock 

我也从中移动了mysql文件夹

 /var/lib/mysql/ 

 /data/mysql 

现在,当我连接到MySQL我得到以下错误:

 [root@youradstats-copy mysql]# mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 

也当我看到/var/logs/msqld.log我得到以下消息:

 InnoDB: Setting log file /data/mysql/ib_logfile0 size to 512 MB InnoDB: Database physically writes the file full: wait... InnoDB: Progress in MB: 100 200 300 400 500 120704 7:43:31 InnoDB: Log file /data/mysql/ib_logfile1 did not exist: new to be created InnoDB: Setting log file /data/mysql/ib_logfile1 size to 512 MB InnoDB: Database physically writes the file full: wait... InnoDB: Progress in MB: 100 200 300 400 500 InnoDB: Cannot initialize created log files because InnoDB: data files are corrupt, or new data files were InnoDB: created when the database was started previous InnoDB: time but the database was not shut down InnoDB: normally after that. 120704 7:43:36 [ERROR] Plugin 'InnoDB' init function returned error. 120704 7:43:36 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 

在进行这些更改之前,我正确closures了mysql,然后正确启动了它,但不知道为什么要获取这些消息。 请帮忙解决问题,因为我已经改变了my.cnf中的套接字path,但仍然指向旧path…

检查是否在新的位置有套接字文件?

ls -la /data/mysql/mysql.sock

如果存在,权限是否正确? 告诉我们,如果你不确定。

如果存在,下一步是尝试:

 mysql -S /data/mysql/mysql.sock 

如果这样的话,你只需要改变my.cnf文件的[client]部分中的sock=/path/ 。 如果那里不存在,那么你应该创build它。

当您更改my.cnf文件的[client]部分中的内容时,不需要重新启动mysql。

另外,你发布的日志消息看起来好像没有正确复制你的/var/lib/mysql/目录下的数据,或者你有权限问题。 如果您不确定,请向我们显示ls -la /data/mysql/

您应该在/etc/my.cnf或/root/.my.cnf文件中有[mysql-client]部分,它定义了套接字的位置。

如果你阅读你的MySQL日志,它会告诉你需要重新启动数据库(/etc/init.d/mysqld restart)。