Mysql 5.6 headaches on Mac OSX - mysql

Several of my colleagues and I have recently upgraded from MySQL 5.5 to MySQL 5.6 using homebrew on our Macs to test locally before upgrading our servers. Since this upgrade, we all have been experiencing intermittent MySQL errors when running our rails code:
Lost connection to MySQL server at 'sending authentication information', system error: 32
We have tried re-making our usernames and passwords in our database, and upping the connection timeout, but neither have fixed the problem. The error logs do not mention the issue. The only workaround we have found when we run into the problem is to kill mysql and restart it. I have even noticed this error more recently using mysql -u root -p on the command line. It seems that once I start getting this error, I cannot exceed my current number of connections no matter what username I use. If I close a connection, then I can re-open one.
We have the following environments:
some of us: Rails 3.2, Ruby 2, mysql2 0.3.13, MySQL 5.6.12, Mac OSX 10.8.4
others of us: Rails 3.2, Ruby 1.9, mysql2 0.3.13, MySQL 5.6.10, Mac OSX 10.8.4
Any ideas what might be causing this?
Thanks!
Julie

None of the answers here helped me, but finally I got MySQL 5.6 to work.
THREE options to fix MySQL 5.6:
(confirmed) Edit /etc/my.cnf (create if not exists) and add:
[mysqld]
innodb_file_per_table = OFF
and restart MySQL. Then for this to work you'll need to dump your databases into SQL file (mysqldump), then drop and re-create the databases, then load the data back.
Change default ulimit value of OSX (suggested by Github user sodabrew): https://superuser.com/questions/261023/how-to-change-default-ulimit-values-in-mac-os-x-10-6
Add the following option to [mysqld] section of my.cnf: table_open_cache = 250. By default it is set to 2000, which is way above OSX's default ulimit. This solution is also not recommended, because it hurts the performance of your MySQL - it forces MySQL to re-open tables often, if you have more than 250 tables: https://mariadb.com/kb/en/optimizing-table_open_cache/
Why this error is happening?
Since MySQL 5.6 innodb_file_per_table option is ON by default, which means that each table's data is stored in its own file. OSX default limit of the number of the open files is 256 per process. Normally this isn't a problem, but in my case I'm running unit tests in parallel, which creates 8 databases with 405 tables each. OSX has a limit of the number of open file handles per process. This StackOverflow answer suggests that this limit is 256, which explains my problem perfectly: before MySQL 5.6 all data from all these 8 databases was in ONE file.
Thanks to my colleague Thomas L. who found a MySQL bug report which hinted this solution!

We had the same problem. This fixed it for us
project-root$ mysql.server stop
project-root$ gem uninstall mysql2
project-root$ bundle install
project-root$ mysql.server start

That's an issue with the latest mysql version that is installed via homebrew.
5.6.x creates the problem. downgrading to 5.5.x solved the issue for me.
You can install old formula versions pretty easily with homebrew:
brew versions mysql will give you the sha you have to checkout in /usr/local to be able to install an old version
cd /usr/local
git checkout 336c976
brew info mysql
This will show you 5.5.29 as the mysql version. You can then uninstall mysql based on these instructions and reinstall simply by running
brew install mysql
and running through the normal installation process with homebrew:
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
Hope that helps.
You can checkout master in /usr/local after installing the old version of mysql after that again. The brew versions command even gives you the command to just checkout the formula for mysql but I don't think that has any advantages over just checking out the whole repository for the sha and then going back to master after installing the old mysql version.

We found that using the following fixes this for us:
brew install mysql --use-llvm
This is on a rails 2.3 ontop of REE (1.8.7) in rbenv on OSX 10.8. YMMV

I'm having the same issue on same configuration (mysql 5.6.12). I've just upgraded mysql with homebrew to version 5.6.13 and the problem is gone.

I struck this problem with mysql 5.6.16, freshly installed via Homebrew on Mavericks, along with rbenv and rails etc.
Decided to reboot before working through the other solutions here. Problem solved!
So if you haven't rebooted since installing mysql etc, I'd recommend restarting before working through the answers here.

What I found worked, was setting table_open_cache to a value no higher than 1000
table_open_cache=1000
I found this on the bug page, very last comment https://bugs.mysql.com/bug.php?id=71960

