MAC安装MYSQL

安装 Homebrew 安装工具

官网 https://brew.sh/index_zh-cn 

输入下面命令去终端,然后按任意键继续

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

开始用命令安装MYSQL 示例如下

安装mysql:brew install mysql

如果初始化出错,可能需要加软连接 修改安装目录下的my.cnf文件 加入下面配置,mysql.sock存放路径不一样,可以find 先查找

socket  = /private/tmp/mysql.sock
feideMacBook-Air:~ fei$ brew install mysql@5.7
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/mysql@5.7-5.7.23.high_sierra.
Already downloaded: /Users/fei/Library/Caches/Homebrew/mysql@5.7-5.7.23.high_sierra.bottle.tar.gz
==> Pouring mysql@5.7-5.7.23.high_sierra.bottle.tar.gz
==> /usr/local/Cellar/mysql@5.7/5.7.23/bin/mysqld --initialize-insecure --user=fei
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/mysql@5.7/lib
    CPPFLAGS: -I/usr/local/opt/mysql@5.7/include


To have launchd start mysql@5.7 now and restart at login:
  brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql@5.7/bin/mysql.server start
==> Summary
?  /usr/local/Cellar/mysql@5.7/5.7.23: 317 files, 234.4MB

基本都是brew工具提示操作 

对mysql进行初始化操作:mysql_secure_installation

初始化之前必须启动服务 命令如下 

mysql.server start
或者是
启动mysql:brew services start mysql@5.7
停止mysql:brew services stop mysql@5.7
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?
 // 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的
Press y|Y for Yes, any other key for No: N   
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.
 
 // 是否删除test库
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!

到这里安装完成,下面尝试登录

登陆mysql:mysql -u root -p
启动mysql:brew services start mysql@5.7
停止mysql:brew services stop mysql@5.7

 

如果之前没有安装过MySQL 5.7 (后面注释去掉)  后面环境变量的文件,根据输出的变量文件替换

brew install mysql@5.7  // 安装
brew link --force mysql@5.7 // 链接
brew services start mysql@5.7 // 启动服务
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc // 输出到环境变量

安装过就卸载 重装

brew uninstall mysql@5.7
rm -rf /usr/local/var/mysql
rm /usr/local/etc/my.cnf

❗️重要的一步,设置安全的访问 (与安装时设置密码一样)

初始化密码插件
mysql_secure_installation

-- 如果不想使用复杂的密码,可以不安装或者卸载掉密码安全插件(比如开发环境)
-- 登录root用户
mysql -uroot -p

mysql> UNINSTALL PLUGIN validate_password; (卸载密码安全插件)
Query OK, 0 rows affected (0.00 sec)

-- 再按照上面的操作,使用mysql_secure_installation修改root密码即可

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值