{"action":"opened","issue":{"url":"https://api.github.com/repos/issaxite/issaxite.github.io/issues/168","repository_url":"https://api.github.com/repos/issaxite/issaxite.github.io","labels_url":"https://api.github.com/repos/issaxite/issaxite.github.io/issues/168/labels{/name}","comments_url":"https://api.github.com/repos/issaxite/issaxite.github.io/issues/168/comments","events_url":"https://api.github.com/repos/issaxite/issaxite.github.io/issues/168/events","html_url":"https://github.com/issaxite/issaxite.github.io/issues/168","id":318740964,"number":168,"title":"mac 单独安装mysql遇坑","user":{"login":"issaxite","id":25907273,"avatar_url":"https://avatars3.githubusercontent.com/u/25907273?v=4","gravatar_id":"","url":"https://api.github.com/users/issaxite","html_url":"https://github.com/issaxite","followers_url":"https://api.github.com/users/issaxite/followers","following_url":"https://api.github.com/users/issaxite/following{/other_user}","gists_url":"https://api.github.com/users/issaxite/gists{/gist_id}","starred_url":"https://api.github.com/users/issaxite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/issaxite/subscriptions","organizations_url":"https://api.github.com/users/issaxite/orgs","repos_url":"https://api.github.com/users/issaxite/repos","events_url":"https://api.github.com/users/issaxite/events{/privacy}","received_events_url":"https://api.github.com/users/issaxite/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-29T19:04:53Z","updated_at":"2018-04-29T19:04:53Z","closed_at":null,"author_association":"OWNER","body":"首先，正常流程安装官网最新版本\r\n![image](https://user-images.githubusercontent.com/25907273/39409696-5201797a-4c1e-11e8-88c2-505a4ffedad4.png)\r\n下载完成安装完成，打开编好设置，最下面一栏也出现mysql图标，打开，start mysql，输完密码！以为可以啦！那就正常操作，命令行执行：\r\n```\r\nmysql -uroot -p\r\n```\r\n然而，抛出如下异常：\r\n```\r\nERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'\r\n```\r\nwhat？\r\ncd 到 `/tmp`下，并无发现`mysql.sock`！what？\r\ngoogle一下，部分人说，可能在`/var/lib/mysql`下，cd过去，然而并没有~\r\nok！我不死心，我命令`find`一下\r\n```\r\nsudo find / -name 'mysql.sock'\r\n```\r\n然而并没有~\r\n继续google一下，发现，wtm没有启动mysql，what？我一开始不就在客户端上开启了吗？\r\n我继续打开偏好设置，继续启动一下，当我再次启动后，按钮还是`start mysql`这是我意识到，我没有成功开启~\r\n\r\n继续google一下如何开启mysql~\r\n\r\n知道一个答案如下\r\n```\r\nmysql.server start\r\n```\r\n然后抛出没有这命令`mysql.server`，what？\r\n\r\nok！我猜或许没有这个环境变量，然后我在mysql目录下找这个命令~\r\n\r\n然后，我在`/usr/local/mysql/support-files`下找到了这个命令，保守起见我如此启动：\r\n```\r\nsudo ./mysql.server start\r\n```\r\n然而还是不行（忘记抛出什么异常了~）\r\n\r\n怎么办~\r\n\r\n我选择删除重新装~\r\n删除工作如下：\r\n```\r\nsudo rm /usr/local/mysql\r\nsudo rm -rf /usr/local/mysql*\r\nsudo rm -rf /Library/StartupItems/MySQLCOM\r\nsudo rm -rf /Library/PreferencePanes/My*\r\nsudo rm -rf /Library/Receipts/mysql*\r\nsudo rm -rf /Library/Receipts/MySQL*\r\nsudo rm -rf /var/db/receipts/com.mysql.*\r\n```\r\n然后，重新启动电脑（记得是重启，不是注销，不要问我为什么知道）\r\n再装一次，然而还是启动不了~\r\n\r\n然后我继续删除重新装了另外一个版本：5.7.22\r\n\r\n然而还是不行~\r\n\r\n别人启动成功是这样的：\r\n![image](https://user-images.githubusercontent.com/25907273/39409835-676e8878-4c20-11e8-8e00-0bfb109a830c.png)\r\n然而我还是一直是stopped……\r\n\r\n再google一下，有人说在`/usr/local/etc/`下添加或修改`my.cnf`，文件内容如下：\r\n```\r\n[client]\r\nport = 3306\r\nsocket = /tmp/mysql.sock\r\ndefault-character-set = utf8\r\n\r\n[mysqld]\r\ncollation-server = utf8_unicode_ci\r\ncharacter-set-server = utf8\r\ninit-connect ='SET NAMES utf8'\r\nmax_allowed_packet = 64M\r\nbind-address = 127.0.0.1\r\nport = 3306\r\nsocket = /tmp/mysql.sock\r\ninnodb_file_per_table=1\r\n\r\n[mysqld_safe]\r\ntimezone = '+0:00'\r\n```\r\nanyway，还是不行~\r\n\r\n我还在怎么办？继续google，有人说这是mos版mysql的bug，主要是5.5以上版本的bug~\r\n\r\n然后，我继续卸载了以上版本，去官网找了[历史版本](https://downloads.mysql.com/archives/community/)：5.1.72\r\n\r\n当然，删除完要记得重启！然后开始客户端引导安装，安装完成后，偏厚设置最下面一栏没有了mysql的图标！难道没有安装成功？不会啊，客户端提示成功了！cd 到`/usr/local/`我发现了mysql目录，我确信是成功了，ok！那么接下来命令行启动吧！\r\n```\r\nsudo ./mysql.server start\r\n```\r\n输出如下：\r\n![image](https://user-images.githubusercontent.com/25907273/39409930-98454ec2-4c21-11e8-9bc6-578bd6ab42fa.png)\r\n成功了~我就是这么平静，没有一丝成功的喜悦~\r\n\r\nok！启动成功那么就连接mysql吧！\r\n\r\n```\r\nmysql -uroot -p\r\n```\r\n提示叫我输密码！what？我没有设置密码啊~难道有默认密码？\r\n\r\n继续google一下[捂脸]，首次连接，不需要密码，直接enter就好~[手动滑稽]\r\n\r\nok！连接成功了，那么开始改密码吧！\r\n\r\n如是操作：\r\n```\r\n\\> FLUSH PRIVILEGES;\r\n\\> SET PASSWORD FOR 'root'@'localhost' = 'xxxxxxxx'\r\n```\r\n\r\n抛出如下异常：\r\n```\r\nPassword hash should be a 41-digit hexadecimal number\r\n```\r\n不能明文设置密码~\r\n\r\n怎么办？继续google一下\r\n\r\n要如是操作：\r\n```\r\n\\> select password('xxxxxxxx')\r\n```\r\n![image](https://user-images.githubusercontent.com/25907273/39409980-9d7ab818-4c22-11e8-8033-5074f842d74b.png)\r\n继续设置：\r\n```\r\nSET PASSWORD FOR 'root'@'localhost' = '*C47C6EF6F324BF0926781358C11C26EB77036DC8';\r\n```\r\n\r\n成功了~ 我还是那么平静~\r\n\r\n设置环境变量的方法：\r\n```\r\n\\> vim ~/.bash_profile\r\n```\r\n在文件内添加：\r\n```\r\nexport PATH=${PATH}:/usr/local/mysql/bin\r\n```\r\n保存然后执行：\r\n```\r\n\\> source ~/.bash_profile\r\n```\r\n如法炮制，添加了mysql和mysql.server的环境变量"}}
{"actor":{"display_login":"issaxite"}}