mysql-server 更改数据位置到 /data

通常会遇到MySQL数据盘不够用,但贸然更改数据存放位置、即使变更了 /etc/my.cnf 的数据目录指向位置,纵然权限一样,启动之时还会报如下错误:

[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).  2019-04-19T08:04:39.691961Z 0 [Warning] Can't create test file /data/mysql/localhost.lower-test 2019-04-19T08:04:39.692134Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.25) starting as process 10281 ...  2019-04-19T08:04:39.699760Z 0 [Warning] Can't create test file /data/mysql/localhost.lower-test
[Warning] Can't create test file /data/mysql/localhost.lower-test
[Note] InnoDB: PUNCH HOLE support available
[Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
[Note] InnoDB: Uses event mutexes
[Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
[Note] InnoDB: Compressed tables use zlib 1.2.11
[Note] InnoDB: Using Linux native AIO
[Note] InnoDB: Number of pools: 1
[Note] InnoDB: Using CPU crc32 instructions
[Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
[Note] InnoDB: Completed initialization of buffer pool
[Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
[Note] InnoDB: Highest supported file format is Barracuda.
[Note] InnoDB: Creating shared tablespace for temporary tables
[ERROR] InnoDB: Operating system error number 13 in a file operation.
[ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
[ERROR] InnoDB: Operating system error number 13 in a file operation.
[ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
[ERROR] InnoDB: Cannot open datafile './ibtmp1'
[ERROR] InnoDB: Unable to create the shared innodb_temporary
[ERROR] InnoDB: Plugin initialization aborted with error Cannot open a file
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[ERROR] Failed to initialize builtin plugins.
[ERROR] Aborting

【解决方案如下】

系统:

[root@localhost ~]# uname -a

Linux localhost.localdomain 3.10.0-957.10.1.el7.x86_64 #1 SMP Mon Mar 18 15:06:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

[root@localhost ~]# mysql --version

mysql  Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using  EditLine wrapper

步骤:

1、安装 MySQL 或者已经安装

更改 /etc/my.cnf 文件的数据指向目录,注释部分为原始配置:

#datadir=/var/lib/mysql

#socket=/var/lib/mysql/mysql.sock

datadir=/data/mysql

socket=/data/mysql/mysql.sock

2、关闭 selinux 测试是否可用:

setenforce 0

3、开启 MySQL 开机启动

systemctl enable mysqld

4、关闭 selinux 自动重启

更改 /etc/selinux/config  文件,注释部分为原始配置:

#SELINUX=enforcing

SELINUX=permissive

5、重启校验:

lsof -i:3306

 

你可能感兴趣的:(mysql,linux)