mysql_install_db gives FATAL ERROR: Could not find my-default.cnf - mysql

I've download MySQL and I'm trying to setup the MySQL grant tables, but when I type:
scripts/mysql_install_db --basedir=/usr/local
I get the error above.
I'm not sure how to fix it, as my-default.cnf is in the support_files directory and I believe I'm setting the basedir correctly.
(This is on mac btw)

(I'm assuming you're using Homebrew, since I hit the same issue trying to do the same thing on Homebrew on my macbook)
I believe you need to point it to the actual mysql directory in the cellar as its basedir, not at /usr/local (since that's just things symlinked from the cellar dir).
So, in my case, I had to use:
$ mysql_install_db --basedir=/usr/local/Cellar/mysql/5.6.10

Need copy /usr/share/my.cnf
Try this:
sudo cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf
sudo mysql_install_db
Its help for me on Ubuntu 14.04 and mysql 5.6.33

To extend to rascalking's answer, the current mysql installs to /usr/local/mysql/ via brew.
But to get over timestamp issue and the permission issue the full command will be:
sudo mysql_install_db --basedir=/usr/local/mysql --explicit_defaults_for_timestamp
Don't forget to set your password first incase you skipped the instruction:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'

Related

Not able to get mysql running on my mac

I'm trying to install mysql on my mac but unable to start server. When I try to start mysql server, I get this error in the logs: Can't start server: can't create PID file: Permission denied. Can't create/write to file ~/Downloads/mysql-5.5.32-osx10.6-x86_64/data/HOSTNAME.pid. I have symlinked /usr/local/mysql to ~/Downloads/mysql-5.5.32-osx10.6-x86_64. And all files/directories under /usr/local/mysql and ~/Downloads/mysql-5.5.32-osx10.6-x86_64 are owned by mysql. I'm trying start mysql server as root. Searched everywhere for this, but no luck. I tried with mysql 5.5 and 5.6. Same problem with both the versions. Any clues?
I'd highly recommend you install mysql using Homebrew. To do this:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
brew install mysql
The output of the second command may give you a few extra steps. Follow them and you should be set.
You have to start it as an administrator. Write sudo and a space followed by the command you will use to start MySQL.
Use below permission to grant permissions:
check your mysqld location, mine is this:
do this:
ls -ld /usr/local/var/mysql
sudo chmod a+w /usr/local/var/mysql

After MySQL install via Brew, I get the error - The server quit without updating PID file

Ok, I've searched all over and have spent quite a bit of my time installing, uninstalling, trying various option but without success.
I'm on Mac OS X Lion (10.7.3) and am trying to setup a Python, MySQL.
I successfully installed Python and MySQL via HomeBrew.
Python works great.
After MySQL Installation, I followed the first 2 steps - unset and the mysql_install_db commands.
Now, when I try to start mysql "mysql.server start", I get the following error
ERROR! The server quit without updating PID file (/usr/local/var/mysql/Brajeshwar.local.pid).
Brajeshwar is my username on my machine.
I found that it was a permissions issue with the mysql folder.
chmod -R 777 /usr/local/var/mysql/
solved it for me.
EDIT 2012/09/18:
As pointed out by Kane, make sure the mysql database is properly set up before doing anything else. See “PID error on mysql.server start?” for more info.
Original answer kept for history's sake:
It most likely is a permissions issue. Check /usr/local/var/mysql/*.err. Mine said:
120314 16:30:14 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
120314 16:30:14 mysqld_safe mysqld from pid file /usr/local/var/mysql/janmoesen.local.pid ended
I also had to do this:
sudo chown _mysql /usr/local/var/mysql/*
I ended up with completely reinstalling of mysql, and it finally worked out.
WARNING This will remove all of your databases, so make sure to save dumps first.
brew remove mysql
brew cleanup
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /usr/local/var/mysql
brew install mysql
mysqld --initialize --explicit_defaults_for_timestamp
mysql.server start # no sudo!
I had this issue on mac 10.10.5 Yosemite
What I did to solve this
cd /usr/local/var/mysql
sudo rm *.err && sudo rm *.pid
sudo reboot
sudo mysql.server start
I had the same issue on OS X El Capitan, here's the terminal command sequence that fixed it for me.
Delete error files (you'll have to change the path depending on your setup)
sudo rm /usr/local/mysql/data/*.err
Find the info for the mysql process that's still running and kill it:
ps -A | grep -m1 mysql | awk '{print $1}' | sudo xargs kill -9
Now restart MySQL:
/usr/local/mysql/support-files/mysql.server start
November, 2014: If you're getting this error on MySQL 5.6.x on Mac OS X Mavericks or Yosemite and want to use MySQL with PHP locally (/tmp/mysql.sock is where PHP PDO expects to find the sock file), here is what fixed it for me:
1) Uncomment the default homebrew config file lines and edit as below
$ sudo vi /usr/local/Cellar/mysql/5.6.21/my.cnf
...
basedir = /usr/local/Cellar/mysql/5.6.21
datadir = /usr/local/var/mysql
port = 3306
server_id = <UNIQUE_NUMBER_HERE_OR_LEAVE_COMMENTED_OUT>
socket = /tmp/mysql.sock
pid-file = /usr/local/var/mysql/[BOXNAME].local.pid
....
BOXNAME is what you have in your System Prefs -> Network as the unique id for your computer on the network.
2) Set permissions on all the files in the mysql datadir. These were all owned by [my_username]. MySQL is very picky about this and refuses to create the pid file unless it (the user _mysql) owns the directory.
$ sudo chown -R _mysql:mysql /usr/local/var/mysql
3) Start MySQL using the bash helper/wrapper script:
$ sudo mysql.server start
Starting MySQL
. SUCCESS!
Hope that helps. If the above doesn't work for you, try to run the mysqld_safe binary manually in the Cellar/mysql/VERSION_/bin/ directory and check what the settings are (if it runs)
sudo /usr/local/Cellar/mysql/5.6.12/bin/mysqld_safe &
If that runs, you can
ps aux | grep mysql
and see something like
[username] 6881 0.0 2.7 3081392 454836 ?? S 8:52AM 0:00.54 /usr/local/Cellar/mysql/5.6.21/bin/mysqld --basedir=/usr/local/Cellar/mysql/5.6.21 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/5.6.21/lib/plugin --verbose --log-error=/usr/local/var/mysql/BOXNAME.local.err --pid-file=/usr/local/var/mysql/BOXNAME.local.pid
I'm not sure why that worked for me but it shows you where I got the my.cnf config file options from. You can also use the command line options to try to troubleshoot when starting mysqld manually.
If you do run manage to run MySQL server using mysqld_safe, you may have to do this to shut it down before trying the mysql.server bash helper. Resist the urge to kill -9 [PID] because you can corrupt your data.
mysqladmin -uroot shutdown
Good luck!
This worked for me:
sudo chmod -R 777 /usr/local/var/mysql/
sudo /usr/local/mysql/support-files/mysql.server start
This worked for me on 10.12.2 :
$ rm /usr/local/var/mysql/*.err
then
$ brew services restart mysql
If I remember correctly it is a permissions issue. Try to 'touch' and 'chmod' the pid file or the folder the file is held in.
My issue was that I started server as sudo once and then tried to restart as a local user.
Here mysql was not able to write to '.err' file owned by root.
I had to remove that file and restart the server:
sudo rm /usr/local/var/mysql/*.err
mysql.server start
Try this (OSX)
Step 1:
ps -aux | grep mysql
Then kill the 4 digits PID number
Step 2: kill 1965
Step 3: mysql.server start
Or having hard time to locate those PID numbers, try this below
Step 1 again: ps -aux | grep mysql
Step 2 again: killall
Step 3 again: mysql.server start
I’ve got a similar problem with MySQL on a Mac (Mac Os X Could not startup MySQL Server. Reason: 255 and also “ERROR! The server quit without updating PID file”). After a long trial and error process, finally in order to restore the file permissions, I’ve just do that:
launch the Disk Utilities.app
choose my drive on the left panel
click on the “Repair disk permissions” button
This did the trick for me. Hoping this can help someone else.
Find usr/local/var/mysql/your_computer_name.local.err file and understand the more information about error
Location : /usr/local/var/mysql/your_computer_name.local.err
It's probably problem with permissions
Find if mysql is running and kill it
ps -ef | grep mysql
kill -9 PID
where PID is second column value
2. check ownership of mysql
ls -laF /usr/local/var/mysql/
if it is owned by root, change it mysql or your user name

sudo chown -R mysql /usr/local/var/mysql/
For me it worked with:
unset TMPDIR
mysql_install_db --user=`whoami` --basedir="$(brew --prefix mariadb)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
What worked for me was:
Go to your mysql installation directory
sudo chmod -R 777 data
Then go back one directory
cd support-files/
sudo ./mysql.server start
After that the server started running.
But the problem with this method is that I have to repeat this every time I want to start the mysql now. Don't know why it started behaving like this suddenly.
I had this problem on Linux, but the cause is relevant to any mysql installation. In my case, the server was crashing before startup was complete and the pid file updated. The error messages were seen when starting up mysqld directly instead of via "service mysql start".
In my case, the cause was the partition where the log files were located being full. Removing log files permitted mysql to start again. To test for this issue, go to the location of your mysql activity logs, and do df ..
If you have upgraded your mysql installation to 8.x, check if your previous version is supported for upgradation.
If not, mysql will not work! Uninstall your mysql along with all configuration files in /usr/local/var/mysql (remove the whole folder). Reinstall mysql.
NOTE: reinstalling might lead to loss of data.
Please check the log , you will get more detailed information .
Use the below command to tail the error log
tail -100 /usr/local/var/mysql/<user_name>.local.err
For me , one of the directory is missing , once created the server has started .
The key takeaway is to check the .err file, by default on Mac OSX it's in /usr/local/var/mysql.
That log filed revealed to me that I had to delete the following files:
ibdata1
ib_logfile0
ib_logfile1
Running MySQL with mysql.start worked successfully after that. Note that deleting those files will likely causes data loss.
sudo chmod -R 777 /usr/local/var/mysql/
works for me.
I had the same issue:
But the situation was, every time i try to enter:
/usr/local/mysql/support-files/mysql.server start
a file named localhost.pid is created instead of iMax0.local.pid which was stated in the error:
ERROR! The server quit without updating PID file (/usr/local/mysql/data/iMax0.local.pid).
Solution that works for me was copying localhost.pid and renaming it to iMax0.local.pid.
My solution on OSX El Capitan was:
sudo chmod ugo+w /tmp
It was broken suddenly.
The error was:
ERROR! The server quit without updating PID file
and the log showed:
Can't start server : Bind on unix socket: Permission denied
It might also be helpful to note, that under OSX there is no my.cnf file by default and not needed by default, which I did not know. Good luck!
$ sudo mysql.server restart
It works for me.
I had the similar issue. But the following commands saved me.
cd /usr/local/Cellar
sudo chown _mysql mysql
This is file permission problem.
Check disk permissions and repair.
Osx => Cmd+Space => Disk Utilty => Verify Disk Permissions.
Verify completed after Repair Disk Permissions.
mysql.server start command is worked succesfuly.
None of the answers worked for me. However, I simply did sudo mysql.server start and it worked nicely.
Also, for me, it did NOT show permissions issue in *.err file.
all solutions above doesn't work for me.
but they give me some clues to fix this error.
mysql.server start ----error The server quit without updating PID file
I installed mysql#5.7 on my macbook mojave with homebrew
brew install mysql#5.7
mysql error log located in /usr/local/var/mysql/IU.lan.err,there is one line in it:
Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
after trying many posts in goole search engine,I turned to baidu
https://blog.csdn.net/xhool/article/details/52398042
inspired by this post,I found the solution:
rm /usr/local/var/mysql/*
mysqld --initialize
a random password for root user will be shown in bash.
but the command mysql -uroot -p[theRandomPassword] cant work.so I have to reset password.
create a init file with contents like this
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
place it in any directory easy to find,such as Desktop
mysqld --init-file=[YourInitFile] &
many logs printed on your screen.
mysql -uroot -pMyNewPass
enjoy your high-version mysql!
Happened to me because I was actually switching from MariaDB to Mysql.
Switching back to MariaDB solved this.
I'm guessing the existing database wasn't compatible.
Solved this using sudo chown -R _mysql:_mysql /usr/local/var/mysql
Thanks to Matteo Alessani
This error may be actually being show because mysql is already started. Try to see the current status by:
mysql.server status

Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

I am on a server that has afresh install on RHEL 5. I was able to install Apache and PHP just fine., but I am having serious trouble with my MySQL installation. I tried the following:
yum install mysql-server mysql
And didn't get any errors or conflicts. Then I tried to start mysql with the following commands:
chkconfig --levels 235 mysqld on
service mysqld start
And get Timeout error occurred trying to start MySQL Daemon.
I checked my logs and see this error:
[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
I'm not sure where to go from here.
For reference I am using RHEL 5 and installed the latest versions of PHP 5 and Apache.
After chown and chgrp'ing /var/lib/mysql per the answer by #Bad Programmer, you may also have to execute the following command:
sudo mysql_install_db --user=mysql --ldata=/var/lib/mysql
Then restart your mysqld.
Uninstall mysql using yum remove mysql*
Recursively delete /usr/bin/mysql and /var/lib/mysql
Delete the file /etc/my.cnf.rmp
Use ps -e to check the processes to make sure mysql isn't still running.
Reboot server with reboot
Run yum install mysql-server. This also seems to install the mysql client as a dependency.
Give mysql ownership and group priveleges with:
chown -R mysql /var/lib/mysql
chgrp -R mysql /var/lib/mysql
Use service mysqld start to start MySQL Daemon.
I had this issue on arch linux as well. The issue was pacman installed the package in a different location than MySQL was expecting. I was able to fix the issue with this:
sudo mysql_install_db --user=mysql --basedir=/usr/ --ldata=/var/lib/mysql/
Hope this helps someone!
The root of my problem seemed to be selinux, which was turned on (enforcing)
automatically on OS install.
I wanted my mysql in /data.
After verifying that my.cnf had:
datadir=/data/mysql
(and leaving the socket at /var/lib/mysql)
I executed the command to turn off selinux for mysqld
(alternative is to turn it off completely):
setsebool -P mysqld_disable_trans=1
I ran the following commands:
> chown -R mysql .
> chgrp -R mysql .
> mysql_install_db --user=mysql
I started the mysql daemon and everything worked fine after that.
mysql_install_db –-user=mysql --ldata=/var/lib/mysql
Worked for me in Centos 7
initialize mysql before start on windows.
mysqld --initialize
When download mysql zip version, if run mysqld directly, you'll get this error:
2016-02-18T07:23:48.318481Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2016-02-18T07:23:48.319482Z 0 [ERROR] Aborting
You have to run below command first:
mysqld --initialize
Make sure your data folder is empty before this command.
Just this command is enough to do the magic on centos 6.6
mysql_install_db
I just met the same problem with mysql 5.7 on OSX:
rm -rf {datadir}
mysqld --initialize --datadir {datadir}
mysqld --datadir {datadir}
If you move your datadir, you not only need to give the new datadir permissions, but you need to ensure all parent directories have permission.
I moved my datadir to a hard drive, mounted in Ubuntu as:
/media/*user*/Data/
and my datadir was Databases.
I had to set permissions to 771 to each of the media, user and Data directories:
sudo chmod 771 *DIR*
If this does not work, another way you can get mysql to work is to change user in /etc/mysql/my.cnf to root; though there are no doubt some issues with doing that from a security perspective.
For myself, I had to do:
yum remove mysql*
rm -rf /var/lib/mysql/
cp /etc/my.cnf ~/my.cnf.bkup
yum install -y mysql-server mysql-client
mysql_install_db
chown -R mysql:mysql /var/lib/mysql
chown -R mysql:mysql /var/log/mysql
service mysql start
Then I was able to get back into my databases and configure them again after I nuked them the first go around.
In my case the path of MySQL data folder had a special character "ç" and it make me get...
Fatal error: Can't open and lock privilege tables: Table 'mysql.host'
doesn't exist.
I'm have removed all special characters and everything works.
On CentOS EL 6 and perhaps on earlier versions there is one way to get into this same mess.
Install CentOS EL6 with a minimal installation. For example I used kickstart to install the following:
%packages
#core
acpid
bison
cmake
dhcp-common
flex
gcc
gcc-c++
git
libaio-devel
make
man
ncurses-devel
perl
ntp
ntpdate
pciutils
tar
tcpdump
wget
%end
You will find that one of the dependencies of the above list is mysql-libs. I found that my system has a default my.cnf in /etc and this contains:
[mysqld]
dataddir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
When you build from the Generic Linux (Architecture Independent), Compressed TAR Archive your default data directory is /usr/local/mysql/data which conflicts with the /etc/my.cnf already present which defines datadir=/var/lib/mysql. Also the pid-file defined in the same file does not have permissions for the mysql user/group to write to it in /var/run/mysqld.
A quick remedy is to mv /etc/my.cnf /etc/my.cnf.old which should get your generic source procedure working.
Of course the experience is different of you use the source RPMs.
I had the same issue in trying to start the server and followed the "checked" solution.
But still had the problem. The issue was the my /etc/my.cnf file was not pointing to my
designated datadir as defined when I executed the mysql_install_db with --datadir defined. Once I updated this, the server started correctly.
If you have a server which used to happily run MySQL, but now gives this error, then an uninstall and re-install of MySQL is overkill.
In my case, the server died and took a few disk blocks with it. This affected a few files, including /var/lib/mysql/mysql/host.frm and /var/lib/mysql/mysql/proc.frm
Luckily, I could copy these from another server, and this got me past that table error.
I got similar error on overlayfs (overlay2) that is the default on Docker for Mac.
The error happens when starting mysql on the image, after creating a image with mysql.
2017-11-15T06:44:22.141481Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table storage engine for 'user' doesn't have this option
Switching to "aufs" solved the issue.
(On Docker for Mac, the "daemon.json" can be edited by choosing "Preferences..." menu, and selecting "Daemon" tab, and selecting "Advanced" tab.)
/etc/docker/daemon.json :
{
"storage-driver" : "aufs",
"debug" : true,
"experimental" : true
}
Ref:
https://github.com/moby/moby/issues/35503
https://qiita.com/Hige-Moja/items/7b1208f16997e2aa9028
In Windows run the following commands in the command prompt as adminstrator
Step 1:
mysql_install_db.exe
Step 2:
mysqld --initialize
Step 3:
mysqld --console
Step 4:
In windows
Step 4:
mysqladmin -u root password "XXXXXXX"
Step 5:
mysql -u root -p
My case on Ubuntu 14.04.2 LTS was similar to others with my.cnf, but for me the cause was a ~/.my.cnf that was leftover from a previous installation. After deleting that file and purging/re-installing mysql-server, it worked fine.

brew install mysql on macOS

I'm trying to setup up MySQL on mac os 10.6 using Homebrew by brew install mysql 5.1.52.
Everything goes well and I am also successful with the mysql_install_db.
However when I try to connect to the server using:
/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin -u root password 'mypass'
I get:
/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin: connect to server at 'localhost'
failed error: 'Access denied for user 'root'#'localhost' (using password: NO)'
I've tried to access mysqladmin or mysql using -u root -proot as well,
but it doesn't work with or without password.
This is a brand new installation on a brand new machine and as far as I know the new installation must be accessible without a root password. I also tried:
/usr/local/Cellar/mysql/5.1.52/bin/mysql_secure_installation
but I also get
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I think one can end up in this position with older versions of mysql already installed. I had the same problem and none of the above solutions worked for me. I fixed it thus:
Used brew's remove & cleanup commands, unloaded the launchctl script, then deleted the mysql directory in /usr/local/var, deleted my existing /etc/my.cnf (leave that one up to you, should it apply) and launchctl plist
Updated the string for the plist. Note also your alternate security script directory will be based on which version of MySQL you are installing.
Step-by-step:
brew remove mysql
brew cleanup
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /usr/local/var/mysql
I then started from scratch:
installed mysql with brew install mysql
ran the commands brew suggested: (see note: below)
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
Start mysql with mysql.server start command, to be able to log on it
Used the alternate security script:
/usr/local/Cellar/mysql/5.5.10/bin/mysql_secure_installation
Followed the launchctl section from the brew package script output such as,
#start
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
#stop
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Note: the --force bit on brew cleanup will also cleanup outdated kegs, think it's a new-ish homebrew feature.
Note the second: a commenter says step 2 is not required. I don't want to test it, so YMMV!
Here are detailed instructions combining getting rid of all MySQL from your Mac then installing it The Brew Way as Sedorner wrote above:
Remove MySQL completely per The Tech Lab
ps -ax | grep mysql
stop and kill any MySQL processes
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/mysql*
sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*
sudo rm -rf /tmp/mysql*
try to run mysql, it shouldn't work
Brew install MySQL per user Sedorner from this StackOverflow answer
brew doctor and fix any errors
brew remove mysql
brew cleanup
brew update
brew install mysql
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp # whoami is executed inline
mysql.server start
run the commands Brew suggests, add MySQL to launchctl so it automatically launches at startup
mysql should now work and be running all the time as expected
Godspeed.
Had the same problem. Seems like there is something wrong with the set up instructions or the initial tables that are being created. This is how I got mysqld running on my machine.
If the mysqld server is already running on your Mac, stop it first with:
launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
Start the mysqld server with the following command which lets anyone log in with full permissions.
mysqld_safe --skip-grant-tables
Then run mysql -u root which should now let you log in successfully without a password. The following command should reset all the root passwords.
UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root'; FLUSH PRIVILEGES;
Now if you kill the running copy of mysqld_safe and start it up again without the skip-grant-tables option, you should be able to log in with mysql -u root -p and the new password you just set.
If brew installed MySQL 5.7, the process is a bit different than for previous versions.
In order to reset the root password, proceed as follows:
sudo rm -rf /usr/local/var/mysql
mysqld --initialize
A temporary password will be printed to the console and it can only be used for updating the root password:
mysql.server start
echo "ALTER USER 'root'#'localhost' IDENTIFIED BY 'my-new-password';" | mysql -uroot --password=TEMPORARY_PASSWORD
Homebrew
First, make sure you have homebrew installed
Run brew doctor and address anything homebrew wants you to fix
Run brew install mysql
Run brew services restart mysql
Run mysql.server start
Run mysql_secure_installation
Okay I had the same issue and solved it. For some reason the mysql_secure_installation script doesn't work out of the box when using Homebrew to install mysql, so I did it manually. On the CLI enter:
mysql -u root
That should get you into mysql. Now do the following (taken from mysql_secure_installation):
UPDATE mysql.user SET Password=PASSWORD('your_new_pass') WHERE User='root';
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'
DROP DATABASE test;
FLUSH PRIVILEGES;
Now exit and get back into mysql with: mysql -u root -p
I had the same problem just now. If you brew info mysql and follow the steps it looks like the root password should be new-password if I remember correctly. I was seeing the same thing you are seeing. This article helped me the most.
It turned out I didn't have any accounts created for me. When I logged in after running mysqld_safe and did select * from user; no rows were returned. I opened the MySQLWorkbench with the mysqld_safe running and added a root account with all the privs I expected. This are working well for me now.
If mysql is already installed
Stop mysql completely.
mysql.server stop <-- may need editing based on your version
ps -ef | grep mysql <-- lists processes with mysql in their name
kill [PID] <-- kill the processes by PID
Remove files. Instructions above are good. I'll add:
sudo find /. -name "*mysql*"
Using your judgement, rm -rf these files. Note that many programs have drivers for mysql which you do not want to remove. For example, don't delete stuff in a PHP install's directory. Do remove stuff in its own mysql directory.
Install
Hopefully you have homebrew. If not, download it.
I like to run brew as root, but I don't think you have to. Edit 2018: you can't run brew as root anymore
sudo brew update
sudo brew install cmake <-- dependency for mysql, useful
sudo brew install openssl <-- dependency for mysql, useful
sudo brew info mysql <-- skim through this... it gives you some idea of what's coming next
sudo brew install mysql --with-embedded; say done <-- Installs mysql with the embedded server. Tells you when it finishes (my install took 10 minutes)
Afterwards
sudo chown -R mysql /usr/local/var/mysql/ <-- mysql wouldn't work for me until I ran this command
sudo mysql.server start <-- once again, the exact syntax may vary
Create users in mysql (http://dev.mysql.com/doc/refman/5.7/en/create-user.html). Remember to add a password for the root user.
TL;DR
MySQL server might not be running after installation with Brew. Try brew services start mysql or just mysql.server start if you don't want MySQL to run as a background service.
Full Story:
I just installed MySQL (stable) 5.7.17 on a new MacBook Pro running Sierra and also got an error when running mysql_secure_installation:
Securing the MySQL server deployment.
Enter password for user root:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Say what?
According to the installation info from Brew, mysql_secure_installation should prompt me to... secure the installation. I figured the MySQL server might not be running and rightly so. Running brew services start mysql and then mysql_secure_installation worked like a charm.
Here is an update for MySQL 5.7
bash --version
GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin17.0.0)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
#========================================
brew --version
Homebrew 1.7.6
Homebrew/homebrew-core (git revision eeb08; last commit 2018-09-27)
Homebrew/homebrew-cask (git revision c9f62; last commit 2018-09-27)
#========================================
mysql --version
mysql Ver 14.14 Distrib 5.7.23, for osx10.13 (x86_64) using EditLine wrapper
#========================================
system_profiler SPSoftwareDataType
Software:
System Software Overview:
System Version: macOS 10.13.3 (17D47)
Kernel Version: Darwin 17.4.0
Boot Volume: Macintosh HD
Boot Mode: Normal
Computer Name: EdisonMacHomeBj
User Name: Edison (edison)
Secure Virtual Memory: Enabled
System Integrity Protection: Disabled
Time since boot: 6 days 23:13
brew remove mysql#5.7
brew cleanup
mv /usr/local/var/mysql /usr/local/var/mysql.bak
brew install mysql#5.7
rm -rf /usr/local/var/mysql
#========================================
mysqld --initialize
2018-09-28T04:54:06.526061Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-09-28T04:54:06.542625Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2018-09-28T04:54:07.096637Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-09-28T04:54:07.132950Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-09-28T04:54:07.196824Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 87cf2f10-c2da-11e8-ac2d-ba163df10130.
2018-09-28T04:54:07.224871Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-09-28T04:54:07.366688Z 0 [Warning] CA certificate ca.pem is self signed.
2018-09-28T04:54:07.457954Z 1 [Note] A temporary password is generated for root#localhost: kq3K=JR8;GqZ
#========================================
mysql_secure_installation -uroot -p"kq3K=JR8;GqZ"
mysql_secure_installation: [Warning] Using a password on the command line interface can be insecure.
Securing the MySQL server deployment.
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: n
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
New password:
Re-enter new password:
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n
... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
Just to add something to previous answers - When upgrading from MySql 5.6 to MySql 8.0, I followed the steps provided here to make a clean uninstall, yet I got following errors
2019-11-05T07:57:31.359304Z 0 [ERROR] [MY-000077] [Server] /usr/local/Cellar/mysql/8.0.18/bin/mysqld: Error while setting value 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2019-11-05T07:57:31.359330Z 0 [ERROR] [MY-013236] [Server] The designated data directory /usr/local/var/mysql is unusable. You can remove all files that the server added to it.
2019-11-05T07:57:31.359413Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-11-05T07:57:31.359514Z 0 [Note] [MY-010120] [Server] Binlog end
Took me some time to figure it out. Found a clue here:
https://discourse.brew.sh/t/clean-removal-of-mysql/2251
So, the key to my problem was removing /usr/local/etc/my.cnf file after uninstall.
After that one last step, MySql finally started working.
Try by giving Grant permission Command of mysql
I had the same issue after I tried to restart mysql.
I use the following two aliases in my .profile for convenience
alias mysql-stop='launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist'
alias mysql-start='launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist'
After stoping mysql and then trying to restart I experienced the issue you were having. I looked into the launchctl load and it was reporting a “nothing found to load” error.
After a quick search I found this..
http://www.daveoncode.com/2013/02/01/solve-mac-osx-launchctl-nothing-found-to-load-error/
So I updated me mysql-start alias as follows
alias mysql-start='launchctl load -w -F ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist'
This solved my issue which may be useful for you.
None of the above answers (or any of the dozens of answers I saw elsewhere) worked for me when using brew with the most recent version of mysql and yosemite. I ended up installing a different mysql version via brew.
Specifying an older version by saying (for example)
brew install mysql56
Worked for me. Hope this helps someone. This was a frustrating problem that I felt like I was stuck on forever.
The "Base-Path" for Mysql is stored in /etc/my.cnf which is not updated when you do brew upgrade. Just open it and change the basedir value
For example, change this:
[mysqld]
basedir=/Users/3st/homebrew/Cellar/mysql/5.6.13
to point to the new version:
[mysqld]
basedir=/Users/3st/homebrew/Cellar/mysql/5.6.19
Restart mysql with:
mysql.server start
Try solution I provided for MariaDB, high change that it works with MySQL also:
MacOSX homebrew mysql root password
In short, try to login with your username! not root.
Try same name as your MacOS account username, e.g. johnsmit.
To login as root, issue:
mysql -u johnsmit
deleting /opt/homebrew/var/mysql did the job. Apparently there were mysql data (including password) so all this manipulations described above were to no avail.

PID error on mysql.server start?

I've just tried installing MySQL using homebrew (on Mac OS X 10.6), but I've run across an issue at the first hurdle. When trying to manually start the server (mysql.server start), I get the following error:
. ERROR! Manager of pid-file quit without updating file.
Unfortunately I'm not sure of which error logs or configuration files to check, as I've never installed MySQL in this way before.
I ran into this same problem when installing via homebrew. Make sure you run these commands (which are listed during install but easy to miss):
unset TMPDIR
mysql_install_db
You probably need to ensure that you're running mysql as the root user -- otherwise it won't have permission to write the PID file (thus the error you're receiving).
Try this:
sudo mysql.server start
You'll be prompted for your password. (this assumes that your user account has permissions to "sudo" -- which it should, unless it's setup as a restricted user account in OS X).
This may not be the only issue -- but it should get you to the next step anyway.
I ran into the same issue while trying to install MySQL 5.5.15 in Lion using homebrew and resolved the issue with:
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
and creating a the file ~/my.cnf
with the content:
[mysqld]
basedir=/usr/local/Cellar/mysql/5.5.15
datadir=/usr/local/var/mysql
basedir - should be your current MySQL instalation dir
datadir - should be the location of MySQL data
You can figure out that too location by watching the make command during the "brew install mysql" searching for something like this:
-DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/mysql/5.5.15 -DMYSQL_DATADIR=/usr/local/var/mysql -DINSTALL_MANDIR=/usr/local/Cellar/mysql
Where DCMAKE_INSTALL_PREFIX = basedir and DMYSQL_DATADIR = datadir
Nothing else really helped, but the following worked:
$ ps aux | grep mysql
tagir 27260 0.0 1.0 3562356 175120 ?? S 2:52PM 0:00.42 mysqld --skip-grant-tables
tagir 42704 0.0 0.0 2434840 784 s000 S+ 3:04PM 0:00.00 grep mysql
$ kill 27260
# Careful! This might erase your existing data
$ rm -rf /usr/local/var/mysql
$ mysqld --initialize
$ mysql.server start
These following two commands should solve your issue.
> unset TMPDIR
> mysql_install_db --verbose --user=\`whoami\` --basedir="$(brew
--prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
I am adding this here because I encountered this problem several times after installing other software. MySQL was working fine for days, then suddenly I get this error.
It seems to happen when I install something (eg. elasticsearch or Puma web server). The MySql permissions get reverted again (back to me, and not _mysql). No idea why.
MacOS Sierra
Homebrew 1.0.5-43-g41b2df8 (2016-10-02)
MySQL 5.7.15
So I have found that one cause of this is the permissions on the location where MySQL stores your databases, which by default is here:
/usr/local/var/mysql
If you look in that folder you will see a file
<your computer name>.err
If you look inside that file (more it or cat it) you will probably see this error:
[ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
If so then you know it is a permissions issue.
If you don't care, you can probably just run MySQL by just running mysqld (and leave that terminal open).
If you do care:
ls -al /usr/local/var/mysql
you will notice that the permissions are probably all set to you (your user account). This means mysql cannot mount your databases when you run it using the homebrew shortcut sudo mysql.server start [even though you are using sudo to run in 'admin' mode].
So, change the permissions:
$ sudo chown -R _mysql /usr/local/var/mysql
$ sudo chmod -R o+rwx /usr/local/var/mysql
Then it will work.
It appears that for whatever reason I can't comment below Immendes above, but on 10.8.2 with mySQL 5.6.10, in addition to verifying the db_install and adding the my.cnf, I also had to chown -R myusername /tmp/mysql.sock.
It appears that allowing mySQL to run under the user (as apposed to root or www as I woudl do on linux) is not the best idea in this regard (though Homebrew could update the formula -- beyond my scope and time).
brew postinstall mysql
delete document /opt/homebrew/var/mysql
brew postinstall mysql