mysql 修改data目录后 无法使用脚本启动

一、公司Mysql环境

#1. 目前公司Mysql只做了主从

#2. Mysql数据库版本:Percona-Server-server-56-5.6.20-rel68.0.el6.x86_64.rpm

二、Mysql从库的问题

Mysql从库一直都用命令启动:mysqld_safe --defaults-file=/etc/my.cnf & 。用/etc/init.d/mysql启动脚本一直报错。最郁闷的是在错误日志里没有记录启动错误信息。

我忍受了大半年的命令启动,终于不想再忍下去了。

之前一直以为/etc/my.cnf有问题,再尝试大半天时间后没有解决。 我决定还是卸载之前的mysql,重新安装mysql

卸载准备工作:

tar zcvf mysql.tar.gz  /data/mysql        # 备份mysql数据目录

mv  /etc/my.cnf  /etc/my.cnf.ori

删除

rm -rf /data/mysql

rpm -e Percona-Server-server-56-5.6.20

rpm -e Percona-Server-client-56-5.6.20

rpm -e Percona-Server-shared-56-5.6.20

安装

rpm -ivhPercona-Server-client-56-5.6.20-rel68.0.el6.x86_64.rpm Percona-Server-server-56-5.6.20-rel68.0.el6.x86_64.rpm Percona-Server-shared-56-5.6.20-rel68.0.el6.x86_64.rpm

#############################################

我以为会重新生成默认的/etc/my.cnf,发现没有。又找了一台服务器安装了mysql,导出默认的/etc/my.cnf

###################################

重装之后,在不修改默认配置是可以正常启动的。但只要导入生产/etc/my.cnf配置后又是错误

