two installs of mysql on osx? - mysql

I've been running MySQL Ver 14.14 Distrib 5.6.10, for osx10.6 (x86_64) for a while with no issues. I had to hard restart my laptop tonight, and a while after it started, i tried to access a dev database. I got the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
here are the commands and responses:
$ which mysql
#=> mysql: aliased to nocorrect mysql
$ unset TMPDIR
$ mysql_install_db
#=> FATAL ERROR: Could not find ./bin/my_print_defaults
$ sudo /usr/local/mysql/support-files/mysql.server start
#=> ERROR! The server quit without updating PID file (/usr/local/mysql/whoamis-MacBook-Pro.local.pid).
$ mysqld
#=> 2013-10-19 00:11:08 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-10-19 00:11:08 5029 [Warning] Can't create test file /usr/local/var/mysql/whoamis-MacBook-Pro.lower-test
2013-10-19 00:11:08 5029 [Warning] Can't create test file /usr/local/var/mysql/whoamis-MacBook-Pro.lower-test
mysqld: Can't change dir to '/usr/local/var/mysql/' (Errcode: 2 - No such file or directory)
2013-10-19 00:11:08 5029 [ERROR] Aborting
2013-10-19 00:11:08 5029 [Note] Binlog end
2013-10-19 00:11:08 5029 [Note] mysqld: Shutdown complete
$ usr/local/Cellar/mysql
sure enough, there was a mysql installation here, too. So there's one in /usr/local/mysql and there's one in /usr/local/Cellar/mysql, but there's not one in /usr/local/var which is where mysqld, at least, seems to be looking. It's worth noting that the system preferences tool as well as mySQL Workbench server tool doesn't successfully start the server, either. Any idea where to proceed from here?

As per this site
$ sudo mv my.cnf old_my.cnf
$ Password:
$ sudo /usr/local/mysql/support-files/mysql.server start
Starting MySQL
SUCCESS!
It works! However, it's good to note that this isn't perhaps the 'best' way - as Brad Quellhorst notes in the comments:
The better advice would be "Remove anything you recently added to my.cnf and remove the file as a last resort" Unless you already have a bare-defaults my.cnf, by removing it you're destroying any configuration options in favor of defaults, which among other things, are rather insecure. Binding MySQL to all open IPs and removing any caching, replication, and data information is not the solution to a typo'd configuration statement.

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!

Warning: The post-install step did not complete successfully, When trying to install mysql using brew in Mac OS High Sierra

Trying to install mysql5.7 with brew on Mac OS High Sierra
I have used the following commands:
sudo rm -rf /usr/local/var/mysql/
brew install mysql#5.7
brew postinstall mysql#5.7
Got the below errors
2019-10-05T02:59:24.136970Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-05T02:59:24.138997Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2019-10-05T02:59:24.215676Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-10-05T02:59:24.232279Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-10-05T02:59:24.286214Z 0 [ERROR] unknown variable 'mysqlx-bind-address=127.0.0.1'
2019-10-05T02:59:24.286281Z 0 [ERROR] Aborting
Because of which i couldn't able to do
mysql_secure_installation
which throws
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
If you are able to find your my.cnf file (for me, it was in /usr/local/etc/my.cnf) you should remove the below line:
mysqlx-bind-address = 127.0.0.1
Like #sbkrogers says, must to remove the line, but since I use Homebrew to install mysql#5.7:
My file is located on /opt/homebrew/etc/my.cnf. Where remove
mysqlx-bind-address = 127.0.0.1
After the first aborted installation, following folders need to be deleted:
/opt/homebrew/Cellar/mysql#5.7
/opt/homebrew/var/mysql
...then try to install again. brew install mysql
After the installation was success, restart terminal
For our case, it is due to mysql was installed earlier before mariadb. Therefore the my.cnf is already created. The my.cnf from mysql is missing some lines needed for mariadb.
The steps we did to fix:
# uninstall mariadb
brew remove mariadb
# rename my.cnf to something else
# the homebrew etc directory is on /opt/homebrew/etc
# cd /opt/homebrew/etc
mv my.cnf my.cnf.default
# re-install
brew install mariadb
# restart and check the status
brew services restart mariadb && brew service info mariadb

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

[(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/*

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

Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root

I am not sure how to fix this:
dyn-72-33-214-45:python mona$ sudo /usr/local/mysql/bin/mysqld stop
2014-09-06 09:49:04 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-09-06 09:49:04 22992 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql-5.6.15-osx10.7-x86_64/data/ is case insensitive
2014-09-06 09:49:04 22992 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2014-09-06 09:49:04 22992 [ERROR] Aborting
2014-09-06 09:49:04 22992 [Note] Binlog end
2014-09-06 09:49:04 22992 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
I'm using OS X (Yosemite) and this error happened to me when I upgraded from Mavericks to Yosemite. It was solved by using this command
sudo /usr/local/mysql/support-files/mysql.server start
you might try this if you logged in with root:
mysqld --user=root
The MySQL daemon should not be executed as the system user root which (normally) do not has any restrictions.
According to your cli, I suppose you wanted to execute the initscript instead:
sudo /etc/init.d/mysql stop
Another way would be to use the mysqladmin tool (note, root is the MySQL root user here, not the system root user):
/usr/local/mysql/bin/mysqladmin --port=8889 -u root shutdown
Try this for Amazon Linux AMI or for centOS
sudo service mysqld restart
How i resolved this was following the 4th point in this url: https://dev.mysql.com/doc/refman/8.0/en/changing-mysql-user.html
Edit my.cnf
Add user = root under under [mysqld] group of the file
If this doesn't work then make sure you have changed the password from default.
I also had the same problem and able to resolve after using below command
/root/mysql-sandboxes/3320/bin/mysqld --defaults-file=/root/mysql-sandboxes/3320/my.cnf --user=root &
osx could be using launchctl to launch mysql. Try this:
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist
Donal had the right solution for me. However, the updated plist name for 2017 is
com.oracle.oss.mysql.mysqld.plist.
in my case (RHEL7 and MariaDB) this works.
sudo systemctl restart mariadb
On top of #mise's answer,
After I installed MacOS Mojave, I also had to change files ownership on all my MAMP directory and contents).
From the Finder, I went in Application/MAMP, showed files info (cmd + i) and in permissions section added myself with read & write perms, then from the little gear applied to all the children.
The correct answer that worked for me on CentOS is
/etc/init.d/mysql restart
which is an init script and not /etc/init.d/mysqld restart, which is binary
The is in fact comment of #MrTux on the question which worked for me. It took quite a bit of my time hence posting it as answer.
to run mysqld as root user from command line you need to add the switch/options
--user=root
mariadb run as system root user
I had this issue while running MySQL on Minikube (Ubuntu box) and I solved it with:
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
Very weird, but I got this error when I made a typo in the my.cnf file.
So it had nothing to do with the user directive not defined or not running as root-user.
My mistake was:
bind=192.168.1.2
instead of
bind-address=192.168.1.2