On Mavericks, this worked for me:
mysql.server stop
brew install mysql
mysql.server start
gem remove mysql2
gem install mysql2
I reinstalled Homebrew after upgrading to Mavericks. Homebrew installed the bottled version of MySQL 5.6.13.

Related

MySQL brew cannot run on macOS Monterey?

MySQL suddenly stopped working after updating from macOS Big Sur to Monterey (naive). Local Laravel dev environment suddenly lost connection to MySQL. Couldn't debug it properly (still learning), so decided to do a fresh MySQL installation via brew. Was installed through brew previously as well.
On the final step, mysql_secure_installation shows this:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
brew services start mysql
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/stranger/Library/LaunchAgents/homebrew.mxcl.mysql.plist` exited with 5.
Am I doing something wrong? Why would it suddenly drop?
Thanks!
Not a solution, but, according to the MySQL documentation, Monterey is not yet a supported platform.
MySQL Supported Platforms
I tried brew uninstall mysql, brew install mysql and then brew services restart mysql and it did the trick for me

How to install and start MySQL 5.7 on macOS BigSur (Apple Silicon) with Homebrew?

I need a specific version of MySQL (5.7) to be installed on my MacBook with M1.
I'm trying to do that with Homebrew.
brew install mysql#5.7
The output:
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
mysql#5.7 is keg-only, which means it was not symlinked into /opt/homebrew, because this is an alternate version of another formula.
If you need to have mysql#5.7 first in your PATH, run: echo 'export PATH="/opt/homebrew/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
For compilers to find mysql#5.7 you may need to set: export LDFLAGS="-L/opt/homebrew/opt/mysql#5.7/lib" export CPPFLAGS="-I/opt/homebrew/opt/mysql#5.7/include"
To have launchd start mysql#5.7 now and restart at login: brew services start mysql#5.7 Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/mysql#5.7/bin/mysql.server start
Right after that, I try to run:
echo 'export PATH="/opt/homebrew/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
source .zshrc
mysql_secure_installation
And get the error:
Securing the MySQL server deployment.
Enter password for user root:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Also, I've tried:
brew services start mysql#5.7
And also get the error:
Error: Permission denied # rb_sysopen - /Users/vivanc/Library/LaunchAgents/homebrew.mxcl.mysql#5.7.plist
Seems like there is a permissions-related problem.
Any advice is appreciated.
If you are running into issues like "Can't connect to local MySQL server through socket '/tmp/mysql.sock'" or "The post-install step did not complete successfully MySQL", and you installed a previous version of mysql (e.g. 8.x) previously, you may have been at the point where you need to clean everything before reinstalling your preferred version of mysql#x.x.
If you've already visited these to links:
Uninstall all those broken versions of MySQL and re-install it with Brew on Mac Mavericks (Coderwall) + Install MySQL 5.7 on macOS using Homebrew (github) and your're still having trouble with starting your mysql-service, you should try to also remove also /opt/homebrew/etc/my.cnf file.
Remove it together with all the related files too! Summary for an M1 Apple Silcion machine, after uninstalling via brew uninstall mysql or brew uninstall mysql#x.x, please remove:
/opt/homebrew/var/mysql
/opt/homebrew/etc/my.cnf
After this, everything worked like a fresh install (for me). Hope this saved someone's time.
While this question is specific to Apple Silicon and mysql 5.7, and I will address that in this answer, I would like to start by adding some general notes to save others time:
Homebrew supports mysql 5.7 for both intel and apple silicon.
https://formulae.brew.sh/formula/mysql#5.7
Homebrew supports mysql 5.6 for the intel chip, but not apple silicon:
https://formulae.brew.sh/formula/mysql#5.6
If you need 5.6 on apple silicon, it's probably a good idea to just settle with 5.7 since production will need to be upgraded eventually and the differences aren't that big.
In my situation I originally did brew install mysql and it gave me the latest mysql (currently 8.0). When I tried going back over it and doing brew install mysql#5.6, of course this didn't work due to not being supported on the m1 max (apple silicon). I ran into issues then trying to get brew install mysql#5.7 working. I followed some guides mentioning various suggestions. After playing with it for a while, it seems that running two versions of mysql at once will corrupt your mysql files and make it hard to work with and confuse homebrew.
I came across these guides:
brew install mysql on macOS
https://coderwall.com/p/os6woq/uninstall-all-those-broken-versions-of-mysql-and-re-install-it-with-brew-on-mac-mavericks
https://www.codegrepper.com/code-examples/shell/brew+uninstall+mysql
Before reading further, note that in my situation, I had a zip available for my whole local mysql database needs and could risk destroying what I have.
Warning! Reading further and executing these commands carelessly may delete your mysql storage. Make sure you have a backup.
brew remove mysql is a good command that got rid of my latest install.
I also needed brew remove mysql#5.7 even though this is the version I'm trying to install, but they were stepping on each other's foot...
brew cleanup is nice, I noticed it freed up some lock files.
I don't recall having any luck with:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
but you can try it.
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist has worked for me.
But note there will also be another file in there for your 5.7 setup.
I'd recommend:
cd ~/Library/LaunchAgents/ then look around to see if you have any mysql* in there. Then if you do, such as homebrew.mxcl.mysql#5.7.plist, then remove it.
These are some that worked for me:
sudo rm -rf /usr/local/var/mysql
rm /usr/local/etc/my.cnf
rm /usr/local/etc/my.cnf.default
Also:
cd opt/homebrew/var
Then if you notice a mysql directory in there, remove it.
It's possible you might have docker or something else similar also running mysql or mysqld.
ps -ax | grep "[m]ysql"
(Note the brackets and quotes in the above is to prevent the grep from showing up in the process list and matching itself unlike the lazier version: ps -ax | grep mysql which will give the impression there's an extra mysql process running)
Once you're ready, please run:
brew services list
double-check you don't have mysql in there.
Then double check you don't have any mysql process running:
ps -ax | grep "[m]ysql"
This can happen for example if you enter mysqld for example....
You might need to do brew services stop mysql or brew services stop mysql#5.7 or similar and repeat steps if you see anything on the service list or process list.
Finally, you should be ready for a fresh install.
The fresh installation process should be rather straight forward:
brew install mysql#5.7
brew link --force mysql#5.7
brew services start mysql#5.7
Then run brew services list to make sure your installation worked correctly.
If you see it's green and "started", your installation was successful!
You should also run:
mysql_secure_installation
Then choose a password for root and go through the list of questions like validation, etc.
Once you're installed, you might also run into mysql mode issues.
cd /opt/homebrew/etc and you should find a my.cnf file.
Edit it using either vim or nano.
You should see something like:
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
Edit it and set the mysql mode. For example, I don't want the no_zero_in_date mode, so I use:
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
sql-mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Then restart mysql like so:
brew services restart mysql#5.7
Then double check you still have a green status "started":
brew services list
If you do, then you should have the no_zero_in_date mode disabled.
You can test it with a query:
SELECT ##sql_mode;
You should now have mysql 5.7 running on Apple Silicon and have the sql_mode set.
If you run into more troubleshooting, do your best to get into a known state such as uninstalled, doing a fresh install, or already installed with some version, etc.
I solved it after hours of searching, it was because I had not cleaned everything regarding my previous MySQL 8.X installation. I followed this and got suspicious when I realized I don't have most of the folders there. I then did a search for all folders named mysql on my computer and found a mysql folder in opt/homebrew/var. After removing it, reinstalling MySQL 5.7, and starting the server everything is working as expected.
When setting up my Apple M1 Macbook Pro I was experiencing the issue of the following error message being thrown:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
My fix was to modify the MySQL config file:
nano /usr/local/etc/my.cnf
Append the following lines:
tmpdir=/tmp
user=root
Then run:
brew services restart mysql#5.7
This fixed my issue, and I was then able to connect successfully with my DB client.
Seems like I found the solution (or workaround).
After installing the MySQL 5.7 with Homebrew just run:
mysql.server start
MySQL is started and then you are able to run mysql_secure_installation and mysql commands.
I got this warning:
You should change the ownership of these directories to your user.
sudo chown -R $(whoami) /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1
And make sure that your user has write permission.
chmod u+w /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1
I run those two command then it works.

Will the MAMP(PRO) mysql conflict with brew install mysql on macos

I'm trying to install a clean mysql on my macos Sierra. As I already installed brew, I decided to use this stackoverflow answer. Nevertheless, before installation, these pre-install check is done:
I have already checked the bash line with mysql command, and found no such command.
I brew info mysql, and found mysql Not Installed.
However, I still have doubt over that I might not have a clean installation environment. So I use the find / -name mysql -type d to search all the directory for mysql. And I've found there are mysql included in MAMP. As these line writes:
/Applications/MAMP/db/mysql
/Applications/MAMP/db/mysql/mysql
/Applications/MAMP/Library/lib/perl5/site_perl/5.22.0/darwin-2level/auto/DBD/mysql
/Applications/MAMP/Library/lib/perl5/site_perl/5.22.0/darwin-2level/DBD/mysql
I've installed MAMP about two years ago. Now I just want to learn mysql in command line rather than one-click environment like MAMP. And I wonder if I can install the mysql using brew to get a generic mysql environment if I don't uninstall the MAMP? And WHY is that the MAMP will/will not affect the mysql installed from brew?
Not really, they wont' be on conflict.
Mamp use another port, and brew use default mysqm port 3306
Mamp use this foder: /Applications/MAMP/Library/bin/mysql
Brew use his own folder : /usr/local/Cellar/mysql/(version...)
with brew you don't need use path to execute bin files, just type 'mysql -uroot -p' on the terminal.

How to install MySQL 5.7.x on Mac OS Sierra

I need to obtain the functionality of MySQL 5.7. I had zend server 9 (first 9 version). After reinstallation of zend server (it doesn't supports upgrade).
- Result: MySQL 5.5 !
May there exist solutions for:
Upgrade mysql inside zend framework?
Install other apache2.4+mysql5.7+php7 developer server?
some other solution.
Requirements:
PHP7.0.8 or later
MySQL 5.7
Apache 2.4 or later
Uninstall your existing version of mysql and install mysql 5.7
mysql.server stop # kill the running process
brew uninstall mysql # uninstall mysql
brew update # update brew
brew install mysql#5.7 # install mysql 5.7
Now you can start mysql.server with /usr/local/opt/mysql#5.7/bin/mysql.server start
Modify your PATH variable in ~/.bash_profile so you can start it with just mysql.server start
# ~/.bash_profile
export PATH="/usr/local/opt/mysql#5.7/bin:$PATH"
mysql.com offers a automatic dmg installer, which I find I have the most success with. It typically installs in /usr/local/mysql so you may want to try deleting any other installations you have on your system first.
You can download it here:
https://dev.mysql.com/downloads/mysql/
As for apache and php I find that I typically stick with the ones preloaded into os x, you can There are a number of articles out there on how to active these, but I believe its just a matter of uncommenting the php LoadModule line in /etc/apache2/httpd.conf
#LoadModule php5_module libexec/apache2/libphp5.so
and then starting apache in terminal with the apachectl command.
I installed https://dbngin.com/
Then after that i went to /usr/local
Then I saw a folder name for each of the MySQL versions I had installed using dbngin
Then after that I added it to path. Then that was it.
echo 'export PATH="/usr/local/path-to-mysql/bin:$PATH"' >> ~/.zshrc
You know, after MySQL is uninstalled and reinstalled via homebrew, it will prompt: 1. Upgrade to macOS 10.13; 2. Upgrade to Xcode 9.2.
If you don't want to upgrade the system or Xcode version, then request the MySQL official website to download:
https://downloads.mysql.com/archives/community/
The MySQL version suitable for macOS 10.12 ranges from 5.7.17 to 5.7.23.

Centos 5.5 - upgrade Mysql to 5.1 and get it working

I am not a server administrator but hope that one can help me. Thanks!
I have a fresh CentOS 5.5 with VirtualMin installed.
I get this when starting MySQL:
Failed to start database :
sh: /etc/rc.d/init.d/mysqld: No such file or directory
IN ADDITION, I wish to upgrade from 5.0 mysql to 5.1 mysql. I have already used this command:
rpm -Uvh MySQL-shared-community-5.1.56-1.rhel5.i386.rpm
But in Webmin my MySQL version still shows up as mysql 5.0.77-4.el5_5.4, rather than upgrade 5.0 rpm just installs 5.1 along side it.
How do I upgrade to 5.1 and configure it to work? Thanks much.
If you already have mysql installed, try the "--replacepkgs" argument together with the "rpm" command.
Regarding sh: /etc/rc.d/init.d/mysqld: No such file or directory, it should be fixed once you install the newer mysql successfully.