Mac利用brew安装mysql并设置初始密码

前言

之前一直是在windows上开发后段程序,所以只在windows上装mysql。(我记得linux只需要适应yum之类的命令即可)

另外, linux的移步 linux安装mysql (详细步骤,初次初始化,sql小例子,可视化操作客户端推荐)

好家伙,我佛了,写完当天网上发现自己之前写过一篇 brew 安装mysql (Mac OS), 不过那篇没有说如何设置初始密码.

安装mysql

bash 复制代码
brew install mysql

等它装完就好啦

开启mysql

bash 复制代码
mysql.server start

顺带一提,关闭命令是

bash 复制代码
mysql.server stop

设置初始密码

bash 复制代码
mysql_secure_installation

输入上面这个命令,就会提示你一系列操作,就可以设置我们的初始密码了

复制代码
andydennis@192 ~ % mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
Error: Access denied for user 'root'@'localhost' (using password: YES)
andydennis@192 ~ % mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 

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: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Using existing password for root.

Estimated strength of the password: 25 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: 

Re-enter new password: 

Estimated strength of the password: 25 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
 ... Failed! Error: Your password does not satisfy the current policy requirements

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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) : 

 ... 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! 

这里密码需要大于等于8个,所以我设置了 root1234

然后就可以用我们熟悉的命令登录上mysql了

bash 复制代码
mysql -u root -p

输入密码 root1234

查看 有无启动

bash 复制代码
ps aux|grep mysqld

或者

bash 复制代码
ps -ef|grep mysqld

或者换一种思路,看3306端口号是否被占用

bash 复制代码
lsof -i :3306
相关推荐
xhbh6669 小时前
MySQL数据导出避坑指南:如何选择正确的工具并设计安全的备份策略?
数据库·mysql·oracle·程序员·mysql导出数据库
FOLLOW ME31110 小时前
MySQL集群高可用架构
数据库·mysql·架构
·云扬·10 小时前
MySQL 日志全解析:Binlog/Redo/Undo 等 5 类关键日志的配置、作用与最佳实践
android·mysql·adb
Magnetic_h11 小时前
【iOS】block复习
笔记·macos·ios·objective-c·cocoa
程序新视界11 小时前
一篇文章全面重温MySQL的join操作
mysql
BYSJMG11 小时前
计算机毕设选题:基于Python+MySQL校园美食推荐系统【源码+文档+调试】
大数据·开发语言·python·mysql·django·课程设计·美食
宁小法12 小时前
MySQL - 全表扫描 会发生死锁?
数据库·mysql·死锁·存储引擎·全表扫描
叫我龙翔12 小时前
【MySQL】从零开始了解数据库开发 --- 数据类型
数据库·mysql·数据库开发
栒U20 小时前
一文从零部署vLLM+qwen0.5b(mac本地版,不可以实操GPU单元)
人工智能·macos·vllm
福赖20 小时前
《MySQL基础——用户管理》
mysql·用户管理