0

I am running mac OS sierra and have more than one installation of MySQL on the machine. One installed manually and the other with Homebrew. I have no problem connecting and using MySQL which I assume is the Homebrew version but I honestly don't know.

I am dealing with a sock error that indicates that the app I am using cannot connect to MySQL (on my local mac) and I have been digging in ever since. The app runs over http and shouldn't have a problem connecting but I am getting the below error that lead me to finding out about two installations of mysql. Makes sense because when I got the machine I installed mysql before becoming hip to homebrew.

Connection Test Failed:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Any ideas how to first determine which is being used by default and then delete the version not being used? Note that the instance running by default connects fine via all the clients I use to manage my local databases.

Update: There is a folder inside Cellar /usr/local/Cellar/mysql/5.6.25 and then there is another version in /usr/local/var/mysql/ which is the one where all my databases are.

mysqld stop renders the following errors and leads me to believe that mysqld is controlling the version of MySQL I would like delete:

$ mysqld stop

2017-05-04 18:44:54 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2017-05-04 18:44:54 0 [Note] mysqld (mysqld 5.6.25) starting as process 1718 ...

2017-05-04 18:44:54 1718 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive

2017-05-04 18:44:54 1718 [Note] Plugin 'FEDERATED' is disabled.

2017-05-04 18:44:54 1718 [Note] InnoDB: Using atomics to ref count buffer pool pages

2017-05-04 18:44:54 1718 [Note] InnoDB: The InnoDB memory heap is disabled

2017-05-04 18:44:54 1718 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2017-05-04 18:44:54 1718 [Note] InnoDB: Memory barrier is not used

2017-05-04 18:44:54 1718 [Note] InnoDB: Compressed tables use zlib 1.2.3

2017-05-04 18:44:54 1718 [Note] InnoDB: Using CPU crc32 instructions

2017-05-04 18:44:54 1718 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2017-05-04 18:44:54 1718 [Note] InnoDB: Completed initialization of buffer pool

2017-05-04 18:44:54 1718 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 35

2017-05-04 18:44:54 1718 [Note] InnoDB: Check

 or log files.

2017-05-04 18:43:41 1635 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 35

2017-05-04 18:43:41 1635 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
lcm
  • 1,737
  • 6
  • 17
  • 40

1 Answers1

0

Just use ps and grep command to do this:

➜  ps -ef|grep mysqld
  501 51092     1   0         0:00.03 /bin/sh /usr/local/opt/mysql/bin/mysqld_safe --bind-address=127.0.0.1 --datadir=/usr/local/var/mysql
  501 51194 51092   0         0:00.45 /usr/local/Cellar/mysql/5.7.17/bin/mysqld --basedir=/usr/local/Cellar/mysql/5.7.17 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/5.7.17/lib/plugin --bind-address=127.0.0.1 --log-error=/usr/local/var/mysql/McGrady.local.err --pid-file=/usr/local/var/mysql/McGrady.local.pid

The above result indicates the path of the program and options, for me, my data directory is --datadir=/usr/local/var/mysql, so you will find which one is you need.

Also you can use brew services list to do this, if you run mysql by brew services start mysql:

➜  brew services list
Name    Status  User  Plist
mysql   started ** /Users/**/Library/LaunchAgents/homebrew.mxcl.mysql.plist

➜  cat /Users/**/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  ...
  <array>
    <string>/usr/local/opt/mysql/bin/mysqld_safe</string>
    <string>--bind-address=127.0.0.1</string>
    <string>--datadir=/usr/local/var/mysql</string>
  </array>
  ...

Here, we can get the datadir option.

[ERROR] InnoDB: Unable to lock ./ibdata1, error: 35

The above error just tells you some other process (maybe another instance of mysqld) has already locked the file. Which means if you've already started a mysql server, when you run mysqld command next time, you will get this error.

You can see this question to find a way to stop the server.

Or just kill -9 pid to kill the process, to uninstall mysql if you want to remove the one installed by brew, you can run this:

brew uninstall mysql

Another one, you can use:

sudo rm -rf /path_you_install_mysql.*

have a look at How do you uninstall MySQL from Mac OS X?

Community
  • 1
  • 1
McGrady
  • 10,869
  • 13
  • 47
  • 69