使用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数据库字符编码为UTF-8解决中文乱码
由于MySQL编码原因会导致数据库出现乱码. 解决办法: 修改MySQL数据库字符编码为UTF-8,UTF-8包含全世界所有国家需要用到的字符,是国际编码. 具体操作: 1.进入MySQL控制台 &g ...
linux下修改mysql数据库编码后无法启动解决办法
linux下老版本的Mysql修改数据库编码的方法是 修改my.cnf vi /etc/my.cnf 在[client]下添加 default-character-set=utf8 在[mysqld] ...
windows下数据库文件使用脚本同步到linux下的mysql数据库中
1.背景 windows server 2008 下 每天会有 *.sql数据文件 需要上传到linux 中的mysql数据库中 而运维人员是在 windows server 下使用 xshell 连 ...
Linux下实现mysql数据库每天自动备份
Linux下实现mysql数据库每天自动备份 1.基本操作步骤 a.创建备份目录 mkdir -m 777 /home/wwwroot/backup b.创建备份脚本sh vim /home/wwwr ...
linux下搭建mysql数据库
linux下搭建mysql数据库 1.下载mysql: http://dev.mysql.com/downloads/mysql/5.6.html#downloads wget http://dev. ...
Linux下重启mysql数据库的方法