资讯专栏INFORMATION COLUMN

在 Mac 下用 Homebrew 安装 MySQL各种解决思路

ninefive / 2695人阅读

摘要:经常不断的遇到在上使用这个包管理神器安装出问题,今天在百度谷歌上搜索资料解决方案今天总算解决掉了,把这个解决方案分享出来我的系统是准备安装的是开始之前,假设你的已经安装好并可以使用。

经常不断的遇到在mac上使用brew这个包管理神器安装mysql出问题,今天在百度谷歌上搜索资料解决方案今天总算解决掉了,把这个解决方案分享出来

我的系统是 Mac OS X 10.12,准备安装的是 mysql 5.7.9
开始之前,假设你的brew已经安装好并可以使用。

安装mysql,在终端输入如下命令并回车:

brew install mysql

等待大概5分钟(视网速而定)执行完毕后,会看到这一段提示:

/usr/local/Cellar/mysql/5.7.9/bin/mysqld --initialize-insecure --user=comet
==> Caveats
We"ve installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

可以看到brew在安装的时候已经初始过mysql了(不用再像网上说的再执行mysql_install_db命令),且当前没有密码于是我按照它的提示,执行命令:

mysql_secure_installation

需要密码时,直接回车,出现了如下的错误:

Securing the MySQL server deployment.

Enter password for user root:
Error: Access denied for user "root"@"localhost" (using password: NO)

启动mysql服务的时候报错

mysql.server start
Starting MySQL
... ERROR! The server quit without updating PID file (/usr/local/var/mysql/zhangzhingdeMBP.AirDream.pid).

在谷歌查询了关于这个报错PID文件的问题解决方案,执行下面的命令,(关于这个报错可以参考我的另外一篇文章 )

sudo rm -rf /usr/local/var/mysql/dev.work.err (dev.work is my hostname)

然后再启动mysql服务命令

mysql.server start

提示 .SUCCESS!这时tmp目录下有mysql.sock这个文件了,于是我继续执行 mysql_secure_installation

cometdeMacBook-Pro:~ comet$ mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank 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   // 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的
Please set the password for root here.

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) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

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!

OK!搞定,可以使用mysql -u root -p 进行密码连接了

PS:以后再也不担心此类问题报错了,妈妈再也不担心我mysql安装报错了

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/21337.html

相关文章

  • Mac下Nginx、PHP、MySQL 和 PHP-fpm安装配置

    摘要:安装之前,需要确定是否安装过然后安装命令行工具。安装命令行工具如果该方法你不愿用或者各种原因,可以登录然后下载安装注一定要选择和系统版本,版本一致的命令行工具。安装好了之后,便可以使用命令来安装相应的包了。 之前换电脑装了个Mnmp,有遇到一些小坑,写在这,希望能帮到一些初次搭建Mnmp的phper。 ... 安装 Mac 的包管理器 - homebrew Homebrew是一款Mac...

    fireflow 评论0 收藏0
  • Mac下Nginx、PHP、MySQL 和 PHP-fpm安装配置

    摘要:安装之前,需要确定是否安装过然后安装命令行工具。安装命令行工具如果该方法你不愿用或者各种原因,可以登录然后下载安装注一定要选择和系统版本,版本一致的命令行工具。安装好了之后,便可以使用命令来安装相应的包了。 之前换电脑装了个Mnmp,有遇到一些小坑,写在这,希望能帮到一些初次搭建Mnmp的phper。 ... 安装 Mac 的包管理器 - homebrew Homebrew是一款Mac...

    animabear 评论0 收藏0
  • Mac下怎么搭建MySQL环境?简单教程手把手教你!

    摘要:但新版本不能这样改了,因为密码认证变了。方法二用进行安装总所周知,可以利用进行安装管理,十分方便,如果没有安装可以点击安装。如果觉得这篇文章不错的话,也可以分享给更多的人看到,感谢各位的阅读在下搭建环境搭建环境 这篇文章主要跟大家介绍的是在Mac下怎么搭建MySQL环境,相信很多小伙伴都不知道,对此,摩杜云小杜就整理了一下文字并分享给大家做个参考,由于内容思路清...

    番茄西红柿 评论0 收藏2637

发表评论

0条评论

最新活动
阅读需要支付1元查看
<