Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

血红的双手。 提交于 2019-11-28 17:01:24
David Schwartz

You need to follow the directions to install and start the server.

The command varies depending on how you installed MySQL. Try this first:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

If that fails:

cd /usr/local/mysql
sudo ./bin/mysqld_safe
(Enter your password, if necessary)
(Press Control-Z)
bg

Also, if you got this error and installed mysql via Homebrew, I found that this works (though you need to change "5.6.12" to your own version):

/usr/local/Cellar/mysql/5.6.12/bin/mysql.server restart

I just created a file ~/restartMysql.sh in my home directory (with only the line above in it) so that I can just use this whenever MySQL is acting up

Run the following on the command line :

$ mysql.server start
abbood

this post helped did it for me, I'll rewrite the steps here (note: i'll be also writing the output of your commands.. just so that you know you're on track)

first stop the server if running:

[root@servert1 ~]# /etc/init.d/mysqld stop
Stopping MySQL: [ OK ]

run an sql dameon on a separate thread

[root@servert1 ~]# mysqld_safe --skip-grant-tables &    
[1] 13694    
[root@servert1 ~]# Starting mysqld daemon with databases from /var/lib/mysql

open a separate shell window and type

[root@servert1 ~]# mysql -u root

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.0.77 Source distribution



Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

start using mysql

mysql> use mysql; 

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A



Database changed

update the user table manually with your new password (note: feel free to type mysql> show tables; just to get a perspective on where you are)

NOTE: from MySQL 5.7 passwords are in the authenication_string table, so the command is update user set authentication_string=password('testpass') where user='root';

mysql> update user set password=PASSWORD("testpass") where User='root';

Query OK, 3 rows affected (0.05 sec)

Rows matched: 3 Changed: 3 Warnings: 0

flush privileges (i'm not sure what this privileges is all about.. but it works)

mysql> flush privileges; 

Query OK, 0 rows affected (0.04 sec)

quit

mysql> quit

Bye

stop the server

NOTE: on OS X or macOS, mysql.server is located at /usr/local/mysql/support-files/.

mysql.server stop

Shutting down MySQL
.130421 09:27:02 mysqld_safe mysqld from pid file /usr/local/var/mysql/mycomputername.local.pid ended
 SUCCESS! 
[2]-  Done                    mysqld_safe --skip-grant-tables

kill the other shell window that has the dameon running (just to make sure)

now you are good to go! try it:

[root@servert1 ~]#  mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.10 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

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> 

done!

I hope this helps somebody. I was getting the same error, but seemingly for a much different reason than other people.

I have 2 CentOS machines.

I copied my.cnf to the new machine, not realizing that I had upgraded the old machine to MySQL 5.6, and the new machine had 5.5 installed. When I commented out the 5.6-only directives, MySQL started as expected. (and now I am running the upgrade so I can apply the massively useful innodb_buffer_pool_dump_at_shutdown and innodb_buffer_pool_load_at_startup directives)

I would suggest trying a bare minimum my.cnf. If MySQL starts up, then you've found the source of your problem.

It looks like you need a MySQL server installed, there is install packages on mysql's site, or you can install through macports (I assume from the darwin11 line). I installed mine via ports, and the socket lives in /opt/local/var/run/mysql5/.

In my case, I don't got tmp folder setting up right. What I end up with these steps:

1. cd /

2. ln -s private/tmp /tmp
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!