当前位置:首页 > 操作系统 > MacOs

Mac下Mysql启动异常["ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"]

2002 (HY000): Cant connect to local MySQL server through socket /tmp/mysql.sock (2)

查看mysql的安装位置:

huijundeMacBook-<span style="color: #000000;">Pro:bin huijunzhang$ which mysql
</span>/usr/local/bin/mysql

说明mysql还是安装过的

huijundeMacBook-<span style="color: #000000;">Pro:bin huijunzhang$ brew info mysql
mysql: stable </span><span style="color: #800080;">5.7</span>.<span style="color: #800080;">13</span><span style="color: #000000;"> (bottled)
Open source relational database management system
https:</span><span style="color: #008000;">//</span><span style="color: #008000;">dev.mysql.com/doc/refman/5.7/en/</span>
Conflicts with: mariadb, mariadb-connector-c, mysql-cluster, mysql-connector-c, percona-<span style="color: #000000;">server
</span>/usr/local/Cellar/mysql/<span style="color: #800080;">5.7</span>.<span style="color: #800080;">13</span> (<span style="color: #800080;">13</span>,<span style="color: #800080;">344</span> files, <span style="color: #800080;">445.0M</span>) *<span style="color: #000000;">
  Poured </span><span style="color: #0000ff;">from</span> bottle on <span style="color: #800080;">2016</span>-<span style="color: #800080;">06</span>-<span style="color: #800080;">30</span> at <span style="color: #800080;">15</span>:<span style="color: #800080;">05</span>:<span style="color: #800080;">40</span><span style="color: #000000;">
From: https:</span><span style="color: #008000;">//</span><span style="color: #008000;">github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb</span>
==><span style="color: #000000;"> Dependencies
Build: cmake ?
Required: openssl ?
</span>==><span style="color: #000000;"> Options
</span>--with-archive-storage-<span style="color: #000000;">engine
    Compile with the ARCHIVE storage engine enabled
</span>--with-blackhole-storage-<span style="color: #000000;">engine
    Compile with the BLACKHOLE storage engine enabled
</span>--with-<span style="color: #000000;">debug
    Build with debug support
</span>--with-<span style="color: #000000;">embedded
    Build the embedded server
</span>--with-local-<span style="color: #000000;">infile
    Build with local infile loading support
</span>--with-<span style="color: #000000;">test
    Build with unit tests
</span>==><span style="color: #000000;"> Caveats
We</span><span style="color: #800000;">‘</span><span style="color: #800000;">ve installed your MySQL database without a root password. To secure it run:</span>
<span style="color: #000000;">    mysql_secure_installation

To connect run:
    mysql </span>-<span style="color: #000000;">uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, </span><span style="color: #0000ff;">if</span> you don<span style="color: #800000;">‘</span><span style="color: #800000;">t want/need a background service you can just run:</span>
  mysql.server start

有可能是mysql服务没有启动

huijundeMacBook-<span style="color: #000000;">Pro:bin huijunzhang$ mysql.server start
Starting MySQL
. SUCCESS</span>! 

哈哈,mysql服务启动了,好开心呀!

接下来要试试能否进入mysql了

huijundeMacBook-<span style="color: #000000;">Pro:bin huijunzhang$ mysql
ERROR </span><span style="color: #800080;">1045</span> (<span style="color: #800080;">28000</span>): Access denied <span style="color: #0000ff;">for</span> user <span style="color: #800000;">‘</span><span style="color: #800000;">huijunzhang</span><span style="color: #800000;">‘</span>@<span style="color: #800000;">‘</span><span style="color: #800000;">localhost</span><span style="color: #800000;">‘</span> (<span style="color: #0000ff;">using</span> password: NO)

这个提示应该很明显了吧,权限问题,mysql下没有huijunzhang这个用户,装过mysql的朋友应该知道,安装mysql默认的用户名是root,端口是3306,别问我为什么知道。。。

那就使用root用户启动:

huijundeMacBook-<span style="color: #000000;">Pro:bin huijunzhang$ sudo mysql
Password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id </span><span style="color: #0000ff;">is</span> <span style="color: #800080;">4</span><span style="color: #000000;">
Server version: </span><span style="color: #800080;">5.7</span>.<span style="color: #800080;">13</span><span style="color: #000000;"> Homebrew

Copyright (c) </span><span style="color: #800080;">2000</span>, <span style="color: #800080;">2016</span>, Oracle and/<span style="color: #000000;">or its affiliates. All rights reserved.

Oracle </span><span style="color: #0000ff;">is</span> a registered trademark of Oracle Corporation and/<span style="color: #000000;">or its
affiliates. Other names may be trademarks of their respective
owners.

Type </span><span style="color: #800000;">‘</span><span style="color: #800000;">help;</span><span style="color: #800000;">‘</span> or <span style="color: #800000;">‘</span><span style="color: #800000;">h</span><span style="color: #800000;">‘</span> <span style="color: #0000ff;">for</span> help. Type <span style="color: #800000;">‘</span><span style="color: #800000;">c</span><span style="color: #800000;">‘</span><span style="color: #000000;"> to clear the current input statement.

mysql</span>><span style="color: #000000;">
mysql</span>><span style="color: #000000;"> show databases
    </span>-><span style="color: #000000;"> ;
</span>+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
<span style="color: #800080;">4</span> rows <span style="color: #0000ff;">in</span> <span style="color: #0000ff;">set</span> (<span style="color: #800080;">0.01</span> sec)

哈哈,问题解决了,好开心呀!

总结:出现“ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)”的根本原因就是mysql服务没有启动,下面总结下mysql在mac下的几个常用的命令吧!

<span style="color: #000000;">$ mysql.server start
$ mysql.server restart
$ mysql.server stop
$ mysql.server status<br />$ </span><span class="s1">mysql -u root -p</span>


 

Mac下Mysql启动异常["ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"]

标签:

本文系统来源:http://www.cnblogs.com/zhjsll/p/5702950.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