一、前言
mariadb安装完成之后,默认的数据目录是/var/lib/mysql,为了避免空间增长/var空间不足,现在把数据目录移动至/data/soft/mysql。
二、具体操作步骤
1.关闭mariadb数据库
[root@centos7 ~]# systemctl stop mariadb.service
2.复制/var/lib/mysql到/data/soft/mysql
[root@centos7 soft]# cp -rp /var/lib/mysql/* /data/soft/mysql [root@centos7 soft]# ls -ld mysql/* -rw-rw---- 1 mysql mysql 16384 Apr 18 10:57 mysql/aria_log.00000001 -rw-rw---- 1 mysql mysql 52 Apr 18 10:57 mysql/aria_log_control -rw-rw---- 1 mysql mysql 18874368 Apr 18 10:57 mysql/ibdata1 -rw-rw---- 1 mysql mysql 5242880 Apr 18 10:57 mysql/ib_logfile0 -rw-rw---- 1 mysql mysql 5242880 Apr 18 10:55 mysql/ib_logfile1 drwx------ 2 mysql mysql 4096 Apr 18 10:55 mysql/mysql drwx------ 2 mysql mysql 4096 Apr 18 10:55 mysql/performance_schema drwx------ 2 mysql mysql 6 Apr 18 10:55 mysql/test
3.删除/var/lib/mysql目录,并创建对/data/soft/mysql的软链接
[root@centos7 lib]# rm -rf mysql [root@centos7 lib]# ln -s /data/soft/mysql/ mysql [root@centos7 lib]# ll mysql lrwxrwxrwx 1 root root 17 Apr 18 11:13 mysql -> /data/soft/mysql/ [root@centos7 lib]# ls -ld mysql/* -rw-rw---- 1 mysql mysql 16384 Apr 18 10:57 mysql/aria_log.00000001 -rw-rw---- 1 mysql mysql 52 Apr 18 10:57 mysql/aria_log_control -rw-rw---- 1 mysql mysql 18874368 Apr 18 10:57 mysql/ibdata1 -rw-rw---- 1 mysql mysql 5242880 Apr 18 10:57 mysql/ib_logfile0 -rw-rw---- 1 mysql mysql 5242880 Apr 18 10:55 mysql/ib_logfile1 drwx------ 2 mysql mysql 4096 Apr 18 10:55 mysql/mysql drwx------ 2 mysql mysql 4096 Apr 18 10:55 mysql/performance_schema drwx------ 2 mysql mysql 6 Apr 18 10:55 mysql/test
4.启动mariadb数据库
[root@centos7 lib]# systemctl start mariadb.service Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
报错:查看日志
[root@centos7 lib]# tail /var/log/mariadb/mariadb.log 160418 11:16:37 [Note] Server socket created on IP: '0.0.0.0'. 160418 11:16:37 [ERROR] Can't start server : Bind on unix socket: Permission denied 160418 11:16:37 [ERROR] Do you already have another mysqld server running on socket: /var/lib/mysql/mysql.sock ? 160418 11:16:37 [ERROR] Aborting 160418 11:16:37 InnoDB: Starting shutdown... 160418 11:16:38 InnoDB: Shutdown completed; log sequence number 1597945 160418 11:16:38 [Note] /usr/libexec/mysqld: Shutdown complete 160418 11:16:38 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
查看/var/run/mariadb目录权限:
[root@centos7 lib]# ls -ld /var/run/mariadb drwxr-xr-x 2 mysql mysql 40 Apr 18 10:57 /var/run/mariadb
这个没错啊...
查一下/data/soft/mysql的权限:
[root@centos7 lib]# ls -ld /data/soft/mysql drwxr-xr-x 5 root root 151 Apr 18 11:11 /data/soft/mysql
看来问题出在这了,授权所有者,所有组为mysql
drwxr-xr-x 5 root root 151 Apr 18 11:11 /data/soft/mysql [root@centos7 lib]# chown mysql.mysql /data/soft/mysql [root@centos7 lib]# ls -ld /data/soft/mysql drwxr-xr-x 5 mysql mysql 151 Apr 18 11:11 /data/soft/mysql
再次启动:
[root@centos7 lib]# systemctl start mariadb.service [root@centos7 lib]# lsof -i:3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 7275 mysql 14u IPv4 98512 0t0 TCP *:mysql (LISTEN)
ok,成功。
注意:刚在的复制按照下面的方式就不会出现这个错误。
cp -rp /var/lib/mysql /data/soft/
转载于:https://blog.51cto.com/zhangbei/1764958