Centos6.2系统自带的Mysql版本较低,卸载掉再重装一个最新的。

下载并安装以下包

MySQL-client-5.5.25-1.el6.i686.rpm

MySQL-devel-5.5.25-1.el6.i686.rpm(含mysql_config)

MySQL-server-5.5.25-1.el6.i686.rpm

MySQL-shared-5.5.25-1.el6.i686.rpm

MySQL-shared-compat-5.5.25-1.el6.i686.rpm

安装成功后

启动mysql,使用

#service mysql start

显示Starting MySQL SUCCESS!

使用ps命令查看进程情况

#ps -ef | grep mysql

root 2853 1 0 09:03 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/python.centos.pid

mysql 3105 2853 0 09:03 ? 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql--log-error=/var/lib/mysql/python.centos.err --pid-file=/var/lib/mysql/python.centos.pid --socket=/var/lib/mysql/mysql.sock --port=3306

root 4163 1 0 09:17 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/python.centos.pid

mysql 4416 4163 1 09:17 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/lib/mysql/python.centos.err --pid-file=/var/lib/mysql/python.centos.pid --socket=/var/lib/mysql/mysql.sock --port=3306

mysql写错误日志,python.centos是我的机器名。两个时间,可能是我运行了两次。

从shell进入mysql

# mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

结束mysql服务

#service mysql stop

ERROR! MySQL server PID file could not be found!

查看/var/lib/mysql/python.centos.err错误日志

120706 09:17:59 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

120706 9:17:59 [Note] Plugin 'FEDERATED' is disabled.

120706 9:17:59 InnoDB: The InnoDB memory heap is disabled

120706 9:17:59 InnoDB: Mutexes and rw_locks use GCC atomic builtins

120706 9:17:59 InnoDB: Compressed tables use zlib 1.2.3

120706 9:17:59 InnoDB: Using Linux native AIO

120706 9:17:59 InnoDB: Initializing buffer pool, size = 128.0M

120706 9:17:59 InnoDB: Completed initialization of buffer pool

InnoDB: Unable to lock ./ibdata1, error: 11

InnoDB: Check that you do not already have another mysqld process

InnoDB: using the same InnoDB data or log files.

120706 9:17:59 InnoDB: Retrying to lock the first data file

InnoDB: Unable to lock ./ibdata1, error: 11

InnoDB: Check that you do not already have another mysqld process

... ... ... ... ... ... ...InnoDB: Check that you do not already have another mysqld process

InnoDB: using the same InnoDB data or log files.

InnoDB: Unable to lock ./ibdata1, error: 11

InnoDB: Check that you do not already have another mysqld process

InnoDB: using the same InnoDB data or log files.

120706 9:19:40 InnoDB: Unable to open the first data file

InnoDB: Error in opening ./ibdata1

120706 9:19:40 InnoDB: Operating system error number 11 in a file operation.

InnoDB: Error number 11 means 'Resource temporarily unavailable'.

InnoDB: Some operating system error numbers are described at

InnoDB: http://dev.mysql.com/doc/refman/5.5/en/operating-system-error-codes.html

120706 9:19:40 InnoDB: Could not open or create data files.

120706 9:19:40 InnoDB: If you tried to add new data files, and it failed here,

120706 9:19:40 InnoDB: you should now edit innodb_data_file_path in my.cnf back

120706 9:19:40 InnoDB: to what it was, and remove the new ibdata files InnoDB created

120706 9:19:40 InnoDB: in this failed attempt. InnoDB only wrote those files full of

120706 9:19:40 InnoDB: zeros, but did not yet use them in any way. But be careful: do not

120706 9:19:40 InnoDB: remove old data files which contain your precious data!

120706 9:19:40 [ERROR] Plugin 'InnoDB' init function returned error.

120706 9:19:40 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.

120706 9:19:40 [ERROR] Unknown/unsupported storage engine: InnoDB

120706 9:19:40 [ERROR] Aborting

120706 9:19:40 [Note] /usr/sbin/mysqld: Shutdown complete

120706 09:19:40 mysqld_safe mysqld from pid file /var/lib/mysql/python.centos.pid ended

查找InnoDB: Unable to lock ./ibdata1, error: 11的解决方法

Solution:

make a copy of the original files (ibdata1, ib_logfile0, ib_logfile1...).

mv ibdata1 ibdata1.bak

cp -a ibdata1.bak ibdata1

......

操作:

先查看/var/lib/mysql目录下的文件

# cd /var/lib/mysql/

# ll

total 28812

-rw-rwxr-x. 1 mysql mysql 18874368 Jul 4 17:30 ibdata1

-rw-rwxr-x. 1 mysql mysql 5242880 Jul 6 09:03 ib_logfile0

-rw-rwxr-x. 1 mysql mysql 5242880 Jun 14 15:48 ib_logfile1

drwxr-xr-x. 2 mysql mysql 4096 Jun 14 14:39 mysql

-rw-rw----. 1 mysql mysql 107 Jul 6 09:03 mysql-bin.000001

-rw-rwxr-x. 1 mysql mysql 19 Jul 6 09:03 mysql-bin.index

drwxr-xr-x. 2 mysql mysql 4096 Jun 14 14:39 performance_schema

-rw-rwxr-x. 1 mysql root 108068 Jul 6 09:19 python.centos.err

-rw-r-xr-x. 1 root root 329 Jun 14 15:47 RPM_UPGRADE_HISTORY

-rw-r-xr-x. 1 mysql mysql 329 Jun 14 15:47 RPM_UPGRADE_MARKER-LAST

-rw-r-xr-x. 1 root root 0 Jul 5 16:56 -S

drwxr-xr-x. 2 mysql mysql 4096 Jun 14 16:06 test

上面三个文件ibdata1、ib_logfile0、ib_logfile1都是属于mysql用户的。

切换到mysql用户再进行操作

# su mysql

bash-4.1$ pwd

/var/lib/mysql

确认当前在/var/lib/mysql目录下,执行

bash-4.1$ mv ibdata1 ibdata1.bak

bash-4.1$ cp -a ibdata1.bak ibdata1

bash-4.1$ mv ib_logfile0 ib_logfile0.bak

bash-4.1$ cp -a ib_logfile0.bak ib_logfile0

bash-4.1$ mv ib_logfile1 ib_logfile1.bak

bash-4.1$ cp -a ib_logfile1.bak ib_logfile1

bash-4.1$ exit

退出mysql用户,使用lsof查找mysql进程并杀掉,重启mysql服务# lsof -i:3306

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

mysqld 3105 mysql 11u IPv4 15743 0t0 TCP *:mysql (LISTEN)

# kill -9 3105

# service mysql start

Starting MySQL.. SUCCESS!

进入mysql

# mysql

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

Your MySQL connection id is 1

Server version: 5.5.25-log MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle 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

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| test |

+--------------------+

4 rows in set (0.10 sec)

将mysql添加到自动启动/sbin/chkconfig --level 35 mysql on

成功解决。对于错误ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)的讨论:

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