mac使用homebrew安装mysql

本文介绍了如何在Mac上通过homebrew安装MySQL,包括启动服务、初次设置root用户密码以及如何修改MySQL密码的过程。首先,通过命令行安装homebrew,然后使用homebrew安装mysql。安装完成后,启动mysql服务,由于初始无密码,可以以root用户无密登录。最后,通过mysql_secure_installation命令设置和修改MySQL的root用户密码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

0.下载软件包管理工具homebrew

Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能
Homebrew网站链接
命令行输入homebrew安装命令

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

安装完成后,在命令行进行验证

$ brew --version
Homebrew 2.0.3
Homebrew/homebrew-core (git revision 4d5e6; last commit 2019-03-06)
Homebrew/homebrew-cask (git revision c2065; last commit 2019-03-07)

这就表示homebrew安装完毕

1.homebrew安装mysql

$ brew install mysql

等待下载安装结束就可以了,

2.启动mysql服务,并修改密码

待上述安装完成之后。命令行启动mysql服务,输入

$ mysql.server start
Starting MySQL
 SUCCESS!

刚刚安装完成的mysql是没有密码的,以用户名root即可进入数据库

$ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.15 Homebrew

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.02 sec)

3.修改mysql密码

使用mysql_secure_installation命令

/$ mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT 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 component?

Press y|Y for Yes, any other key for No:             <----回车
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) :            <----是否删除匿名用户

 ... skipping.


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) :             <----是否禁用远程登录

 ... 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) :             <----是否删除test数据库

 ... skipping.
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) :             <----是否重新加载权限表

 ... skipping.
All done!
/$

密码登录

$ mysql -u root -p
Enter password:

输入密码即可登录

  • 如有不妥,请指示正,谢谢阅读!
    作者:togetlife
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值