The post-install step did not complete successfully MySQL Mac OS Sierra - mysql

[(pyEnv) Anants-MacBook-Pro:litibackend anantchandra$ brew postinstall mysql
==> Postinstalling mysql
==> /usr/local/Cellar/mysql/8.0.11/bin/mysqld --initialize-insecure --user=anantchandra --basedir=/usr/local/Cellar/mysql/8.0.11 --datadir=/usr/local/var/mysql --tmpdir=/tmp
Last 15 lines from /Users/anantchandra/Library/Logs/Homebrew/mysql/post_install.01.mysqld:
2018-06-15 04:41:04 -0700
/usr/local/Cellar/mysql/8.0.11/bin/mysqld
--initialize-insecure
--user=anantchandra
--basedir=/usr/local/Cellar/mysql/8.0.11
--datadir=/usr/local/var/mysql
--tmpdir=/tmp
2018-06-15T11:41:04.901191Z 0 [System] [MY-013169] [Server] /usr/local/Cellar/mysql/8.0.11/bin/mysqld (mysqld 8.0.11) initializing of server in progress as process 37841
2018-06-15T11:41:04.903504Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2018-06-15T11:41:04.903537Z 0 [ERROR] [MY-010119] [Server] Aborting
2018-06-15T11:41:04.903701Z 0 [System] [MY-010910] [Server] /usr/local/Cellar/mysql/8.0.11/bin/mysqld: Shutdown complete (mysqld 8.0.11) Homebrew.
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall mysql`

I was able to go back to 5.7 for anyone who wants to:
brew uninstall mysql
brew install mysql#5.7
brew link --force mysql#5.7
mysql.server start
mysql_secure_installation
After all that, I'm back in 5.7 with all my databases intact. In my case, I knew the data in the databases wasn't crucial, so I didn't attempt to backup the data in advance. Worked fine for me. If you have irreplaceable data in your local databases, you might want to tread carefully. I didn't lose data, but I don't want anyone else to lose data on my advice either. ;)
Normally, I don't mind a MySQL upgrade, but 8.0 looks to have compatibility issues I'd like to vet before going forward, and in the meantime, I'd rather be back on a version that doesn't force me to deal with those issues.

The installation or re-installation, brew install mysql, created the default data directory, and the post installation does not handle it...
Simply move the existing data directory (this moves it to a sibling directory, named with the process id of the shell):
$ mv /usr/local/var/mysql /usr/local/var/mysql-$$
or might need super user privileges...
$ sudo mv /usr/local/var/mysql /usr/local/var/mysql-$$
Then run:
$ brew postinstall mysql

First, backup the content of your data directory: /usr/local/var/mysql by copying it to a safe place.
The error happens because the post-install script check if a file /usr/local/var/mysql/mysql/user.frm exists. For whatever reason you don't have this file. The postinstall script then tries to install a new MySQL 8 database by running mysqld with --initialize-insecure but as the directory already contains some data from MySQL 5.7 the script halts.
Here is the correspoding part of the script in mysql.rb:
def post_install
# Make sure the datadir exists
datadir.mkpath
unless (datadir/"mysql/user.frm").exist?
ENV["TMPDIR"] = nil
system bin/"mysqld", "--initialize-insecure", "--user=#{ENV["USER"]}",
"--basedir=#{prefix}", "--datadir=#{datadir}", "--tmpdir=/tmp"
end
end
There is several possible solutions. If you can still run your MySQL 5.7 database, export everything with mysqldump then install a fresh MySQL 8 database by removing all content in /usr/local/var/mysql and then import everything back again. Another solution, is to use the mysql_upgrade tool.
P.S.: Personally, I use the formula mysql#5.7 and I will in the future switch to MariaDB.

According to this link, below command saves me on macOS Mojave:
sudo chown -R $(whoami) /usr/local/*

Related

Homebrew MySQL 8.0.18 on macOS 10.15 Catalina won't run as service

Another macOS upgrade + another MySQL upgrade = another set of problems.
I can't seem to get MySQL 8.0.18 to run as a homebrew service on macOS 10.15 Catalina. Please show me the error of my ways.
Here's what I did:
brew install mysql
brew pin mysql
touch /tmp/mysql.sock
mysql.server start
unset TMPDIR
mysql_secure_installation
mysql.server stop
sudo brew services start mysql
Here's what I expected:
MySQL to run merrily along as a homebrew service as user root.
Here's what happened:
MySQL falls right over and dies, leaving a cryptic last statement in /usr/local/var/mysql/[host.domain.com].err:
"[ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!"
Additional information:
MySQL runs fine through subsequent reboots so long as I launch it manually:
sudo reboot now
ssh [servername.domain.com]
touch /tmp/mysql.sock
mysql.server start
Here's the /usr/local/var/mysql/[servername.domain.com].err file contents:
2019-10-20T18:02:14.6NZ mysqld_safe Logging to '/usr/local/var/mysql/moriarty.farces.com.err'.
2019-10-20T18:02:14.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2019-10-20T18:02:14.670494Z 0 [System] [MY-010116] [Server] /usr/local/Cellar/mysql/8.0.18/bin/mysqld (mysqld 8.0.18) starting as process 557
2019-10-20T18:02:14.685511Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2019-10-20T18:02:15.617696Z 0 [System] [MY-010229] [Server] Starting crash recovery...
2019-10-20T18:02:15.626461Z 0 [System] [MY-010232] [Server] Crash recovery finished.
2019-10-20T18:02:15.795626Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-10-20T18:02:15.833541Z 0 [System] [MY-010931] [Server] /usr/local/Cellar/mysql/8.0.18/bin/mysqld: ready for connections. Version: '8.0.18' socket: '/tmp/mysql.sock' port: 3306 Homebrew.
2019-10-20T18:02:15.993739Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/tmp/mysqlx.sock' bind-address: '127.0.0.1' port: 33060
After a reboot, when I try to run MySQL as a Homebrew service:
sudo reboot now
ssh [servername.domain.com]
sudo brew services start mysql
MySQL fails with the following error recorded in the /usr/local/var/mysql/[servername.domain.com].err file:
2019-10-20T18:44:13.780394Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2019-10-20T18:44:13.780503Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-10-20T18:44:13.780727Z 0 [System] [MY-010910] [Server] /usr/local/opt/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.18) Homebrew.
2019-10-20T18:44:13.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/moriarty.farces.com.pid ended
Never use sudo with command brew. It will ruin the ownership of related files. Running brew as root is not supported. (I'm talking about brew, not mysqld)
Quote from Homebrew doc
tl;dr Sudo is dangerous, and you installed TextMate.app without sudo anyway.
Homebrew refuses to work using sudo.
Warnings from the source code of brew
check-run-command-as-root() {
...
odie <<EOS
Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
EOS
}
Solutions
Disable the service and remove the launchdaemon.
# stop and unload the launchdaemon
sudo launchctl unload -w /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
# remove the lauchdaemon file
sudo rm -f /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
sudo rm -f /tmp/mysql.sock /tmp/mysqlx.sock
Fix ownership of homebrew related files
# For x86 Mac
sudo chown -R "$(whoami):admin" /usr/local/*
# For M1 Mac
sudo chown -R "$(whoami):admin" /opt/homebrew/*
# it will take some time
Re-enable the MySQL service.
# DO NOT USE "sudo brew"
brew services start mysql
Update:
Seems some of you are not familiar with Homebrew. I'll explain how Homebrew manages services here.
mysqld listens at port 3306 by default, which is not a privileged port. So there's no need to start mysqld with root. systemd starts mysqld with root on Linux, but macOS is not Linux.
Homebrew manages services with the help of launchd, which is kind of a systemd alternative on macOS. launchd starts a foreground process and manages it for you, just like what systemd does.
brew services start/stop mysql will suffice your need. It creates a launchd file ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist, starts mysqld with it (run by current user).
/usr/local/mysql/support-files/mysql.server is a shell script brought by MySQL to help you start mysqld. Using it directly is not recommended unless you build MySQL from source outside Homebrew. If you're using Homebrew, just stick with brew services. Or say it in another way, if you're using Homebrew, you should do things in the Homebrew way.
MySQL refuses to start on Catalina because elevated privileges are required to run it.
You need to locate your MySQL bin directory first:
which mysqld
The result you get should be similar to /usr/local/mysql/bin/mysql.
The support-files directory contains the required scripts needed to start-up MySQL, and is located in the same directory where the bin directory is located. In the above example, the support files directory will be /usr/local/mysql/support-files/.
Start the MySQL service with administrative privileges as follows:
sudo /usr/local/mysql/support-files/mysql.server start
N.B: In case the output from the first command you run is different from the one above, adjust the support-files directory accordingly as explained above.
Oh geez, he says, shaking his head...
This was a case of RTFM, and I didn't. Here's the applicable page from the MySQL 8.0 Reference manual. And here's the magic juju:
Add user=root to the [mysqld] section of the /usr/local/etc/my.cnf file, like so:
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
user=root
I just encountered the same issue after upgrading to Catalina.
If I started MySQL server from system preferences it would just start and stop itself. The solution for me was:
sudo /usr/local/mysql-8.0.17-macos10.14-x86_64/support-files/mysql.server start
instead of: /usr/local/mysql/support-files/mysql.server start
I've encountered a lot of problems with Catalina. Now I can't start/stop mysql server from system preferences, only from terminal.
It's my first post so I hope this helps, I only registered to answer you since you're the only one I found with the same question.
I solved like this:
Remove MySQL completely Watching: https://gist.github.com/vitorbritto/0555879fe4414d18569d
Install MySQL with Download do MySQL community server
https://dev.mysql.com/downloads/mysql/
And Done! Successfully!

MySQL privilege tables

I downgraded from 5.6 to 5.5 and now I can't start mysql. Log files show the following:
50421 12:11:10 [ERROR] /usr/sbin/mysqld: Incorrect information in file: './mysql/proxies_priv.frm'
150421 12:11:10 [ERROR] Fatal error: Can't open and lock privilege tables: Incorrect information in file: './mysql/proxies_priv.frm'
I've done the following to try and resolve but no joy:
chgrp -R mysql /var/lib/mysql
chown -R mysql /var/lib/mysql
and I've also tried the following:
mysql_install_db --user=mysql --ldata=/var/lib/mysql
Which gives this error message:
Installing MySQL system tables...
150421 12:18:01 [ERROR] /usr/sbin/mysqld: Incorrect information in file: './mysql/tables_priv.frm'
ERROR: 1033 Incorrect information in file: './mysql/tables_priv.frm'
I have Googled the problem for about an hour now and am still struggling. Any help appreciated.
I dealt with this by first purging mysql using:
sudo apt-get purge mysql-server-<version>
Then I deleted everything in/var/lib/mysql and ran
sudo apt-get install mysql-server-<version>
I've recently had to deal with this problem as well. Before an upgrade, it's always a good idea to backup the mysql system tables. That way, if you need to rollback, you can get yourself back to a good state.
That being said, here we are. Try this:
1. rm -rf /var/lib/mysql/mysql/* (As suggested by user3392517)
2. mysql_install_db --user=mysql --ldata=/var/lib/mysql
3. start mysqld
4. mysql_upgrade --force
As with most errors that takes day or more to resolve i resorted to extreme measures:
rm -rf /var/lib/mysql/mysql/*
Fixed the problem.
Note: Data loss did occur, but this a development server so I did not care.
Delete the file as root or sudo
rm /var/lib/mysql/mysql/proxies_priv.frm
Then restart MySQL.
I didn't lose any data this way.

MySQL on ubuntu 12.04 won't run after MySQL Workbench installed

Recently I installed MySQL Workbench 6.2 and used it to create ER diagrams of the MySQL 5.5.41 databases I'm working with on Ubuntu 12.04. Everything worked fine until I restarted Ubuntu and suddenly mysql was no longer running. Running mysqld from the command line results in this:
150216 12:50:37 [ERROR] Can't read from messagefile '/usr/share/mysql/english/errmsg.sys'
150216 12:50:37 [Warning] Can't create test file /var/lib/mysql/euler.lower-test
150216 12:50:37 [Warning] Can't create test file /var/lib/mysql/euler.lower-test
mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 13)
150216 12:50:37 [ERROR] Aborting
150216 12:50:37 [Note]
The file /usr/share/mysql/english/errmsg.sys exists, owned by root, with permissions 644. The directory /var/lib/mysql exists, owned by mysql, with permissions 700.
I'm guessing that the installation of Workbench changed something (maybe config files) so that mysql is no longer working, but after a fair amount of Internet research, I have not discovered how to solve this problem. Any help will be greatly appreciated.
Seems like file permission problem. Try running mysqld again using sudo
If this doesn't help, maybe you shouldn't be starting it directly via mysqld. Check if the installer package added a service
sudo service --status-all | grep mysql
And if one exist, use it to start mysql, typically:
sudo service mysqld start
Also don't forget to check if mysqld is already running. If so you can't start duplicate process. I know this sound silly but has happened to me before
ps -ef | grep mysqld

Can't get MySQL to work on OS X 10.9

I know there are tons of posts about this problem but, I have tried all the solutions I have seen, and none are working. I have been working on this for two days now...it seems like I should be able to get a simple install working. Here are the facts:
I downloaded mysql-5.6.15-osx10.7-x86_64.dmg from the MySQL site. I opened and ran the mysql-5.6.15-osx10.7-x86_64.pkg. Then I went to the command line and tried a long list of commands to start MySQL and NOTHING works.
Here is a list of some of my attempts and their results:
~ $ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)
~ $ mysqld
2014-01-13 19:52:20 0 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
2014-01-13 19:52:20 0 [Warning] Using unique option prefix thread_cache instead of thread_cache_size is deprecated and will be removed in a future release. Please use the full name instead.
2014-01-13 19:52:20 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-01-13 19:52:20 953 [Warning] Can't create test file /usr/local/mysql-5.6.15-osx10.7-x86_64/data/rogerknwlessmbp.lower-test
2014-01-13 19:52:20 953 [Warning] Can't create test file /usr/local/mysql-5.6.15-osx10.7-x86_64/data/rogerknwlessmbp.lower-test
mysqld: File './mysql-bin.index' not found (Errcode: 13 - Permission denied)
2014-01-13 19:52:20 953 [ERROR] Aborting
~ $ sudo mysqld
After several warnings about deprecated settings, I got:
2014-01-13 20:27:55 1311 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2014-01-13 20:27:55 1311 [ERROR] Aborting
2014-01-13 20:27:55 1311 [Note] Binlog end
~ $ sudo /usr/local/mysql/bin/mysqld_safe
140113 20:30:08 mysqld_safe Logging to '/usr/local/mysql/data/rogerknwlessmbp.err'.
140113 20:30:09 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
140113 20:30:11 mysqld_safe mysqld from pid file /usr/local/mysql/data/rogerknwlessmbp.pid ended
~ $ sudo /usr/local/mysql/support-files/mysql.server start
Starting MySQL
... ERROR! The server quit without updating PID file (/usr/local/mysql/data/rogerknwlessmbp.pid).
I read one post that said this was a permissions issue, and that the solution was to rebuild permissions using the Disk Utility app in Mac OS X. I have done that with no effect.
Over the past few days, I have tried so many things, I can't keep track but, they all get about the same results. I have tried installing earlier versions, different versions (x86), and on and on. If anyone has a recommendation as to what else I might try I would really appreciate it. I would love to get MySQL working on this machine. It was on my machine and working at one point but, I uninstalled it because of some problems I was having long ago. Now, I can't get it to work.
Thanks for any advice you can give.
I believe socket should link to /var/lib/mysql/mysql.sock
You can edit a file that is usually in /etc/mysql/ folder and fine a line starting with socket=
Try putting /var/lib/mysql/mysql.sock as a value for this.
I believe you can see a location for mysql.sock by running this command
$ mysqladmin variables | grep socket
If it's /tmp/mysql.sock
you can try sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock too
Finally! I got it to install and to start.
Essentially, the turning point was viewing the installation logs and working through the errors that were reported there. I had not completely removed all the old files, and one of them was causing an error.
If you are installing onto mac using the .dmg file, you can hit Ctrl+L to view the log file, and identify, specifically, what the problems are.
The MySQL portion of this guide worked for me:
Download the “x86, 64bit” DMG version of MySQL 5.6.x for OS X 10.7
from mysql.com and install the pkg, the startup item and the pref
pane.
Open the pref pane and start the MySQL Server.
Update the path by editing ~/.bash_profile and add:
export PATH=~/bin:/usr/local/bin:/usr/local/mysql/bin:$PATH
at top of file.
Set up MySQL root password:
mysqladmin -u root password {new-password}
mysqladmin -u root> -p{new-password} -h localhost password {new-password}
mysqladmin -u root -p{new-password} reload
Clear the history file by typing history -c so that {new-password}
isn’t in plain text on the disk.
Now ensure that the mysql.sock file can be found by PHP: Ensure that
MySQL is running
sudo mkdir /var/mysql sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
This answer on StackOverflow explains it pretty well: https://stackoverflow.com/a/15472270/1067124.
Backup your your /usr/local/mysql/data/ folder first
Delete old installation (this will also remove your data!):
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*
Install MySQL from http://dev.mysql.com/downloads/mysql/5.1.html
Restore /usr/local/mysql/data/
OS Yosemite and Maverick has been having these issues to DYLD_LIBRAARY PATH
Found here
Please Use this link to view the answer already on stack overflow.
I see someone has given an answer that works in the original poster's case, but as this is such a common problem I thought I'd post the solution I found to the same problem in my own case.
I thought I knew what I was doing as I had successfully installed MySQL (mysql-5.6.15-osx10.7-x86_64.dmg) on two machines running Mavericks following the procedures at https://discussions.apple.com/docs/DOC-3082, which also allow you to install Perl drivers. However when I tried on a laptop that had previously been running Snow Leopard (sic) I hit the dreaded error message, and although a mysql directory had been generated at /var/mysql/ no socket was generated there or anywhere else.
The problem must have been caused by the previous version of MySQL I had installed, as the solution was to do a complete uninstall (http://johnmcostaiii.net/2011/removing-mysql-osx-lion/) and then reinstall. So if you have a early version of MySQL installed and you hit this problem, this might be the solution. It worked for me.

MySQL data directory location

I installed MySQL on a Mac after downloading its DMG file version 64 bit.
While trying to create a database it gave me error 1006 -- can't create database. After browsing a number of website, it seems due to user ownership setting of MySQL "data directory" location that needs to be changed.
Where is MySQL default data directory? I could not find /var/lib/mysql in localhost.
THANKS.
If the software is Sequel pro the default install mysql on Mac OSX has data located here:
/usr/local/var/mysql
See if you have a file located under /etc/my.cnf. If so, it should tell you where the data directory is.
For example:
[mysqld]
set-variable=local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
...
My guess is that your mysql might be installed to /usr/local/mysql-XXX.
You may find these MySQL reference manual links useful:
Installing MySQL 8.0 on MacOS
Installing MySQL 5.7 on MacOS
Installing MySQL 5.6 on MacOS
Installing MySQL 5.5 on MacOS
As suggested, I edited this message to place a proper answer.
The 'physical' location of the MySQL database is under /usr/local/mysql
The mysql is a symlink to the current active MySQL installation, in my case the exact folder is mysql-5.6.10-osx10.7-x86_64.
Inside that folder you'll see another data folder, inside it are RESTRICTED folders with your databases.
You can't actually see the size of your databases (that was my issue) from the Finder because the folder are protected, you can though see from the terminal with sudo du -sh /usr/local/mysql/data/{your-database-name} and like this you'll get a nice formatted output with the size.
In those folder you have different files with all the folders present in your database, so it's safer to check the db's folder to get a size.
That's it. Enjoy!
Well, if yo don't know where is my.cnf (such Mac OS X installed with homebrew), or You are looking found others choices:
ps aux|grep mysql
abkrim 1160 0.0 0.2 2913068 26224 ?? R Tue04PM 0:14.63 /usr/local/opt/mariadb/bin/mysqld --basedir=/usr/local/opt/mariadb --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/opt/mariadb/lib/plugin --bind-address=127.0.0.1 --log-error=/usr/local/var/mysql/iMac-2.local.err --pid-file=iMac-2.local.pid
You get datadir=/usr/local/var/mysql
On M1 and homebrew the "data directory" is:
/opt/homebrew/var/mysql
And the main path is:
/opt/homebrew/Cellar/mysql
Check where is the root folder of mysql with:
mysql_config
If you are using macOS {mine 'High Sierra'} and Installed XAMPP
You can find mysql data files;
Go to : /Applications/XAMPP/xamppfiles/var/mysql/
If you install MySQL via homebrew on MacOS, you might need to delete your old data directory /usr/local/var/mysql. Otherwise, it will fail during the initialization process with the following error:
==> /usr/local/Cellar/mysql/8.0.16/bin/mysqld --initialize-insecure --user=hohoho --basedir=/usr/local/Cellar/mysql/8.0.16 --datadir=/usr/local/var/mysql --tmpdir=/tmp
2019-07-17T16:30:51.828887Z 0 [System] [MY-013169] [Server] /usr/local/Cellar/mysql/8.0.16/bin/mysqld (mysqld 8.0.16) initializing of server in progress as process 93487
2019-07-17T16:30:51.830375Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2019-07-17T16:30:51.830381Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /usr/local/var/mysql/ is unusable. You can safely remove it.
2019-07-17T16:30:51.830410Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-07-17T16:30:51.830540Z 0 [System] [MY-010910] [Server] /usr/local/Cellar/mysql/8.0.16/bin/mysqld: Shutdown complete (mysqld 8.0.16) Homebrew.
If you are using Homebrew to install MySQL#5.7, the location is
/usr/local/Homebrew/var/mysql
I don't know if the location is the same for other versions.