蘭陵N梓記

一指流沙,程序年华


  • 首页

  • 归档

  • 关于

  • 搜索
close

Install MySQL on MacOS

时间: 2017-06-03   |   分类: 笔记     |   阅读: 615 字 ~2分钟

最近在家想写的东西,在MacOS上需要使用到MySQL。在MacOS下,使用brew来安装软件是最便捷。关于brew是什么,可在brew官网查看:brew官网

安装:

➜  ~ brew info mysql
mysql: stable 5.7.18 (bottled)
Open source relational database management system
......
➜  ~ brew install mysql

mysql的安装过程会显示,注,我安装的5.7.18,目录为/usr/local/Cellar/mysql/5.7.18_1:

==> /usr/local/Cellar/mysql/5.7.18_1/bin/mysqld –initialize-insecure –user=xiao –basedir=/usr/local/Cellar/mysql/5.7.18_1 –datadir=/usr/local/var/mysql –t
..... 
We’ve installed your MySQL database without a root password. To secure it run: 
mysql_secure_installation

这说明MySQL已安装成功,必需要使用mysql_secure_installation来初始化用户密码:

➜  ~ mysql.server start
Starting MySQL
SUCCESS!
➜  ~ mysql_secure_installation
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

......

按英文提示一步步设置password validation policy与password等。

测试,输入mysql_secure_installation设置过程的密码:

➜  ~ mysql -u root –p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.18 Homebrew
......

新增用户xiao,密码为123456,并赋所有权限给他:

mysql>use mysql;
mysql>GRANT ALL PRIVILEGES ON *.* TO 'xiao'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql>flush privileges;

如果想设置开机启动MySQL,执行如下命令:

➜  ~ mkdir -p ~/Library/LaunchAgents
➜  ~ cp /usr/local/Cellar/mysql/5.7.18_1/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/  
➜  ~ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

使用命令行来操作MySQL不方便,推荐使用Navicat MySQL/Preminum软件。软件安装包在网上搜索吧。

参考:

[1] https://dev.mysql.com/doc/refman/5.7/en/mysql-secure-installation.html

#MySQL# #MacOS#
为什么我写不下去
PaaS的发展
微信扫一扫交流

标题:Install MySQL on MacOS
作者:兰陵子
关注:lanlingthink(览聆时刻)
声明:自由转载-非商用-非衍生-保持署名(创作共享3.0许可证)

兰陵子

兰陵子

Programmer & Architect

164 日志
4 分类
57 标签
GitHub 知乎
© 2009 - 2022 蘭陵N梓記
Powered by - Hugo v0.101.0
Theme by - NexT
0%