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.
Related
My problem started off with me not being able to log in as root any more on my mysql install. I was attempting to run mysql without passwords turned on... but whenever I ran the command
# mysqld_safe --skip-grant-tables &
I would never get the prompt back. I was trying to follow these instructions to recover the password.
The screen just looks like this:
root#jj-SFF-PC:/usr/bin# mysqld_safe --skip-grant-tables
120816 11:40:53 mysqld_safe Logging to syslog.
120816 11:40:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
and I don't get a prompt to start typing the SQL commands to reset the password.
When I kill it by pressing CTRL + C, I get the following message:
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
If I retry the command and leave it long enough, I do get the following series of messages:
root#jj-SFF-PC:/run/mysqld# 120816 13:15:02 mysqld_safe Logging to syslog.
120816 13:15:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
120816 13:16:42 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[1]+ Done mysqld_safe --skip-grant-tables
root#jj-SFF-PC:/run/mysqld#
But then if I try to log in as root by doing:
# mysql -u root
I get the following error message:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I checked and /var/run/mysqld/mysqld.sock file doesn't not exist. The folder does, but not the file.
Also, I don't know if this helps or not, but I ran find / -name mysqld and it came up with:
/var/run/mysqld - folder
/usr/sbin/mysqld - file
/run/mysqld - folder
I don't know if this is normal or not. But I'm including this info just in case it helps.
I finally decided to uninstall and reinstall mysql.
apt-get remove mysql-server
apt-get remove mysql-client
apt-get remove mysql-common
apt-get remove phpmyadmin
After reinstalling all packages again in the same order as above, during the phpmyadmin install, I got the same error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
So I tried again to uninstall/reinstall. This time, after I uninstalled the packages, I also manually renamed all mysql files and directories to mysql.bad in their respective locations.
/var/lib/mysql
/var/lib/mysql/mysql
/var/log/mysql
/usr/lib/perl5/DBD/mysql
/usr/lib/perl5/auto/DBD/mysql
/usr/lib/mysql
/usr/bin/mysql
/usr/share/mysql
/usr/share/dbconfig-common/internal/mysql
/etc/init.d/mysql
/etc/apparmor.d/abstractions/mysql
/etc/mysql
Then I tried to reinstall mysql-server and mysql-client again. But I've noticed that it doesn't prompt me for a password. Isn't it supposed to ask for an admin password?
Try this command,
sudo service mysql start
To find all socket files on your system run:
sudo find / -type s
My Mysql server system had the socket open at /var/lib/mysql/mysql.sock
Once you find where the socket is being opened, add or edit the line to your /etc/my.cnf file with the path to the socket file:
socket=/var/lib/mysql/mysql.sock
Sometimes the system startup script that launched the command line executable specifies a flag --socket=path. This flag could override the my.cnf location, and that would result in a socket not being found where the my.cnf file indicates it should be. Then when you try to run the mysql command line client, it will read my.cnf to find the socket, but it will not find it since it deviates from where the server created one. So, Unless you care where the socket resides, just changing the my.cnf to match should work.
Then, stop the mysqld process. How you do this will vary by system.
If you're super user in the linux system, try one of the following if you don't know the specific method your Mysql setup uses:
service mysqld stop
/etc/init.d/mysqld stop
mysqladmin -u root -p shutdown
Some systems aren't setup to have an elegant way to stop mysql (or for some reason mysql doesn't respond) and you can force terminate mysql with either:
One step: pkill -9 mysqld
Two step (least preferred):
Find the process id of mysql with either pgrep mysql or ps aux | grep mysql | grep -v grep
Assuming the process id is 4969 terminate with kill -9 4969
After you do this you might want to look for a pid file in /var/run/mysqld/ and delete it
Make sure the permissions on your socket is such that whatever user mysqld is running as can read/write to it. An easy test is to open it up to full read/write and see if it still works:
chmod 777 /var/run/mysqld/mysqld.sock
If that fixes the issue, you can tailor the permissions and ownership of the socket as needed based on your security settings.
Also, the directory the socket resides in has to be reachable by the user running the mysqld process.
This error occurs due to multiple installations of mysql.
Run the command:
ps -A|grep mysql
Kill the process by using:
sudo pkill mysql
and then run command:
ps -A|grep mysqld
Also Kill this process by running:
sudo pkill mysqld
Now you are fully set just run the following commands:
service mysql restart
mysql -u root -p
Have very well working mysql again
The solution is way easier.
First, you have to locate(in Terminal with "sudo find / -type s") where your mysql.sock file is located. In my case it was in /opt/lampp/var/mysql/mysql.sock
Fire up Terminal and issue
sudo Nautilus
This starts your Files manager with super user privileges
From Nautilus navigate to where your mysql.sock file is located
Right click on the file and select Make Link
Rename the Link File to mysqld.sock then Right click on the file and Cut it
Go to /var/run and create a folder called mysqld and enter it
Now right click and Paste the Link File
Voila! You will now have a mysqld.sock file at /var/run/mysqld/mysqld.sock :)
Just Need to Start MySQL Service after installation:
For Ubuntu:
sudo service mysql start;
For CentOS or RHEL:
sudo service mysqld start;
There is a bug on Ubuntu with MySQL 5.6 and 5.7 where var/run/mysqld/ would disappear whenever MySQL service stopped or is rebooted. This prevents MySQL from running at all. Found this workaround, which isn't perfect, but at least it gets it running after stopping/reboot:
mkdir /var/run/mysqld/
chown mysqld /var/run/mysqld/
Make sure your inaccessible socket file path is same as '/var/run/mysqld/mysqld.sock', otherwise change the path as yours.
Stop the mysqld
$ sudo /etc/init.d/mysqld stop
If the process still runing;
$ sudo pkill -9 mysqld
Remove the mysql directory where socket going to create. For me it did not allowed to remove, so I had to forcefully remove.
$ sudo mkdir -p /var/run/mysqld
Set the ownership to the dirctory
$ sudo chown mysql:mysql /var/run/mysqld
Start mysql
$ sudo /etc/init.d/mysql start
Trying to connect mysql
$ sudo mysql -u dbuser -p
Okay just copy and paste these codes: This should be done in the terminal, inside a server, when your mysql database is not properly installed, and when you are getting this error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'.
Stop MySql
sudo /etc/init.d/mysqld stop
Restart it or start it
sudo /etc/init.d/mysqld restart or sudo /etc/init.d/mysqld start
Make a link like this and give it to the system
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
Run a secure installation which guides all the process you need to do to configure mysql
/usr/bin/mysql_secure_installation
I faced same error and found that it was due to upgradation of packages, So after restarting my system I resolved error.
I think due to sql libraries/ packages update that error occured, So try this if you are doing some upgrading :)
There is a lots of reason for this issue, but sometimes just restart the mysql server, it will fix the issue.
sudo service mysql restart
The answer of the user load step worked for me.
Sometimes is need edit the file in /etc/mysql/my.cnf add line to client
[client]
password = your_mysql_root_password
port = 3306
host = 127.0.0.1
socket = /var/lib/mysql/mysql.sock
Using XAMPP on ubuntu:
Create a folder called mysqld inside /var/run directory. You can accomplish that using the command sudo mkdir /var/run/mysqld.
Create a symbolic link to mysql.sock file that is created by the XAMPP server when it is started. You can use the command sudo ln -s /opt/lampp/var/mysql/mysql.sock /var/run/mysqld/mysqld.sock.
Note: The mysql.sock file is created when the server is started and removed when the server is stopped, so sometimes the link you created might appear to be broken but it should work as long as you have started the server using either sudo /opt/lampp/lampp start or any other means.
Start the server if it's not already running and try executing your program again.
Good luck! I hope you'll get away with it this time.
I think your MySQL server has not started. So start the server using one of the following commands.
#services mysql start
or
#/etc/init.d/mysql start
Why getting this error
I received new updates of mysql libraries so i updated my Kubuntu OS after that getting these errors.
Commands i tried and how i fixed it.
MySql-server is running correctly but when i tried to connect its giving
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'.
I checked /var/run/mysqld/mysqld.sock'. this directory.
My files did not existed.
I also tried these commands to connect but did not worked for me.
mysql -h 127.0.0.1 -P 3306 -u root -p
sudo service mysql start
After wasting round about 2 hours i found the solution
sudo apt-get clean
sudo apt-get update
sudo apt-get upgrade -f
After that everything fixed for me.
*Error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
solutions
finally uninstall and reinstall mysql. **
sudo apt-get remove mysql-server
sudo apt-get remove mysql-client
sudo apt-get remove mysql-common
sudo apt-get remove phpmyadmin
then install again by
sudo apt-get install mysql-server-5.6
After this operation, 164 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y press YES for complete installations
......
.......
At last you will get these lines....
Setting up libhtml-template-perl (2.95-1) ...
Setting up mysql-common-5.6 (5.6.16-1~exp1) ...
Processing triggers for libc-bin (2.19-0ubuntu6)
Processing triggers for ureadahead (0.100.0-16) ...
And then
root#ubuntu1404:~# mysql -u root -p (for every password first u
should use )
Enter password:
Note :Entered password should be same as the installation time
password of mysql(like .root,system,admin,rahul etc...)
Then type
USE rahul_db(database name);
Thanks.**
Temporary Solution
Maybe someone facing this problem. I am using Mysql Workbench on Ubuntu 14 and got this error.
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect
Find your socket file by running sudo find / -type s, in my case it was /run/mysqld/mysqld.sock
So, I just created a link to this file in tmp directory.
sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
Please note that this is a temporary solution since the file created will be under /tmp. See other answers for a permanent solution.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
in /etc/my.cnf add this lines:
[client]
socket=/var/lib/mysql/mysql.sock <= this path should be also same as is[mysqld]
And restart the service with:
service mysql restart
this worked for me
This was mentioned a couple of times already, but this worked immediately for me:
service mysql restart
you can find mysqld.sock in /var/run/mysqld if you have already installed mysql-server
by sudo apt-get install mysql-server
I just had this problem on Ubuntu 14.10
Turns that mysql-server was no longer installed (somehow it had been removed) but I couldn't just install it because there were some broken packages and dependency issues/conflicts.
In the end I had to reinstall mysql
sudo apt-get remove mysql-client
sudo apt-get install mysql-server
I had the exactly same issue. After struggling for an hour, I found a way of correcting it without reinstalling mysql-common, mysql-client, mysql-server.
First of all, go to "/var/run/mysqld". You will find that the mysql.sock does not exist. Simply remove the entire mysqld directory and recreate it and provide it necessary privileges.
# rm -rf /var/run/mysqld && mkdir /var/run/mysqld && chown mysql /var/run/mysqld/
Now, Kill the mysql process in it's entirety. It might be possible that it will show you "waiting for page cleaner" on running "/etc/init.d/mysql status" command even after shutting down the service.
To completely close the service, use
# pkill -9 mysqld
Once the process is killed, try starting it again using
# /etc/init.d/mysql start
And you will see that it works good! And also there will be no issue in stopping it too.
In My case two mysqld processes were running..
killed the optional processs by using
pkill -9 mysqld
If you have a lot of databases and tables on your system, and if you have innodb_file_per_table set in my.cnf, then your mysql server might have run out of opened objects / files (or rather the descriptors for these objects)
Set a new max number with
open-files-limit = 2048
and restart mysql.
This approach might help when the socket is not created at all, but really this might not not be the real problem, there is an underlying problem.
My solution;
Ubuntu 18.04 (WSL)
/etc/mysql/my.cnf
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
/etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
I changed the port. It's worked for me. You can write another port. Example 3355
I am using XAMPP on Ubuntu. I found this error when connecting database through terminal. I solve it without any configuration because default socket file path in XAMPP is written in "/opt/lampp/etc/my.cnf" as following:
[client]
#password = your_password
port = 3306
socket = /opt/lampp/var/mysql/mysql.sock
now you can connect just by giving this socket path parameter with mysql command on terminal like:
mysql -u root --socket /opt/lampp/var/mysql/mysql.sock
and it's done without any configuration.
If you don't want to type socket path everytime, then go for changing default path in my.cnf by "/var/run/mysqld/mysqld.sock". Provide permissions and restart mysql server.
Edit:
Recently I've installed Ubuntu 20.04 and trying to install MySQL server but my system were crashing and not working at all. So I've just completely removed MySQL and installed MariaDB. Its working like a charm without any problems.
Changing the host to 127.0.0.1 worked for me.
Edit the file in /etc/mysql/my.cnf and add the below mentioned line to the section: client
[client]
port = 3306
host = 127.0.0.1
socket = /var/lib/mysql/mysql.sock
After you are done with it. Execute the following command.
sudo service mysql start
I had similar problem on a CentOS VPS. If MySQL won't start or keeps crashing right after it starts, try these steps:
1) Find my.cnf file (mine was located in /etc/my.cnf) and add the line:
innodb_force_recovery = X
replacing X with a number from 1 to 6, starting from 1 and then incrementing if MySQL won't start. Setting to 4, 5 or 6 can delete your data so be carefull and read http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html before.
2) Restart MySQL service. Only SELECT will run and that's normal at this point.
3) Dump all your databases/schemas with mysqldump one by one, do not compress the dumps because you'd have to uncompress them later anyway.
4) Move (or delete!) only the bd's directories inside /var/lib/mysql, preserving the individual files in the root.
5) Stop MySQL and then uncomment the line added in 1). Start MySQL.
6) Recover all bd's dumped in 3).
Good luck!
I uninstalled mysql in Ubuntu 16.04 https://askubuntu.com/questions/172514/how-do-i-uninstall-mysql
I reinstalled mysql
https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-16-04
This seemed to work.
First create dir /var/run/mysqld
with command:
mkdir -p /var/run/mysqld
then add rigths to the dir
chown mysql:mysql /var/run/mysqld
after this try
mysql -u root
You must install mysql-server
apt install mysql-server
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.
This question already has answers here:
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)
(43 answers)
Closed 21 days ago.
I installed MySQL on Mac OS X Mountain Lion with homebrew install mysql, but when I tried mysql -u root I got the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
What does this error mean? How can I fix it?
You'll need to start MySQL before you can use the mysql command on your terminal. To do this, run brew services start mysql. By default, brew installs the MySQL database without a root password. To secure it run: mysql_secure_installation.
To connect run: mysql -uroot. root is the username name here.
This happened after the homebrew install and occurs due to permission issues. The following commands fixed the issue.
sudo chown -R _mysql:mysql /usr/local/var/mysql
sudo mysql.server start
It's probably because MySQL is installed but not yet running. [...] To verify that it's running, open up Activity Monitor and under "All Processes", search and verify you see the process "mysqld".
You can start it by installing "MySQL.prefPane".
The above quote is from the blog Obscured Clarity, "Install MySQL on Mac OS X", where you can also find the complete tutorial that I found most helpful.
Run: brew info mysql
And follow the instructions. From the description in the formula:
Set up databases to run AS YOUR USER ACCOUNT with:
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
To set up base tables in another folder, or use a different user to run
mysqld, view the help for mysql_install_db:
mysql_install_db --help
and view the MySQL documentation:
* http://dev.mysql.com/doc/refman/5.5/en/mysql-install-db.html
* http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html
As others have pointed out this is because MySQL is installed but the service isn't running. There are many ways to start the MySQL service and what worked for me is the below.
To start the service:
Go to "System Preference"
At the bottom pane there should be MySql icon.
Double click that to launch the 'MySQL Server Status' and press the button 'Start MySQL Server'
My env:
Mac Yosemite 10.10.3
Installed Package: /Volumes/mysql-advanced-5.6.24-osx10.8-x86_64
Solutions revolve around:
changing MySQL's permissions
sudo chown -R _mysql:mysql /usr/local/var/mysql
Starting a MySQL process
sudo mysql.server start
Just to add on a lot of great and useful answers that have been provided here and from many different posts, try specifying the host if the above commands did not resolve this issue for you, i.e
mysql -u root -p h127.0.0.1
The designated data directory /usr/local/var/mysql/ is unusable. You can remove all files that the server added to it.
MacOS:
$brew services stop mysql
$brew services list
$brew uninstall mysql
$brew install mysql
$brew postinstall mysql
If Any error found then run those cmd
! Warning: this will delete any databases on this server:
$sudo rm -rf /usr/local/var/mysql
$sudo rm /usr/local/etc/my.cnf
$brew postinstall mysql
$brew services start mysql
$mysql_secure_installation
Completed All process of secure installation then run
$mysql -u root -p
Congratulations you’ve just set up mysql!
Warning - this method will remove all of your databases in the /usr/local/var/mysql folder
I had MySQL installed with Homebrew, and the only thing that fixed this for me was re-installing MySQL.
On my company laptop, I didn't have permission to uninstall MySQL from my computer via Homebrew:
$ brew uninstall mysql --ignore-dependencies
Uninstalling /usr/local/Cellar/mysql/8.0.12... (255 files, 233.0MB)
Error: Permission denied # dir_s_rmdir - /usr/local/Cellar/mysql/8.0.12
So instead, I removed and reinstalled MySQL manually:
$ sudo rm -rf /usr/local/Cellar/mysql
$ brew cleanup
$ sudo rm -rf /usr/local/var/mysql
$ brew install mysql
And that worked!
Looks like your mysql server is not started. I usually run the stop command and then start it again:
mysqld stop
mysql.server start
Same error, and this works for me.
Below I'm including the latest instructions from brew install mysql so newer searches for this issue can benefit:
$ brew install mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.6.26.yosemite.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring mysql-5.6.26.yosemite.bottle.1.tar.gz
To connect:
mysql -uroot
To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start
In my case I loaded mysql now via launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist and was then able to launch $ mysql and be on my way.
This problem related to /usr/local/var/mysql folder access, I remove this folder and reinstall mysql.
uninstall mysql with brew :
brew uninstall mysql
sudo rm -r /usr/local/var/mysql
brew install mysql#8.0
mysql -u root
This solution works fine for me!
BUT YOU LOST ALL YOUR DATABASES! WARNING!
This fixed my issue when I restarted the mysql service. Just run:
brew services start mysql
In my case it was simply a matter of deleting a lock file.
sudo rm -f /tmp/mysql.sock.lock
Ough, that took me a while to figure out. I saw it in a comment. After installing mysql using brew, and starting the service (perhaps using sudo brew services start mysql) then run:
$ mysqld
And MySQL should be running for your thereafter.
For me it was simple as running:
/usr/local/opt/mysql/bin/mysqld_safe
instead of mysqld
I went through this issue and I managed to run mysql server using below solution
Install mysql through .dmg(https://dev.mysql.com/downloads/mysql/5.7.html), you will get mysql service panel in system preferences then start mysql from the panel and try
mysql -u root -p
Images attached for reference
just hit "brew services start mysql" in terminal
I found the solution to my problem. It was indeed because my MySQL server was not running.
It was caused by MySQL not being correctly set up on my machine, thus not being able to run.
To remedy this, I used a script which installs MySQL on Mac OSX Mountain Lion, which must have installed missing files.
Here is the link: http://code.macminivault.com/
Important Note: This script sets the root password as a randomly generated string, which it saves on the Desktop, so take care not to delete this file and to note the password. It also installs MySQL manager in your system preferences. I'm also not sure if removes any existing databases, so be careful about that.
After working on this for several hours what worked for me was
go to /etc/mysql/ and edit the my.cnf file. Add the following
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
AFTER USING ALL THE ABOVE SOLUTIONS, NOTHING WORKED FOR ME BUT THIS WORKED.
I you have installed MySQL using HomeBrew then check System Preferences > MySQL in your mac that MySQL Server is stopped if it is running stop it by clicking on Stop MySQL Server and start MySQL from terminal writing the command mysqlserver.start.
If it doesn't work you can also try:-
If you have also installed MySQL workbench then just uninstall MySQL workbench and MySQL and after that install MySQL first and then MySQL workbench.
I would recommend you to run
mysql.server start
before going to
mysql -u root -p
so as to make sure that the mysql server is running before trying to login into it
This happens many times what you start/restart a machine where by no mysql server is running.
I keep coming back to this post, I've encountered this error several times. It might have to do with importing all my databases after doing a fresh install.
I'm using homebrew. The only thing that used to fix it for me:
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
This morning, the issue returned after my machine decided to shut down overnight. The only thing that fixed it now was to upgrade mysql.
brew upgrade mysql
After trying many solutions, seems like the one that finally did the trick was to connect by IP. No longer file sockets getting deleted randomly.
Just update your MySQL client config (e.g. /usr/local/etc/my.cnf) with:
[client]
port = 3306
host=127.0.0.1
protocol=tcp
Probably you might have faced some issues during the homebrew mysql installation and mysql services might not be running. If that is the case, then it might be worth trying below steps to reinstall mysql properly and then try to connect.
sudo chown -R $(whoami) /usr/local/var
sudo chown -R $(whoami) /Library/Caches/Homebrew
brew uninstall mysql
brew install mysql
mysql.server start
mysql -uroot
Homebrew will absolutely never repair the permissions using a standard reinstall, and chasing down which folder/file is corrupted will take longer than it is worth.
In this case - blow away the mysql install manually and reinstall via homebrew. Takes about 2 minutes.
cd /usr/local/var
sudo rm -rf mysql
brew install mysql
Homebrew installs mysql insecure by default, so if you want a password:
mysql_secure_installation
Then fire it up.
mysql -uroot
After installing MySQL on my mac m1 macOS Monterey, using brew install mysql I got this info:
[System] [MY-013169] [Server] /opt/homebrew/Cellar/mysql/8.0.27_1/bin/mysqld (mysqld 8.0.27) initializing of server in progress as process 3624
[ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
[ERROR] [MY-013236] [Server] The designated data directory /opt/homebrew/var/mysql/ is unusable. You can remove all files that the server added to it.
[ERROR] [MY-010119] [Server] Aborting
[System] [MY-010910] [Server] /opt/homebrew/Cellar/mysql/8.0.27_1/bin/mysqld: Shutdown complete (mysqld 8.0.27) Homebrew.
and this warning:
Warning: The post-install step did not complete successfully You can
try again using: brew postinstall mysql
After that I try to start MySQL using brew services start mysql, and I got this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2)
I managed to fix it using:
> rm -rf ~/opt/homebrew/var/mysql/
> brew postinstall mysql
Now you can connect with mysql -uroot or mysql -uroot -p.
only this has made the trick for me
brew services start --all
(after trying all answers)
I managed to solve this issue by changing localhost to 127.0.0.1
For my case, just specify host as 127.0.0.1, instead of localhost:
$ bin/mysql -uroot -p -h127.0.0.1
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
if you are using Kali linux you might want to specify the host explicitly
do that with
mysql -h 127.0.0.1 -u root
where 127.0.0.1 is your localhost
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.
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