[[email protected]###### ~]# service mysql start

Starting MySQL (Percona Server).The server quit without upd[FAILED]D file (/home/mysql/mysql.pid).

再改回默认的/etc/my.cnf正常。 只要修改默认配置就出错。(真心折腾啊)

[mysqld]
datadir=/data/mysql      # 默认/var/lib/mysql
socket=/data/mysql/mysql.sock  # 默认/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/data/mysqld.log   # 默认/var/log/mysqld.log
pid-file=/data/mysqld/mysqld.pid   #/var/run/mysqld/mysqld.pid

幸运的是此次有了错误日志

[[email protected]###### data]# !tail

tail -20 /var/log/mysqld.log

160524 14:07:20 mysqld_safe Starting mysqlddaemon with databases from /data/mysql

2016-05-24 14:07:20 13213 [Warning] Can‘t create test file/data/mysql/mfs-data3.lower-test

2016-05-24 14:07:20 13213 [Warning] Can‘tcreate test file /data/mysql/mfs-data3.lower-test

/usr/sbin/mysqld: File‘/data/mysql/mysql-bin.index‘ not found (Errcode: 13 - Permission denied)

2016-05-24 14:07:20 13213 [ERROR] Aborting

花了点时间找到该错误是由selinux引起的。 关闭selinux

setenforce 0

sed -i "s#enforcing#disabled#g"  /etc/selinux/config

再次启动

[[email protected]###### mysql]# service mysql start

Starting MySQL (Percona Server)..The server quit without up[FAILED]ID file (/home/mysql/mysql.pid).

[[email protected] mysql]# cat log/mysql-error.log

160524 14:31:37 mysqld_safe Starting mysqld daemon with databases from /home/mysql/data/

2016-05-24 14:31:38 6632 [Warning] Can‘t create test file /data/mysql/data/*.lower-test

2016-05-24 14:31:38 6632 [Warning] Can‘t create test file /data/mysql/data/*.lower-test

/usr/sbin/mysqld: Can‘t change dir to ‘/data/mysql/data/‘ (Errcode: 2 - No such file or directory)

2016-05-24 14:31:38 6632 [ERROR] Aborting

思路:创建所需的目录

mkdir /data/mysql/{data,log} -p

发现问题依旧。后来仔细检查了生产的/etc/my.cnf

datadir                        = /data/mysql/data/

终于找到原因了:

之前创建新实例命令是:mysql_install_db  --user=mysql --datadir=/home/mysql

改为                mysql_install_db  --user=mysql --datadir=/data/mysql/data

再次使用/etc/init.d/mysql restart终于成功了。

[[email protected]###### data]# service mysql restart

Shutting down MySQL (Percona Server).. SUCCESS!

Starting MySQL (Percona Server).. SUCCESS!

三、恢复从库身份

之前主库一直有备份,所以不用担心在主库工作时间做主从同步了。

将主备份拷贝到从

[[email protected]##### tmp]# scp 192.168.2.105:/data/bak/all_2016-05-22.sql.gz ./

[email protected]‘s password:

all_2016-05-22.sql.gz                                                                                                                                                                                100%   21MB 20.9MB/s   00:00

[[email protected]##### tmp]# ls

all_2016-05-22.sql.gz

[[email protected] tmp]# gzip -d all_2016-05-22.sql.gz

[[email protected] tmp]# less all_2016-05-22.sql

-- MySQL dump 10.13 Distrib 5.6.20-68.0, for Linux (x86_64)

--

-- Host: localhost   Database:

-- ------------------------------------------------------

-- Server version      5.6.20-68.0-log

/*!40101 [email protected][email protected]@CHARACTER_SET_CLIENT */;

/*!40101 [email protected][email protected]@CHARACTER_SET_RESULTS */;

/*!40101 [email protected][email protected]@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8 */;

/*!40103 SET @[email protected]@TIME_ZONE */;

/*!40103 SET TIME_ZONE=‘+00:00‘ */;

/*!40014 SET @[email protected]@UNIQUE_CHECKS,UNIQUE_CHECKS=0 */;

/*!40014 [email protected][email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;

/*!40101 SET @[email protected]@SQL_MODE,SQL_MODE=‘NO_AUTO_VALUE_ON_ZERO‘ */;

/*!40111 SET @[email protected]@SQL_NOTES, SQL_NOTES=0*/;

--

-- Position to start replication or point-in-timerecovery from

--

-- CHANGE MASTER TO MASTER_LOG_FILE=‘mysql-bin.000042‘, MASTER_LOG_POS=142703;

--

-- Current Database: `decorate`

--

[[email protected]##### tmp]# service mysql status    # mysql服务器运行着

MySQL (Percona Server) running (17022)                     [  OK  ]

[[email protected] tmp]#mysql -uroot -p < all_2016-05-22.sql

Enter password:

[[email protected]##### tmp]# mysql -uroot -p     # 由于没有flush privileges,密码为空。害我输了好几次导入后的root密码

Enter password:

ERROR 1045 (28000): Access denied for user‘root‘@‘localhost‘ (using password: YES)

[[email protected]###### tmp]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.6.20-68.0-log Percona Server (GPL),Release 68.0, Revision 656

Copyright (c) 2009-2014 Percona LLC and/or itsaffiliates

Copyright (c) 2000, 2014, Oracle and/or its affiliates.All rights reserved.

Oracle is a registered trademark of Oracle Corporationand/or its

affiliates. Other names may be trademarks of theirrespective

owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear thecurrent input statement.

mysql> flushprivileges;   # 刷新下

Query OK, 0 rows affected (0.00 sec)

mysql> changemaster tomaster_host=‘192.168.2.105‘,master_port=3306,master_user=‘rep‘,master_password=‘password‘,MASTER_LOG_FILE=‘mysql-bin.000042‘,MASTER_LOG_POS=142703;    # 此命令已经可以盲打了

Query OK, 0 rows affected, 2 warnings (0.01 sec)

mysql> start slave;

Query OK, 0 rows affected (0.00 sec)

mysql> showslave status\G

*************************** 1. row***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 172.30.1.10

Master_User: slave

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000042

Read_Master_Log_Pos: 302454

Relay_Log_File: relay-bin.000002

Relay_Log_Pos: 160034

Relay_Master_Log_File: mysql-bin.000042

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 302454

Relay_Log_Space: 160201

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1

Master_UUID: c73c4373-34fd-11e4-a1bd-b82a72cf2c9f

Master_Info_File: /home/mysql/data/master.info

                    SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for theslave I/O thread to update it

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

1 row in set (0.00 sec)

####至此,全部搞定。 主从2分钟搞定,而且没出错,太顺利了,让我无法接受啊。

时间: 2024-08-11 04:13:11

mysql 修改data目录后 无法使用脚本启动的相关文章

处理更改 MySQL relay log 目录后 slave 无法启动故障

问题:更改 relay log 目录后 slave 无法启动 2018-08-03T02:53:36.172465Z 0 [ERROR] Failed to open the relay log './mysql03-relay-bin.000018' (relay_log_pos 9680848). 2018-08-03T02:53:36.172515Z 0 [ERROR] Could not find target log file mentioned in relay log info i

mysql通过data目录恢复数据库

mysql通过data目录恢复数据库 阅读:1236次   时间:2010-03-24 06:53:30   字体:[大 中 小] 重装系统后,MySQL服务没有了,但是数据库的文件还在,这个时候我想恢复以前的数据库, 起码要把数据导出来. MySQL重装N次,永远提示Could not start service error:0! 后来终于找到一个方儿,就是先把以前的库文件都拷贝出来,把以前的MySQL文 件全部清除,然后装个新的,这个时候MySQl可以正常启动了,然后在新的MySQL里建一个

CentOS下mysql数据库data目录迁移

公司新上线一个资讯网站,独立主机,raid5,lamp架构.由于资讯网是面向小行业,初步估计一两年内访问量压力不大,故,在做服务器系统搭建的时候,只是简单分出一个独立的data区作为数据库和网站程序的专区,其他按照linux的默认分区.apache,mysql,php均使用yum安装(也尝试过独立编译安装,但现实使用中,发现不如yum方便快捷,当然如果是大型应用型网站,估计就不是简单的yum了) 由于yum安装mysql的时候,数据库的data目录默认是在/var/lib下,出于数据安全性的考虑

Harbor修改/data目录位置

由于harbor默认数据存储位置在/data目录,且修改配置文件操作较为复杂,故这里使用软连接的方式将/data目录文件夹内容映射到/app目录下. 如何保证复制保持所属权限不变. 原文地址:https://www.cnblogs.com/lirunzhou/p/10522555.html

通过yum方式安装mysql默认安装后,修改data目录就无法启动

使用yum默认安装的路径:/var/lib/mysql 现在自定义的其它目录:/opt/programfile/mysql56/mysql3306 新建自定义目录 #mkdir -p /opt/programfile/mysql56/mysql3306 移动mysq默认目录下所有数据到指定目录(备注不能用copy,因为使用copy原目录下的权限可能发生改变) #mv /var/lib/mysql /opt/programfile/mysql56/mysql3306 启动mysql #system

mysql修改数据库目录

环境: OS:Red Hat Linux As 5 DB:MySql 5.5 在linux下安装好mysql后,默认的数据文件路径存放在/var/lib/mysql目录下,下面的步骤说明如将该目录下的数据文件迁移到其他目录. 1.创建数据库目录并将该目录权限属主修改为mysql[[email protected] /]# mkdir -p mysql/data[[email protected] /]# chown -R mysql:mysql ./mysql 2.停止mysql服务[[emai

CentOS下mysql数据库data目录迁移和配置优化

目录迁移 关闭数据库服务 service mysqld stop 复制数据库 mv /var/lib/mysql /data/mysql # 或者使用cp -a复制 # 这两个命令都会带权限到新目录去 修改配置文件 /etc/my.cnf [mysqld] #datadir=/var/lib/mysql ------原系统默认路径 datadir=/data/mysql ------现有路径 #socket=/var/lib/mysql/mysql.sock ------原socket路径现 s

将mysql的data目录移走方法

如移动到"/home/mysql/data",我的mysql是装在/usr/local/mysql下的 1. 将/usr/local/mysql/data移动到/home/mysql/data mv /usr/local/mysql/data /home/mysql/data 2. 修改启动文件 vi /usr/local/mysql/support-files/mysql.server 修改如下行,指定datadir datadir=/home/mysql/data 3. 修改配置文

mysql数据库迁移目录后slave报错

使用source /sql文件 导入数据库时,文件太大导致了超时. 后面使用scp -r 拷贝整个目录过去,启动slave报错.后来写了个脚本,批量修复: #!/bin/sh/usr/local/mysql/bin/myisamchk -of ./sundiszuzx/$1/usr/local/mysql/bin/myisamchk -r ./sundiszuzx/$1/usr/local/mysql/bin/myisamchk --safe-recover ./sundiszuzx/$1 原文