linux下更改MySQL数据库存储路径

时间:2024-04-07 20:26:57

第1步:使用第三方软件SSH或xshell成功登录到centos系统。

第2步:home目录下建立data目录,data目录下建立mysql目录

linux下更改MySQL数据库存储路径

第3步:首先停止掉mysql服务,在终端中执行"/etc/init.d/mysql stop" 或者执行"service mysqld stop"并回车确定。

第4步: 把/var/lib/mysql整个目录移到/home/data/下

linux下更改MySQL数据库存储路径

第5步:修改mysql配置文件,执行“vim /etc/my.cnf”命令并确定。

linux下更改MySQL数据库存储路径

第6步:修改mysql配置文件,修改MySQL启动脚本/etc/init.d/mysqld。

执行"vim /etc/init.d/mysqld "(如果没有此文件,就不需要修改)

linux下更改MySQL数据库存储路径

第7步:重新启动MySQL服务
 service mysqld restart  或者/etc/init.d/mysqld start

linux下更改MySQL数据库存储路径

 

可能遇到的问题:

The server quit without updating PID file.

问题解析:

可能是没有将原数据库文件拷贝到新的目录下面,或者没有将新建的目录授权给mysql用户(chown -R mysql.mysql /home/data/mysql)

ps.补充,查看用户组 cat /etc/group

chown -R mysql.mysql /home/data/mysql

mysql数据库报错:InnoDB: Operating system error number 13 in a file operation

环境:centos6.5 x86_64

启动mysql发现日志报错(日志路径可以查看/etc/my.cnf的配置)

 

160722 10:34:08 [Note] Found 42570716 of 42570696 rows when repairing './[email protected]/room_msg'

160810  0:54:00 [ERROR] /usr/libexec/mysqld: Sort aborted
160810 10:41:55 [ERROR] /usr/libexec/mysqld: Sort aborted
160810 16:41:43 [ERROR] /usr/libexec/mysqld: Sort aborted
160823 11:34:45 mysqld_safe Starting mysqld daemon with databases from /home/data
160823 11:34:46 [Warning] Can't create test file /home/data/plugin.lower-test
160823 11:34:46 [Warning] Can't create test file /home/data/plugin.lower-test
160823 11:34:46 [Warning] option 'innodb-additional-mem-pool-size': signed value 200 adjusted to 524288
160823 11:34:46  InnoDB: Initializing buffer pool, size = 128.0M
160823 11:34:46  InnoDB: Completed initialization of buffer pool
160823 11:34:46  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
160823 11:34:46 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
160823 11:45:30 mysqld_safe Starting mysqld daemon with databases from /home/data
160823 11:45:30 [Warning] Can't create test file /home/data/plugin.lower-test
160823 11:45:30 [Warning] Can't create test file /home/data/plugin.lower-test
160823 11:45:30 [Warning] option 'innodb-additional-mem-pool-size': signed value 200 adjusted to 524288
160823 11:45:30  InnoDB: Initializing buffer pool, size = 128.0M
160823 11:45:30  InnoDB: Completed initialization of buffer pool
160823 11:45:30  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.

InnoDB: Cannot continue operation.

linux下更改MySQL数据库存储路径

发现系统启动只有几十分钟,说明服务器刚被人重启过,mysql服务无法启动

百度了下可能是selinux引起的,getenforce 发现问enforcing

setenforce 0

linux下更改MySQL数据库存储路径

并且修改配置vim /etc/sysconfig/selinux

SELINUX=disabled

linux下更改MySQL数据库存储路径

问题解决

转载原文:https://blog.csdn.net/weixin_34368949/article/details/94196444

mysql重启失败报错ibdata1 Can't determine file permissions

[ERROR] InnoDB: os_file_get_status() failed on './ibdata1'. Can't determine file permissions

mysql重启报错以上.

版本:mysql5.7+centos7.0

解决步骤:

    1、查看配置文件内容指定的pid-file

cat /etc/my.cnf
pid-file=/var/run/mysqld/mysqld.pid

    so,查看该目录是否存在。如没有,则创建,并修改属主属组。

ll /var/run/mysqld/
#不存在
mkdir -p /var/run/mysqld/
chown -R mysql:mysql /var/run/mysqld

    试着重启:

service mysqld restart

    如果还报错,则进入下一步。

    2、关闭selinux.并重启。

setenforce 0

    service mysqld restart

或者

   systemctl restart mysqld.service

转载原文链接:https://blog.csdn.net/agonisq/article/details/79817397