Mac如何安装mysql和完全卸载mysql

brew安装mysql

Mac的环境都推荐使用Homebrew来安装,方便管理和使用,如果没有安装Homebrew可以使用HomebrewCN来安装Homebrew,或者使用下面的命令安装Homebrew

复制代码
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

在终端使用命令后,按照步骤安装Homebrew即可

搜索可安装的mysql版本

使用brew search即可在Homebrew仓库中搜索软件

复制代码
brew search mysql

搜索mysql的版本:5.7、8.0、8.4和最新版,这里以安装mysql8。4为例,输入以下命令安装mysql8.4

复制代码
brew install mysql@8.4

这样就安装完成了,比使用mysql的安装器要快很多,安装完成后使用命令启动mysql

复制代码
brew services start mysql@8.4

这样就启动完成,默认情况下mysql是没有密码的可以使用如下命令来进入mysql的命令行

复制代码
mysql -u root

我们可以使用mysql的初始化工具来初始化一下mysql

复制代码
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:

    这里就是问你要不要使用它的工具来检测密码的强度,比如123456这种弱密码,这里如果你需要你就输入Y如果不需要回车就可以了,一般开发环境的密码简单就行了,不是生产环境不需要那么复杂

  2. Please set the password for root here.

    New password:

    Re-enter new password:

    这里呢就是让你输入root的密码,输入密码是不会显示的,你输入就行了,要输入俩次,俩次密码必须一致,如果第一次密码不确认是什么,第二次直接回车就能重写输入第一次

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

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

  5. 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数据库,这是一个测试数据库,任何人都有权限访问它,一般无脑回车就可以了,不需要弄的那么麻烦,如果你需要输入Y

  6. 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 -u root -p

输入密码后回车,密码不会显示,错了就回车重来

这样数据库就安装完了,如果想要体制数据库,让它不在后台运行,只需要执行下面的命令就可以了

复制代码
brew services stop mysql@8.4

使用过mysql安装器导致安装有问题的解决办法

这里我不推荐使用mysql的安装器,我推荐使用Homebrew,方便还快,国内用户使用大学镜像就不用使用魔法来上网,但是使用过mysql的安装器后会如果安装失败,或者像切换版本,就会发现原来的mysql用不了,新安装的mysql也用不了,在安装器卸载mysql结果发现这个安装器死死的还在设置的最底部躺着,根本删不掉,这就是数据库软件的通病安装不行,卸载不了,根本卸载不干净,不管是*nix系统还是Windows系统都是这样,这里我们讲怎么把Mac的这玩意卸载干净

先关闭mysql

查看mysql是否启动:ps -ef |grep mysql

我没有使用mysql安装器来,使用是Homobrew安装mysql,使用我偷了csdn的图片,不过我帮别人装环境测试是差不多的

输入:kill -9 然后回车,关闭mysql。如果报错或者执行失败没关系,不需要管

删除卸载残留

这里呢,可以先使用mysql的安装器来卸载mysql然后在使用如下命令来删除残留

sudo rm /usr/Local/mysql

sudo rm -rf /usr/local/mysql*

sudo rm -rf /Library/StartupItems/MySQLCOM

sudo rm -rf /Library/PreferencePanes/My*

rm -rf ~/Library/PreferencePanes/My*

sudo rm -rf /Library/Receipts/mysql*

sudo rm -rf /Library/Receipts/MySQL*

sudo rm -rf /var/db/receipts/com.mysqL.*

sudo rm -rf /opt/homebrew/var/mysql

sduo rm -rf /usr/local/var/mysql

sudo rm -rf /usr/local/mysql

sudo rm -rf /opt/homebrew/etc/my.cnf

sudo rm -rf ~/Library/Preferences/com.mysql.*

这些命令一行一行执行,如果提示:No such file or directory,不需要管,证明这个残留物不存在,执行完毕以后重启就可以了,这样mysql就卸载完了.可以重新安装其他版本

现在可以去系统设置滑倒最下面查看是否还存在mysql图标.然后使用最上面的Homebrew安装mysql的教程来安装mysql即可

本文标题: Mac如何安装mysql和完全卸载mysql

本文转载罗拉呦: https://www.luola.me/116.html

相关推荐
stayhungry_c6 小时前
Quarto生成PDF无法正常显示中文的问题
python·macos·r语言·pdf
2501_915918416 小时前
uni-app 上架 iOS 应用全流程 从云打包到开心上架(Appuploader)免 Mac 上传发布指南
android·macos·ios·小程序·uni-app·iphone·webview
木易 士心8 小时前
在 Mac 上配置 ADB 环境变量:解决 “command not found: adb” 问题
macos·adb
2501_915918418 小时前
iOS 26 应用管理实战 多工具协同构建开发与调试的高效体系
macos·ios·小程序·uni-app·objective-c·cocoa·iphone
ttghgfhhjxkl8 小时前
《macOS 配置 GO 语言后,如何切换不同 GO 版本?》
开发语言·macos·golang
rchmin10 小时前
Mac安装VisualVM 2.2启动闪退
macos
行思理1 天前
Dockerfile 各指令说明
运维·macos·docker·容器·php
鸠摩智首席音效师1 天前
如何在 macOS 中清理 Homebrew 软件包 ?
macos
skywalk81631 天前
windows装wsl ubuntu24.04 ,里面装qemu ,然后装mac os (windows也可以直接qemu安装macos)(未实践)
windows·ubuntu·macos·qemu