Linux下修改MySQL数据库数据文件路径的步骤

作者:虫文儿~ 时间:2024-01-19 13:53:41 

使用rpm安装方式安装完MySQL数据库后,数据文件的默认路径为/var/lib/mysql,然而根目录并不适合用于存储数据文件。

原路径:/var/lib/mysql

目标路径:/home/mysql_data/mysql

Linux系统版本:centos7.6

MySQL数据库版本:5.7.25

步骤:

1、创建目标路径

mkdir -p /home/mysql_data

2、关闭MySQL

systemctl stop mysqld

3、复制数据文件

cp -arp /var/lib/mysql /home/mysql_data

4、修改配置文件/etc/my.cnf

将datadir和socket中的原路径修改为目标路径


datadir=/home/mysql_data/mysql
socket=/home/mysql_data/mysql/mysql.sock

5、启动MySQL服务

systemctl start mysqld

NOTE:

1、报错如下:

2019-12-22T08:32:42.430564Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2019-12-22T08:32:42.430599Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2019-12-22T08:32:42.430616Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-12-22T08:32:42.430898Z 0 [ERROR] InnoDB: The innodb_temporary data file 'ibtmp1' must be writable
2019-12-22T08:32:42.430923Z 0 [ERROR] InnoDB: The innodb_temporary data file 'ibtmp1' must be writable
2019-12-22T08:32:42.430936Z 0 [ERROR] InnoDB: Could not create the shared innodb_temporary.
2019-12-22T08:32:42.430952Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2019-12-22T08:32:43.038973Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2019-12-22T08:32:43.039021Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2019-12-22T08:32:43.039037Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2019-12-22T08:32:43.039046Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-12-22T08:32:43.039056Z 0 [ERROR] Failed to initialize builtin plugins.
2019-12-22T08:32:43.039063Z 0 [ERROR] Aborting

解决:

执行命令:

setenforce 1

再重新启动

2、报错如下:

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

解决:

修改配置文件my.cnf,添加或修改如下配置:


[client]
socket = /home/mysql_data/mysql/mysql.sock

总结

以上所述是小编给大家介绍的Linux下修改MySQL数据库数据文件路径网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

来源:https://www.cnblogs.com/Lans-word/archive/2019/12/22/12080177.html

标签:mysql,数据,文件,路径
0
投稿

猜你喜欢

  • SqlServer 2005 T-SQL Query 学习笔记(2)

    2024-01-20 20:21:51
  • Python中turtle库常用代码汇总

    2021-02-24 06:50:38
  • SQL Server误区30日谈 第17天 有关页校验和的误区

    2024-01-27 17:48:47
  • Django+boostrap 美化admin后台的操作

    2022-02-26 16:16:21
  • Codeigniter控制器controller继承问题实例分析

    2023-11-23 04:15:31
  • 详解Python实现进度条的4种方式

    2023-07-05 13:31:16
  • python shutil操作文件实例讲解

    2022-05-20 06:42:08
  • 如何查询Top N及Top(M―N)记录?

    2009-11-11 20:03:00
  • 一文吃透Go的内置RPC原理

    2024-02-03 08:45:53
  • 如何用Python进行回归分析与相关分析

    2023-11-24 01:08:14
  • python threading模块操作多线程介绍

    2021-03-16 20:02:13
  • sqlserver中将varchar类型转换为int型再进行排序的方法

    2012-07-11 15:34:41
  • 如何安装2019Pycharm最新版本(详细教程)

    2022-09-19 12:20:54
  • 五个简单有效的Python清理数据脚本分享

    2021-11-01 08:08:50
  • Go语言的type func()用法详解

    2024-02-21 12:50:51
  • Python如何使用函数做字典的值

    2021-10-24 02:28:05
  • 常用ASP自定义函数集 (S.Sams)

    2010-05-27 12:24:00
  • Blender Python编程创建发光材质示例详解

    2022-08-20 21:06:19
  • python+jinja2实现接口数据批量生成工具

    2022-04-30 14:00:20
  • JavaScript中用getDate()方法返回指定日期的教程

    2024-05-09 09:05:46
  • asp之家 网络编程 m.aspxhome.com