MySQL startup error InnoDB: Unable to lock/ibdata1 error

MySQL startup error InnoDB: Unable to lock/ibdata1 error

An error message appears when MySQL is started in OS X environment:

016-03-03T00:02:30.483037Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 35
2016-03-03T00:02:30.483100Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.

The terminal keeps printing the above error log repeatedly. From the error log, it seems that another mysqld process has occupied the ./ibdata1 file. So use the ps command to check whether there is a mysqld process running:

ps -ef |grep mysqld
74 7711 1 0 8:04AM?? 0:00.34 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid

It was found that there was a 7711 process running, so it was killed forcefully:

sudo kill -9 7711

Query again with ps:

ps -ef |grep mysqld
74 7759 1 0 8:10AM?? 0:00.29 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid

It is still there, but the pid has changed from the original 7711 to the current 7759. Then see which files the mysqld process has opened:

lsof -c mysqld

The process doesn't have any files open, that's the problem.

Mac OS X, lsof only shows your own processes unless running as root with sudo

So run again:

sudo lsof -c mysqld
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 8655 _mysql cwd DIR 1,4 544 3090250 /usr/local/mysql/data
mysqld 8655 _mysql.txt REG 1,4 31130736 3089789 /usr/local/mysql/bin/mysqld

Indeed, I found that there is a real mysqld process running, which also occupies these mysql files. After some Google, I found that the way to start MySQL in OS X is completely different from that in Linux. The correct way to start/restart MySQL in OS X is:

sudo launchctl unload -w /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

Now let's see if there is still a mysqld process:

ps -ef |grep mysqld

Well, I found that it is indeed gone, so I started MySQL again:

sudo launchctl load -w /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

The problem is finally solved, but it’s not over yet. We have to figure out the principle.

What is LAUNCHD?

Launchd is a key process introduced in Mac OS X since 10.4. It is used to initialize the system environment. It is the first process started in the OS environment after the kernel is loaded successfully. Traditional Linux uses /etc/rc.* or /etc/init to manage services to be started at boot, while OS X uses launchd to manage them. It is very simple to configure startup items in this way, and only one plist file is needed. The plist files in the /Library/LaunchDaemons directory are all processes that are started immediately after the system starts. Use the launchctl command to load/unload the plist file. After loading the configuration file, the program starts, and after unloading the configuration file, the program closes.

After uninstalling the configuration file, try to start the mysql process directly using the mysqld command:

/usr/local/mysql/bin/mysqld
2016-03-03T01:35:50.359258Z 0 [ERROR] InnoDB: ./ib_logfile0 can't be opened in read-write mode.
2016-03-03T01:35:50.359283Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2016-03-03T01:35:50.670517Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2016-03-03T01:35:50.670555Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-03-03T01:35:50.670568Z 0 [ERROR] Failed to initialize plugins.
2016-03-03T01:35:50.670574Z 0 [ERROR] Aborting

ib_logfile0 cannot be opened. It is probably a user permission file. MySQL cannot be started with the current system user. Then add sudo and start it as root:

2016-03-03T01:38:10.977313Z 0 [ERROR] Fatal error: Please read the "Security" section of the manual to find out how to run mysqld as root!
2016-03-03T01:38:10.977339Z 0 [ERROR] Aborting
2016-03-03T01:38:10.977350Z 0 [Note] Binlog end
2016-03-03T01:38:10.977410Z 0 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

Tell me to read the MySQL security manual and start it with launchd.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Analysis of the difference between Mysql InnoDB and MyISAM
  • How to get the height of MySQL innodb B+tree
  • Differences between MySQL MyISAM and InnoDB
  • Briefly describe the MySQL InnoDB storage engine
  • Detailed explanation of MySQL Innodb storage structure and storage of Null values
  • MySQL InnoDB row_id boundary overflow verification method steps
  • How to ensure transaction characteristics of MySQL InnoDB?
  • In-depth explanation of the locking mechanism in MySQL InnoDB
  • Detailed explanation of how MySQL (InnoDB) handles deadlocks
  • MySQL Learning (VII): Detailed Explanation of the Implementation Principle of Innodb Storage Engine Index
  • MySQL slow_log table cannot be modified to innodb engine detailed explanation
  • Summary of important components of MySQL InnoDB

<<:  Vue two same-level components to achieve value transfer

>>:  How to use port 80 in Tomcat under Linux system

Recommend

MySQL slow query: Enable slow query

1. What is the use of slow query? It can record a...

How to solve the 2002 error when installing MySQL database on Alibaba Cloud

The following error occurred while installing the...

Vue-Element-Admin integrates its own interface to realize login jump

1. First look at the request configuration file, ...

Detailed explanation of how to use Docker-Compose commands

You can manage and deploy Docker containers in a ...

JavaScript and JQuery Framework Basics Tutorial

Table of contents 1. JS Object DOM –1, Function –...

How to install nginx in docker and configure access via https

1. Download the latest nginx docker image $ docke...

Use HTML to write a simple email template

Today, I want to write about a "low-tech&quo...

Introduction to the three essential logs for MySQL database interviews

Table of contents 1. redo log (transaction log of...

Detailed explanation of the use of Linux seq command

01. Command Overview The seq command is used to g...

How to build nfs service in ubuntu16.04

Introduction to NFS NFS (Network File System) is ...

This article teaches you how to play with CSS combination selectors

CSS combination selectors include various combina...

How to access the local machine (host machine) in Docker

Question How to access the local database in Dock...

How to use ES6 class inheritance to achieve a gorgeous ball effect

Table of contents introduce Implementation steps ...