10

I don't know very much about server maintenance and am trying to learn by managing my own Mac. I'm running a local rails application with a MySQL database (5.5.9). All has been well for a long time UNTIL I attempted to start a new rails project. At that time, I ran bundle install, which updated my mysql gem from 0.2.6 to 0.3.6. Ever since then, or I'm associating with that (it may be that I also installed RVM around that time), I can't startup my MySQL server. I get the following error:

Unable to lock ./ibdata1, error: 35

repeatedly. I've tried fixing with:

mv ibdata1 ibdata1.bak
cp -a ibdata1.bak ibdata1

which works (reference: http://cglreport.zhenhua.info/2008/08/mysql-error-unable-to-lock-ibdata1.html) (I have to do it on a few other files too), but it only works for a while. When I restart, or periodically the problem comes back. What's going on ? This doesn't seem to be a reasonable solution to me. Ideas? Thanks!

panzhuli
  • 2,890
  • 6
  • 33
  • 46

2 Answers2

13

That sounds pretty convincingly like you already have an instance of your MySQL server running, and you're trying to steal a data file that it's using.

  • is there a way to ask the system what's running on port 3036? I don't see anything there when running "top" from the terminal. I think this is a limitation of my knowledge here... – panzhuli Aug 07 '11 at 17:40
  • 5
    Probably easier to just look for `ps ax|grep mysql`. For posterity, though, try `lsof -np|grep :mysql`. (`lsof` translates port numbers to service names in its output, so you have to look for ":mysql" instead of ":3306".) –  Aug 07 '11 at 19:55
  • thanks. somewhere along the line the server started up again. Why do you think this is repeatedly happening? Are the above files being corrupted? – panzhuli Aug 07 '11 at 20:18
  • use ps -ef | grep mysqld and kill any mysqld process running. – Kamrul Jul 02 '13 at 00:04
  • Having a similar issue but I do not see a solution here. There is no other mysql currently running on my machine, I did this as well to stop any mysql instances sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop – pal4life Jun 23 '14 at 18:53
  • Not much of an answer here. Would be nice to have some notes on resources or tools on how to resolve with instructions. – frshjb373 Apr 05 '17 at 16:16
  • @frshjb373 It's impossible to give exact instructions; there's a lot of different ways that a MySQL server could be set up (on multiple different operating systems!) which would cause this problem. –  Apr 05 '17 at 18:35
  • @duskwuff, I gotchya...just surprised so many upvotes for this. I resolved by force quitting mysqld processes in Activity Monitor several times, then powering off MAMP Pro and shutting down, waiting a bit and turned back on. Finally worked after several tries. – frshjb373 Apr 05 '17 at 18:47
0

Here is what fixed it for me, looked all around and nothing helped.

To fix this issue, make a copy of the original files (ibdata1, ib_logfile0, ib_logfile1…).

mv /var/lib/mysql/ibdata1 /var/lib/mysql/ibdata1.bak

cp -a /var/lib/mysql/ibdata1.bak /var/lib/mysql/ibdata1

Now start mysql service.

/etc/init.d/mysql start

In my case it was the XAMPP files so I did

sudo mv /Applications/XAMPP/xamppfiles/var/mysql/ibdata1 /Users/username/Documents/tmp/ibdata1.bak
sudo cp -a /Users/username/Documents/tmp/ibdata1.bak /Applications/XAMPP/xamppfiles/var/mysql/ibdata1

Then I noticed that mysql was already started for me.

Based on the solution here

pal4life
  • 3,210
  • 5
  • 36
  • 57