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

Vue implements the full selection function

This article example shares the specific code of ...

Detailed tutorial on how to install mysql8.0 using Linux yum command

1. Do a good job of cleaning before installation ...

How to make a website look taller and more designed

“How to make a website look high-end? Or more des...

CSS code to achieve 10 modern layouts

Preface I watched web.dev's 2020 three-day li...

How to use dl(dt,dd), ul(li), ol(li) in HTML

HTML <dl> Tag #Definition and Usage The <...

About MYSQL, you need to know the data types and operation tables

Data Types and Operations Data Table 1.1 MySQL ty...

CSS3 uses transform to create a moving 2D clock

Now that we have finished the transform course, l...

Will CSS3 really replace SCSS?

When it comes to styling our web pages, we have t...

11 Linux KDE applications you didn't know about

KDE Abbreviation for Kool Desktop Environment. A ...

How to determine if the Linux system is installed on VMware

How to determine whether the current Linux system...

VMware Workstation 12 Pro Linux installation tutorial

This article records the VMware Workstation 12 Pr...

Detailed explanation of MySQL's Seconds_Behind_Master

Table of contents Seconds_Behind_Master Original ...

A brief explanation of the reasonable application of table and div in page design

At the beginning of this article, I would like to ...

Tutorial diagram of installing TomCat in Windows 10

Install TomCat on Windows This article will intro...