在mac下使用brew安装mysql,之前没有使用过,今天启动的时候发现启动不了

huijundeMacBook-Pro:bin huijunzhang$ mysql
ERROR (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

查看mysql的安装位置:

huijundeMacBook-Pro:bin huijunzhang$ which mysql
/usr/local/bin/mysql

说明mysql还是安装过的

huijundeMacBook-Pro:bin huijunzhang$ brew info mysql
mysql: stable 5.7. (bottled)
Open source relational database management system
https://dev.mysql.com/doc/refman/5.7/en/
Conflicts with: mariadb, mariadb-connector-c, mysql-cluster, mysql-connector-c, percona-server
/usr/local/Cellar/mysql/5.7. (, files, 445.0M) *
Poured from bottle on -- at ::
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb
==> Dependencies
Build: cmake ✘
Required: openssl ✔
==> Options
--with-archive-storage-engine
Compile with the ARCHIVE storage engine enabled
--with-blackhole-storage-engine
Compile with the BLACKHOLE storage engine enabled
--with-debug
Build with debug support
--with-embedded
Build the embedded server
--with-local-infile
Build with local infile loading support
--with-test
Build with unit tests
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation To connect run:
mysql -uroot To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start

有可能是mysql服务没有启动

huijundeMacBook-Pro:bin huijunzhang$ mysql.server start
Starting MySQL
. SUCCESS!

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

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

huijundeMacBook-Pro:bin huijunzhang$ mysql
ERROR (): Access denied for user 'huijunzhang'@'localhost' (using password: NO)

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

那就使用root用户启动:

huijundeMacBook-Pro:bin huijunzhang$ sudo mysql
Password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7. Homebrew Copyright (c) , , 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>
mysql> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.01 sec)

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

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

$ mysql.server start
$ mysql.server restart
$ mysql.server stop
$ mysql.server status
$ mysql -u root -p

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

  1. mac 安装mysql 报错“ERROR 2002 (HY000): Can not connect to local MySQL server through socket '/tmp/mysql.sock' (2)” 解决办法

    首先安装 homebrew 再 brew install mysql 之后连接 mysql 无论是登录还是修改初始密码都会报如下的错误 ERROR 2002 (HY000): Can not conn ...

  2. 长久不用的mysql报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

    mac上安装过mysql: 然而,尝试连接时报错: $ mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to lo ...

  3. mysql 报错ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ ( ...

  4. 启动mysql报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

    mysql之前还好好的,突然就启动不了了,我也很纳闷,原来是服务没有启动 netstat -ntlp 后,发现并没有启动 于是我试着启动mysql service mysqld start 查看了my ...

  5. 解决Mysql错误:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

    需要重启服务器:sudo /etc/init.d/mysql restart

  6. Mac mySql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)的解决办法

    我的环境:Mac 10.11.6 ,mysql  5.7.14  . mac mySql 报错ERROR 2002 (HY000): Can't connect to local MySQL serv ...

  7. ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了(转载)

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var mysql 启动不了   ps -A | gr ...

  8. 启动mysql错误ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ ( ...

  9. 安装mysql后ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了

    ps -A | grep -i mysql kill 列出来的进程 service mysql start 我的问题就解决了 ------------------------------------- ...

随机推荐

  1. poj2503--Babelfish(特里一水)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 32988   Accepted: 14189 Descr ...

  2. ff与ie 的关于js兼容性

    FF的FIREBUG,不仅能测试JS还能检查CSS错误,是一般常用的.但它主要检查FF方面的错误,对IE就无能为力了.要测试IE,就用ieTester,它可以测试IE几乎所有版本(1.0恐怕也用不到测 ...

  3. SQL Server 强行Insert包含自增列值的记录

    SET IDENTITY_INSERT 表 ON INSERT INTO 表 ([ID] ,[SequenceNumber] ,[EnumCode] ,[Description]) VALUES ( ...

  4. achartengine 实现平行线 动态数据 x轴动态移动

    achartengine做平行线的时候经常会遇到: java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1 at java.ut ...

  5. 在vs.net c#中添加mysql模型

    http://weblogs.asp.net/gunnarpeipman/getting-mysql-work-with-entity-framework-4-0 http://dev.mysql.c ...

  6. html 调用 activeX(c++)

    1.新建MFC ActiveX 2.添加方法 3.找到add函数编写代码 4.在test.idl中找到最后一个uuid 5.编译工程,会自动注册控件 6.html中的代码 <html> & ...

  7. mysql插入返回当前生成的主键

     1:sql中需要添加属性 keyColumn="base_price_id" keyProperty="basePriceId" useGeneratedKe ...

  8. Mysql 记录

    1.创建用户命令: <!---->mysql> CREATE USER yy IDENTIFIED BY '123'; yy表示你要建立的用户名,后面的123表示密码 上面建立的用户 ...

  9. Android Bitmap圆角

    代码如下: public Bitmap transform(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeig ...

  10. Scrapy:python3下的第一次运行测试

    1,引言 <Scrapy的架构初探>一文讲解了Scrapy的架构,本文就实际来安装运行一下Scrapy爬虫.本文以官网的tutorial作为例子,完整的代码可以在github上下载. 2, ...