一个mysql的问题l

错误代码2003 不能连接到Mysql服务器在llocalhost上
如果出现"ERROR 2003: Can't connect to MySQL server on 'localhost' (10061)", 说明你的MySQL还没有启动。
假设默认安装在C:盘
解决办法:
删除c:\windowns下面的 i
打开c:\mysql\bin\winmysqladmin.exe 输入用户名 和密码
第三步 在dos下 输入 mysqld-nt -remove 删除服务
在接着输入 mysqld-nt -install
第四步 输入mysql 启动成功
启动这台机器上的MySQL服务
如服务启动失败,一定是你的 i文件出了差错, MySQL服务不能正常启动
你删除了它后,MySQL就会按其默认配置运行,那就没有问题了
如果你mysql 不是安装在C盘,或者默认设置不再C盘的,搜索 i就可以了。
其他答案(共2个回答)

2.请说明你是用什么链接的MySql服务器,确定你的MySql是安装在本机上吗?确定你的用户名和密码正确吗?
PS:如果你也是编程人员的话请把你的异常贴出来,谢谢
补充:
1.检查是否启动了 mysql 服务。
windows 主机的话,右键点击我的电脑,单击管理,在服务和应用程序中找到 mysql 服务,看是否是已启动的状态。
2....
1....localhost是本地~~~无需相关信息。
2.请说明你是用什么链接的MySql服务器,确定你的MySql是安装在本机上吗?确定你的用户名和密码正确吗?
PS:如果你也是编程人员的话请把你的异常贴出来,谢谢
补充:
1.检查是否启动了 mysql 服务。
windows 主机的话,右键点击我的电脑,单击管理,在服务和应用程序中找到 mysql 服务,看是否是已启动的状态。
2.检查磁盘空间是否还有剩余可用空间,尽量保持有足够的磁盘空间可用。
3.检查
i 里的 basedir (mysql 安装地址) 和 datadir (数据目录存放地址)等参数设置是否正确,然后重新启动下 mysql 服务。
数据导出功能。
无法10.141.11.55:6379,连接到Redis的服务器错误111连接被拒绝
配置SQL联接时,一般可以使用WINDOWS登录ID验证,或者数据库本身的用户登录ID验证。
看你的错误提示信息:用户’HYCWB\Guest'登录失败!
呵呵~奇迹版真是垃圾啊~
不用外挂就相你说的一样很难进去啊~
一般原因是9C的版本和我们用的计算机系统不兼容~容易出现你说的问题~
我的机子更加郁闷~
答: 大家下载的都是什么宫缩记录仪软件?
答: 好在有许多成熟的安全和网络技术,例如虚拟私有网络(VPN)和防火墙等,能够极大地提高Web服务应用的安全和性能,让开发者拥有选择安全技术的自由,而不是非得使用尚...
答: 某些ADSL调制解调器使用USB接口与电脑相连,需要在电脑上安装指定的软件以添加虚拟网卡来进行通信
大家还关注
确定举报此问题
举报原因(必选):
广告或垃圾信息
激进时政或意识形态话题
不雅词句或人身攻击
侵犯他人隐私
其它违法和不良信息
报告,这不是个问题
报告原因(必选):
这不是个问题
这个问题分类似乎错了
这个不是我熟悉的地区
相关问答:123456789101112131415MySQL无法启动几种常见问题小结
字体:[ ] 类型:转载 时间:
在群里看到有新同学还在问MySQL无法启动的问题,于是总结了几个常见情况与解决方法,需要的朋友可以参考下
昨天在群里看到有新同学还在问MySQL无法启动的问题,于是总结了几个常见情况,权当普及帖了,老鸟自觉飞过。 问题1:目录、文件权限设置不正确 MySQL的$datadir目录,及其下属目录、文件权限属性设置不正确,导致MySQL无法正常读写文件,无法启动。 错误信息例如:
代码如下:[code] mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data /usr/local/mysql/bin/mysqld_safe: line 107: /usr/local/mysql/data/imysql.local.err: Permission denied
问题2:端口冲突 已有其他mysqld实例启动,且占用了相同端口,需要修改 port 选项。 错误信息例如:
代码如下: [ERROR] Can't start server: Bind on TCP/IP port: Address already in use [ERROR] Do you already have another mysqld server running on port: 3306 ? [ERROR] Aborting
问题3:innodb配置不正确 innodb中关于datafile、log file设置不正确,导致无法启动。尤其是第一次用默认参数启动过,后来又参考一些优化指南后,修改了innodb的参数,会提示different size,详细错误例如:
代码如下: InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes InnoDB: than specified in the .cnf file 0
bytes! [ERROR] Plugin ‘InnoDB' init function returned error. [ERROR] Plugin ‘InnoDB' registration as a STORAGE ENGINE failed.
问题4:没有初始化mysql系统库 MySQL安装完后,需要运行mysql_install_db初始化mysql这个系统库,才能正常启动。 问题5:如果将mysql以普通用户权限运行的时候需要注意一些目录权限与用户名密码设置有时候为了让mysql更安全一些,我们都会将,由于一些安全设置工具的原因,需要将此用户重新设置一下密码就可以了。本次先列举上述几个常见问题,下次再补充。 通常地,碰到mysqld进程无法启动时,不管任何错误,都优先检查错误日志(日志文件一般在 $datadir/xx.err文件,或者是 /var/log/message、/var/log/mysql/mysqld.log之类的),根据错误日志提示去找到问题原因,不要只看表面提示,例如找不到 mysql.sock 文件之类的。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具一个最不可思议的MySQL死锁分析
死锁问题背景
做MySQL代码的深入分析也有些年头了,再加上自己10年左右的数据库内核研发经验,自认为对于MySQL/InnoDB的加锁实现了如指掌,正因如此,前段时间,还专门写了一篇洋洋洒洒的文章,专门分析MySQL的加锁实现细节:《》。
但是,昨天”润洁”同学在《》这篇博文下咨询的一个MySQL的死锁场景,还是彻底把我给难住了。此死锁,完全违背了本人原有的锁知识体系,让我百思不得其解。本着机器不会骗人,既然报出死锁,那么就一定存在死锁的原则,我又重新深入分析了InnoDB对应的源码实现,进行多次实验,配合恰到好处的灵光一现,还真让我分析出了这个死锁产生的原因。这篇博文的余下部分的内容安排,首先是给出”润洁”同学描述的死锁场景,然后再给出我的剖析。对个人来说,这是一篇十分有必要的总结,对此博文的读者来说,希望以后碰到类似的死锁问题时,能够明确死锁的原因所在。
一个不可思议的死锁
“润洁”同学,给出的死锁场景如下:
CREATE TABLE dltask (
id bigint unsigned NOT NULL AUTO_INCREMENT COMMENT ‘auto id’,
a varchar(30) NOT NULL COMMENT ‘uniq.a’,
b varchar(30) NOT NULL COMMENT ‘uniq.b’,
c varchar(30) NOT NULL COMMENT ‘uniq.c’,
x varchar(30) NOT NULL COMMENT ‘data’,
PRIMARY KEY (id),
UNIQUE KEY uniq_a_b_c (a, b, c)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=’deadlock test’;
a,b,c三列,组合成一个唯一索引,主键索引为id列。
事务隔离级别:
RR (Repeatable Read)
每个事务只有一条SQL:
delete from dltask where a=? and b=? and c=?;
SQL的执行计划:
死锁日志:
并发事务,每个事务只有一条SQL语句:给定唯一的二级索引键值,删除一条记录。每个事务,最多只会删除一条记录,为什么会产生死锁?这绝对是不可能的。但是,事实上,却真的是发生了死锁。产生死锁的两个事务,删除的是同一条记录,这应该是死锁发生的一个潜在原因,但是,即使是删除同一条记录,从原理上来说,也不应该产生死锁。因此,经过初步分析,这个死锁是不可能产生的。这个结论,远远不够!
如何阅读死锁日志
在详细给出此死锁产生的原因之前,让我们先来看看,如何阅读MySQL给出的死锁日志。
以上打印出来的死锁日志,由InnoDB引擎中的lock0lock.c::lock_deadlock_recursive()函数产生。死锁中的事务信息,通过调用函数lock_deadlock_trx_print()处理;而每个事务持有、等待的锁信息,由lock_deadlock_lock_print()函数产生。
例如,以上的死锁,有两个事务。事务1,当前正在操作一张表(mysql tables in use 1),持有两把锁(2 lock structs,一个表级意向锁,一个行锁(1 row lock)),这个事务,当前正在处理的语句是一条delete语句。同时,这唯一的一个行锁,处于等待状态(WAITING FOR THIS LOCK TO BE GRANTED)。
事务1等待中的行锁,加锁的对象是唯一索引uniq_a_b_c上页面号为12713页面上的一行(注:具体是哪一行,无法看到。但是能够看到的是,这个行锁,一共有96个bits可以用来锁96个行记录,n bits 96:lock_rec_print()方法)。同时,等待的行锁模式为next key锁(lock_mode X)。(注:关于InnoDB的锁模式,可参考我早期的一篇PPT:《》。简单来说,next key锁有两层含义,一是对当前记录加X锁,防止记录被并发修改,同时锁住记录之前的GAP,防止有新的记录插入到此记录之前。)
同理,可以分析事务2。事务2上有两个行锁,两个行锁对应的也都是唯一索引uniq_a_b_c上页面号为12713页面上的某一条记录。一把行锁处于持有状态,锁模式为X lock with no gap(注:记录锁,只锁记录,但是不锁记录前的GAP,no gap lock)。一把行锁处于等待状态,锁模式为next key锁(注:与事务1等待的锁模式一致。同时,需要注意的一点是,事务2的两个锁模式,并不是一致的,不完全相容。持有的锁模式为X lock with no gap,等待的锁模式为next key lock X。因此,并不能因为持有了X lock with no gap,就可以说next key lock X就一定能够加上。)。
分析这个死锁日志,就能发现一个死锁。事务1的next key lock X正在等待事务2持有的X lock with no gap(行锁X冲突),同时,事务2的next key lock X,却又在等待事务1正在等待中的next key锁(注:这里,事务2等待事务1的原因,在于公平竞争,杜绝事务1发生饥饿现象。),形成循环等待,死锁产生。
死锁产生后,根据两个事务的权重,事务1的权重更小,被选为死锁的牺牲者,回滚。
根据对于死锁日志的分析,确认死锁确实存在。而且,产生死锁的两个事务,确实都是在运行同样的基于唯一索引的等值删除操作。既然死锁确实存在,那么接下来,就是抓出这个死锁产生原因。
死锁原因深入剖析
Delete操作的加锁逻辑
在《》一文中,我详细分析了各种SQL语句对应的加锁逻辑。例如:Delete语句,内部就包含一个当前读(加锁读),然后通过当前读返回的记录,调用Delete操作进行删除。在此文的 组合六:id唯一索引+RR 中,可以看到,RR隔离级别下,针对于满足条件的查询记录,会对记录加上排它锁(X锁),但是并不会锁住记录之前的GAP(no gap lock)。对应到此文上面的死锁例子,事务2所持有的锁,是一把记录上的排它锁,但是没有锁住记录前的GAP(lock_mode X locks rec but not gap),与我之前的加锁分析一致。
其实,在《MySQL加锁处理分析》一文中的 组合七:id非唯一索引+RR 部分的最后,我还提出了一个问题:如果组合五、组合六下,针对SQL:select * from t1 where id = 10 第一次查询,没有找到满足查询条件的记录,那么GAP锁是否还能够省略?针对此问题,参与的朋友在做过试验之后,给出的正确答案是:此时GAP锁不能省略,会在第一个不满足查询条件的记录上加GAP锁,防止新的满足条件的记录插入。
其实,以上两个加锁策略,都是正确的。以上两个策略,分别对应的是:1)唯一索引上满足查询条件的记录存在并且有效;2)唯一索引上满足查询条件的记录不存在。但是,除了这两个之外,其实还有第三种:3)唯一索引上满足查询条件的记录存在但是无效。众所周知,InnoDB上删除一条记录,并不是真正意义上的物理删除,而是将记录标识为删除状态。(注:这些标识为删除状态的记录,后续会由后台的Purge操作进行回收,物理删除。但是,删除状态的记录会在索引中存放一段时间。) 在RR隔离级别下,唯一索引上满足查询条件,但是却是删除记录,如何加锁?InnoDB在此处的处理策略与前两种策略均不相同,或者说是前两种策略的组合:对于满足条件的删除记录,InnoDB会在记录上加next key lock X(对记录本身加X锁,同时锁住记录前的GAP,防止新的满足条件的记录插入。) Unique查询,三种情况,对应三种加锁策略,总结如下:
找到满足条件的记录,并且记录有效,则对记录加X锁,No Gap锁(lock_mode X locks rec but not gap);
找到满足条件的记录,但是记录无效(标识为删除的记录),则对记录加next key锁(同时锁住记录本身,以及记录之前的Gap:lock_mode X);
未找到满足条件的记录,则对第一个不满足条件的记录加Gap锁,保证没有满足条件的记录插入(locks gap before rec);
此处,我们看到了next key锁,是否很眼熟?对了,前面死锁中事务1,事务2处于等待状态的锁,均为next key锁。明白了这三个加锁策略,其实构造一定的并发场景,死锁的原因已经呼之欲出。但是,还有一个前提策略需要介绍,那就是InnoDB内部采用的死锁预防策略。
死锁预防策略
InnoDB引擎内部(或者说是所有的数据库内部),有多种锁类型:事务锁(行锁、表锁),Mutex(保护内部的共享变量操作)、RWLock(又称之为Latch,保护内部的页面读取与修改)。
InnoDB每个页面为16K,读取一个页面时,需要对页面加S锁,更新一个页面时,需要对页面加上X锁。任何情况下,操作一个页面,都会对页面加锁,页面锁加上之后,页面内存储的索引记录才不会被并发修改。
因此,为了修改一条记录,InnoDB内部如何处理:
根据给定的查询条件,找到对应的记录所在页面;
对页面加上X锁(RWLock),然后在页面内寻找满足条件的记录;
在持有页面锁的情况下,对满足条件的记录加事务锁(行锁:根据记录是否满足查询条件,记录是否已经被删除,分别对应于上面提到的3种加锁策略之一);
死锁预防策略:相对于事务锁,页面锁是一个短期持有的锁,而事务锁(行锁、表锁)是长期持有的锁。因此,为了防止页面锁与事务锁之间产生死锁。InnoDB做了死锁预防的策略:持有事务锁(行锁、表锁),可以等待获取页面锁;但反之,持有页面锁,不能等待持有事务锁。
根据死锁预防策略,在持有页面锁,加行锁的时候,如果行锁需要等待。则释放页面锁,然后等待行锁。此时,行锁获取没有任何锁保护,因此加上行锁之后,记录可能已经被并发修改。因此,此时要重新加回页面锁,重新判断记录的状态,重新在页面锁的保护下,对记录加锁。如果此时记录未被并发修改,那么第二次加锁能够很快完成,因为已经持有了相同模式的锁。但是,如果记录已经被并发修改,那么,就有可能导致本文前面提到的死锁问题。
以上的InnoDB死锁预防处理逻辑,对应的函数,是row0sel.c::row_search_for_mysql()。感兴趣的朋友,可以跟踪调试下这个函数的处理流程,很复杂,但是集中了InnoDB的精髓。
剖析死锁的成因
做了这么多铺垫,有了Delete操作的3种加锁逻辑、InnoDB的死锁预防策略等准备知识之后,再回过头来分析本文最初提到的死锁问题,就会手到拈来,事半而功倍。
首先,假设dltask中只有一条记录:(1, ‘a’, ‘b’, ‘c’, ‘data’)。三个并发事务,同时执行以下的这条SQL:
delete from dltask where a=’a’ and b=’b’ and c=’c’;
并且产生了以下的并发执行逻辑,就会产生死锁:
上面分析的这个并发流程,完整展现了死锁日志中的死锁产生的原因。其实,根据事务1步骤6,与事务0步骤3/4之间的顺序不同,死锁日志中还有可能产生另外一种情况,那就是事务1等待的锁模式为记录上的X锁 + No Gap锁(lock_mode X locks rec but not gap waiting)。这第二种情况,也是”润洁”同学给出的死锁用例中,使用MySQL 5.6.15版本测试出来的死锁产生的原因。
行文至此,MySQL基于唯一索引的单条记录的删除操作并发,也会产生死锁的原因,已经分析完毕。其实,分析此死锁的难点,在于理解MySQL/InnoDB的行锁模式,针对不同情况下的加锁模式的区别,以及InnoDB处理页面锁与事务锁的死锁预防策略。明白了这些,死锁的分析就会显得清晰明了。
最后,总结下此类死锁,产生的几个前提:
Delete操作,针对的是唯一索引上的等值查询的删除;(范围下的删除,也会产生死锁,但是死锁的场景,跟本文分析的场景,有所不同)
至少有3个(或以上)的并发删除操作;
并发删除操作,有可能删除到同一条记录,并且保证删除的记录一定存在;
事务的隔离级别设置为Repeatable Read,同时未设置innodb_locks_unsafe_for_binlog参数(此参数默认为FALSE);(Read Committed隔离级别,由于不会加Gap锁,不会有next key,因此也不会产生死锁)
使用的是InnoDB存储引擎;(废话!MyISAM引擎根本就没有行锁)
CategoriesMySQL启动故障处理一例(errno13)
之前在上装了个MySQL用于测试,今天发现启动d_safe进程的时候报错,如下所示:
[root@bak local]# mysqld_safe &
[root@bak local]# Starting mysqld daemon with databases from /data/mysql/mysql_3306/data
STOPPING server from pid file /data/mysql/mysql_3306/data/bak.pid
mysqld ended
mysqld_safe
由于我的my.cnf并没有改名,使用的是默认的/f这个位置,因此mysqld_safe &可以不用指定任何参数,需要的参数已经在my.cnf中指定了,如果使用的my.cnf位置不在/etc/下面,或者改过了自定义的名字,那么需要用--defaults-file参数来指定my.cnf文件的位置
[root@bak local]# cd /data/mysql/mysql_3306/logs/
[root@bak logs]# ll
查看日志,并没有任何binlog生成,这里说明一下,这个环境是从原来的一台主机上clone过来的,clone完以后没有启动过MySQL,我想可能是因为这个缘故
[root@bak mysql_3306]# cd /usr/local
[root@bak local]# chown -R mysql:mysql /data/mysql/
[root@bak local]# chown -R mysql:mysql /usr/local/mysql/
[root@bak local]# ll
drwxr-xr-x 2 mysql
502 4096 Aug 25 11:39 bin
-rw-rw---- 1 mysql root
432 Oct 17 09:20 error.log
drwxr-xr-x 2 mysql
502 4096 Aug
drwxr-xr-x 2 mysql
502 4096 Aug
2008 games
drwxr-xr-x 2 mysql
502 4096 Aug
2008 include
drwxr-xr-x 2 mysql
502 4096 Aug
drwxr-xr-x 2 mysql
502 4096 Aug
2008 libexec
lrwxrwxrwx 1 root
38 Sep 24 00:12 mysql -& /opt/mysql/mysql-5.5.39-linux2.6-i686/
drwxr-xr-x 2 mysql
502 4096 Aug
drwxr-xr-x 5 mysql
502 4096 Aug 25 11:39 share
drwxr-xr-x 2 mysql
502 4096 Sep 23 20:34 src
[root@bak local]# id mysql
uid=501(mysql) gid=1000(mysql) groups=1000(mysql)
mysql用户id为501,但不知为何显示的是mysql 502的形式,而不是mysql mysql
开始以为是因为/usr/local/mysql这个目录是root:root的缘故,但改为mysql:mysql后,依然无法启动
[root@bak data]# chown -R mysql:mysql /usr/local
[root@bak data]# cd /usr/local
[root@bak local]# ll
drwxr-xr-x 2 mysql
502 4096 Aug 25 11:39 bin
-rw-rw---- 1 mysql root
432 Oct 17 09:20 error.log
drwxr-xr-x 2 mysql
502 4096 Aug
drwxr-xr-x 2 mysql
502 4096 Aug
2008 games
drwxr-xr-x 2 mysql
502 4096 Aug
2008 include
drwxr-xr-x 2 mysql
502 4096 Aug
drwxr-xr-x 2 mysql
502 4096 Aug
2008 libexec
lrwxrwxrwx 1 mysql mysql
38 Sep 24 00:12 mysql -& /opt/mysql/mysql-5.5.39-linux2.6-i686/
drwxr-xr-x 2 mysql
502 4096 Aug
drwxr-xr-x 5 mysql
502 4096 Aug 25 11:39 share
drwxr-xr-x 2 mysql
502 4096 Sep 23 20:34 src
[root@bak local]# mysqld_safe &
[root@bak local]# Starting mysqld daemon with databases from /data/mysql/mysql_3306/data
[root@bak local]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
报了一个无法通过socket连接到服务器,于是想是不是应该在client项目中添加socket=/tmp/mysql.sock这个参数
--先查看下原来有的配置
[root@bak local]# cat /f
= /tmp/mysql.sock
[mysqld_safe]
open_files_limit
= error.log
...省略以下部分
看来client总已经指定了socket,应该不是这个问题,要判断问题出在哪里,最直接都就是查看error.log文件,由于我在my.cnf参数中指定了error.log的位置,放在了数据文件目录下,并更改了名字。如果没有改,默认的名字为&host_name&.error
[root@bak local]# cat /data/mysql/mysql_3306/data/error.log
:24:53 [Warning] Using unique option prefix myisam_recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use
the full name instead.
:24:53 [Note] Plugin 'FEDERATED' is disabled.
/usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist
:24:53 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
:24:53 InnoDB: The InnoDB memory heap is disabled
:24:53 InnoDB: Mutexes and rw_locks use InnoDB's own implementation
:24:53 InnoDB: Compressed tables use zlib 1.2.3
:24:53 InnoDB: Using
native AIO
:24:53 InnoDB: Initializing buffer pool, size = 128.0M
:24:53 InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
InnoDB: Setting file ./ibdata1 size to 100 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100
InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 100 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100
InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 100 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100
InnoDB: Log file ./ib_logfile2 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile2 size to 100 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: 127 rollback segment(s) active.
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
InnoDB: Waiting for the background threads to start
:25:14 InnoDB: 5.5.39 log sequence number 0
:25:14 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
:25:14 [Note]
- '0.0.0.0' resolves to '0.0.0.0';
:25:14 [Note] Server socket created on IP: '0.0.0.0'.
:25:14 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
:26:15 [Warning] Using unique option prefix myisam_recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
:26:15 [Note] Plugin 'FEDERATED' is disabled.
/usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist
:26:15 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
:26:15 InnoDB: The InnoDB memory heap is disabled
:26:15 InnoDB: Mutexes and rw_locks use InnoDB's own implementation
:26:15 InnoDB: Compressed tables use zlib 1.2.3
:26:15 InnoDB: Using Linux native AIO
:26:15 InnoDB: Initializing buffer pool, size = 128.0M
:26:15 InnoDB: Completed initialization of buffer pool
:26:15 InnoDB: highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 48941
InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 1595668
InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
InnoDB: Waiting for the background threads to start
:26:16 InnoDB: 5.5.39 log sequence number 1595668
:26:16 [Note] Recovering after a crash using /data/mysql/mysql_3306/logs/mysql-bin
:26:16 [Note] Starting crash recovery...
:26:16 [Note] Crash recovery finished.
:26:17 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
:26:17 [Note]
- '0.0.0.0' resolves to '0.0.0.0';
:26:17 [Note] Server socket created on IP: '0.0.0.0'.
:26:17 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
日志中报错提示无法打开mysql.plugin表,也不存在mysql.host这张表,由于是测试环境,没有什么数据,于是决定重新初始化MySQL
[root@bak local]# cd mysql
[root@bak mysql]# ./scripts/mysql_install_db
Installing MySQL system tables...
:28:24 [Warning] options --log-slow-admin-statements, --log-queries-not-using-indexes and --log-slow-slave-statements have no effect if --log_slow_queries is not set
Filling help tables...
:28:25 [Warning] options --log-slow-admin-statements, --log-queries-not-using-indexes and --log-slow-slave-statements have no effect if --log_slow_queries is not set
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h bak password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local/ /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql- perl mysql-test-run.pl
Please report any problems at /
[root@bak mysql]# mysqld_safe &
[root@bak mysql]# Starting mysqld daemon with databases from /data/mysql/mysql_3306/data
[root@bak mysql]# mysqSTOPPING server from pid file /data/mysql/mysql_3306/data/bak.pid
mysqld ended
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
mysqld_safe
初始化时成功的,可以看到有2个OK,不过启动依然报错,再次查看error.log
[root@bak mysql]# cat /data/mysql/mysql_3306/data/error.log
:24:53 [Warning] Using unique option prefix myisam_recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
:24:53 [Note] Plugin 'FEDERATED' is disabled.
/usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist
:24:53 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
:24:53 InnoDB: The InnoDB memory heap is disabled
:24:53 InnoDB: Mutexes and rw_locks use InnoDB's own implementation
:24:53 InnoDB: Compressed tables use zlib 1.2.3
:24:53 InnoDB: Using Linux native AIO
:24:53 InnoDB: Initializing buffer pool, size = 128.0M
:24:53 InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
InnoDB: Setting file ./ibdata1 size to 100 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100
InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 100 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100
InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 100 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100
InnoDB: Log file ./ib_logfile2 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile2 size to 100 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: 127 rollback segment(s) active.
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
InnoDB: Waiting for the background threads to start
:25:14 InnoDB: 5.5.39 log sequence number 0
:25:14 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
:25:14 [Note]
- '0.0.0.0' resolves to '0.0.0.0';
:25:14 [Note] Server socket created on IP: '0.0.0.0'.
:25:14 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
:26:15 [Warning] Using unique option prefix myisam_recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
:26:15 [Note] Plugin 'FEDERATED' is disabled.
/usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist
:26:15 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
:26:15 InnoDB: The InnoDB memory heap is disabled
:26:15 InnoDB: Mutexes and rw_locks use InnoDB's own implementation
:26:15 InnoDB: Compressed tables use zlib 1.2.3
:26:15 InnoDB: Using Linux native AIO
:26:15 InnoDB: Initializing buffer pool, size = 128.0M
:26:15 InnoDB: Completed initialization of buffer pool
:26:15 InnoDB: highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 48941
InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 1595668
InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
InnoDB: Waiting for the background threads to start
:26:16 InnoDB: 5.5.39 log sequence number 1595668
:26:16 [Note] Recovering after a crash using /data/mysql/mysql_3306/logs/mysql-bin
:26:16 [Note] Starting crash recovery...
:26:16 [Note] Crash recovery finished.
:26:17 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
:26:17 [Note]
- '0.0.0.0' resolves to '0.0.0.0';
:26:17 [Note] Server socket created on IP: '0.0.0.0'.
:26:17 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
:28:34 [Warning] Using unique option prefix myisam_recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
:28:34 [Note] Plugin 'FEDERATED' is disabled.
/usr/libexec/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
:28:34 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
:28:34 InnoDB: The InnoDB memory heap is disabled
:28:34 InnoDB: Mutexes and rw_locks use InnoDB's own implementation
:28:34 InnoDB: Compressed tables use zlib 1.2.3
:28:34 InnoDB: Using Linux native AIO
:28:34 InnoDB: Initializing buffer pool, size = 128.0M
:28:34 InnoDB: Completed initialization of buffer pool
:28:34 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Waiting for the background threads to start
:28:35 InnoDB: 5.5.39 log sequence number 1595668
/usr/libexec/mysqld: File '/data/mysql/mysql_3306/logs/mysql-bin.000004' not found (Errcode: 13)
:28:35 [ERROR] Failed to open log (file '/data/mysql/mysql_3306/logs/mysql-bin.000004', errno 13)
:28:35 [ERROR] Could not open log file
:28:35 [ERROR] Can't init tc log
:28:35 [ERROR] Aborting
InnoDB: Starting shutdown...
InnoDB: S log sequence number 1595668
:28:36 [Note] /usr/libexec/mysqld: Shutdown complete
:30:32 [Warning] Using unique option prefix myisam_recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
:30:32 [Note] Plugin 'FEDERATED' is disabled.
/usr/libexec/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
:30:32 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
:30:32 InnoDB: The InnoDB memory heap is disabled
:30:32 InnoDB: Mutexes and rw_locks use InnoDB's own implementation
:30:32 InnoDB: Compressed tables use zlib 1.2.3
:30:32 InnoDB: Using Linux native AIO
:30:32 InnoDB: Initializing buffer pool, size = 128.0M
:30:32 InnoDB: Completed initialization of buffer pool
:30:32 InnoDB: highest supported file format is Barracuda.
InnoDB: Waiting for the background threads to start
:30:33 InnoDB: 5.5.39 log sequence number 1595668
/usr/libexec/mysqld: File '/data/mysql/mysql_3306/logs/mysql-bin.000004' not found (Errcode: 13)
:30:33 [ERROR] Failed to open log (file '/data/mysql/mysql_3306/logs/mysql-bin.000004', errno 13)
:30:33 [ERROR] Could not open log file
:30:33 [ERROR] Can't init tc log
:30:33 [ERROR] Aborting
InnoDB: Starting shutdown...
InnoDB: S log sequence number 1595668
:30:34 [Note] /usr/libexec/mysqld: Shutdown complete
现在error.log里很明显地指出errno为13,我们知道13就是权限问题,这个可以perror命令查看
[root@bak mysql]# perror 13
OS error code
Permission denied
位置可以通过which来定位
[root@bak mysql]# which perror
/usr/bin/perror
或者用find定位也是可以的
[root@bak mysql]#
find / -name perror -print
/opt/mysql/mysql-5.5.39-linux2.6-i686/bin/perror
/usr/bin/perror
既然找到了无法启动的真正原因,那么对症下药,把权限问题解决,问题就可以搞定了
[root@bak mysql]# cd /data/mysql/mysql_3306/data
[root@bak data]# ll
total 410036
-rw-rw---- 1 mysql mysql
7950 Oct 17 09:30 error.log
-rw-rw---- 1 mysql mysql
Oct 17 09:30 ibdata1
-rw-rw---- 1 mysql mysql
Oct 17 09:30 ib_logfile0
-rw-rw---- 1 mysql mysql
Oct 17 09:25 ib_logfile1
-rw-rw---- 1 mysql mysql
Oct 17 09:25 ib_logfile2
drwx------ 2 root
4096 Oct 17 09:28 mysql
drwx------ 2 root
4096 Oct 17 09:28 performance_schema
drwx------ 2 root
4096 Oct 17 09:28 test
[root@bak data]# chown -R mysql:mysql ./
[root@bak data]# ll
total 410036
-rw-rw---- 1 mysql mysql
7950 Oct 17 09:30 error.log
-rw-rw---- 1 mysql mysql
Oct 17 09:30 ibdata1
-rw-rw---- 1 mysql mysql
Oct 17 09:30 ib_logfile0
-rw-rw---- 1 mysql mysql
Oct 17 09:25 ib_logfile1
-rw-rw---- 1 mysql mysql
Oct 17 09:25 ib_logfile2
drwx------ 2 mysql mysql
4096 Oct 17 09:28 mysql
drwx------ 2 mysql mysql
4096 Oct 17 09:28 performance_schema
drwx------ 2 mysql mysql
4096 Oct 17 09:28 test
开始还去调整了/data/mysql/mysql_3306/data目录下面几个的权限,但发现依然无法启动,看来不是这几个目录的权限问题
[root@bak data]# mysqld_safe &
[root@bak data]# Starting mysqld daemon with databases from /data/mysql/mysql_3306/data
[root@bak data]# mysqlSTOPPING server from pid file /data/mysql/mysql_3306/data/bak.pid
mysqld ended
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
mysqld_safe
error.log日志内容和之前一样,仍然报errno 13,就不贴了。针对之前给出的error.log日志里提示的对mysql-bin.000004读写权限的问题做一下处理
[root@bak mysql]# cd /data/mysql/mysql_3306/logs
[root@bak logs]# ll
total 1092
-rw-rw---- 1 mysql mysql
107 Oct 17 09:25 mysql-bin.000001
-rw-rw---- 1 mysql mysql
107 Oct 17 09:26 mysql-bin.000002
-rw-rw---- 1 root
27681 Oct 17 09:28 mysql-bin.000003
-rw-rw---- 1 root
1070549 Oct 17 09:28 mysql-bin.000004
-rw-rw---- 1 mysql mysql
180 Oct 17 09:28 mysql-bin.index
[root@bak logs]# chown -R mysql:mysql ./
[root@bak logs]# ll
total 1092
-rw-rw---- 1 mysql mysql
107 Oct 17 09:25 mysql-bin.000001
-rw-rw---- 1 mysql mysql
107 Oct 17 09:26 mysql-bin.000002
-rw-rw---- 1 mysql mysql
27681 Oct 17 09:28 mysql-bin.000003
-rw-rw---- 1 mysql mysql 1070549 Oct 17 09:28 mysql-bin.000004
-rw-rw---- 1 mysql mysql
180 Oct 17 09:28 mysql-bin.index
原来是root root权限,改为mysql mysql了,再次启动MySQL进程
[root@bak logs]# ps -ef|grep mysql
0 09:35 pts/0
00:00:00 grep mysql
[root@bak logs]# mysqld_safe &
[root@bak logs]# Starting mysqld daemon with databases from /data/mysql/mysql_3306/data
[root@bak logs]# mysql
Welcome to the MySQL monitor.
Your MySQL connection id is 1
Server version: 5.5.39-log MySQL Community Server (GPL)
Copyright (c) ,
and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
Type '' or '\h' for help. Type '\c' to clear the current input statement.
(testing)root@localhost [(none)]& exit
[root@bak logs]# ps aux | grep -v grep | grep mysql
0:00 /bin/sh /usr/bin/mysqld_safe
3.1 16 pts/0
0:02 /usr/libexec/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/mysql_3306/data --user=mysql
--pid-file=/data/mysql/mysql_3306/data/bak.pid --skip-external-locking --port=3306 --socket=/tmp/mysql.sock
这次,数据库顺利启动了,从mysql进程中可以看到,mysqld_safe实际去调用的还是mysqld
当我们遭遇数据库无法启动,如:自动终止进程stopping from pid file或是无法通过socket连接到服务器等错误,首先要去查看数据库的error.log日志,其中有详细的提示(各种ERROR和WARNING),来给你提供无法启动的线索,我们要做的就是更具这些线索,来做相应的处理,才能更快、更好地解决问题。

我要回帖

更多关于 mysql 的文章

 

随机推荐