Mac 下安装 MySQL 经历
Posted 希希里之海
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mac 下安装 MySQL 经历相关的知识,希望对你有一定的参考价值。
1.使用 homebrew 安装:
brew install mysql
结果报错:
$ brew install mysql
==> Downloading http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19.tar.gz/from/http://cdn.mysql.com/
curl: (22) The requested URL returned error: 404 Not Found
Error: Download failed: http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19.tar.gz/from/http://cdn.mysql.com/
这时升级一下你的 homebrew:
brew update
安装完成后,然后又报错:
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/man/man8/mysqld.8
/usr/local/share/man/man8 is not writable.
真是坎坷。。。
解决方法:
#开启权限
$ sudo chown -R $(whoami) /usr/local/
#重新link一次
$ brew link mysql
这下总算安装完成了。
2.配置 mysql :
进入 sql 指令模式:
mysql -uroot -p
然后报错:
Error: Can\'t connect to local MySQL server through socket \'/tmp/mysql.sock\' (2)
表明我们没有启动 mysql 服务。
所以启动服务:
mysql.server start
3.设置 root 账户密码:
mysql_secure_installation
然后出现下列配置选项:
(1)
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:
Please set the password for root here.
New password:
Re-enter new password:
询问你是否安装 VALLDATE PASSWORD 这个套件(可以帮助你验证密码的复杂度,设置的太简单会提醒你),我并没有安装这个套件,直接 enter 后输入两次密码结束。
(2)
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 。
(3)
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) :
是否关闭 root 远端登入?选 y 。
(4)
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 。
(5)
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 。
4.再次尝试进入 sql 指令模式:
mysql -uroot -p
成功!
到这步我们便完成了 MySQL 的安装。
******
以Service方式启动/停止/重启MySQL命令:
service mysqld start
service mysqld stop
service mysqld restart
以上是关于Mac 下安装 MySQL 经历的主要内容,如果未能解决你的问题,请参考以下文章
mac下安装mysql,连接出现Access denied for user 'root'@'localhost' (using password: YES)(示例代码