Mac M1 安装 MySQL

本文详细记录了在Mac上通过Homebrew安装MySQL5.7的过程,包括安装、配置环境变量、查看版本、启动与停止MySQL服务,以及初始化设置,如设置root密码、移除匿名用户、禁止root远程登录和删除test数据库等步骤。

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

安装

% brew install mysql@5.7
Warning: mysql@5.7 5.7.34 is already installed and up-to-date.
To reinstall 5.7.34, run:
  brew reinstall mysql@5.7

mysql5.7的版本就可以安装成功。

配置环境变量

# 终端
echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
 
# 刷新 ~/.zshrc
source ~/.zshrc

查看版本

nichengjing@nichengjingdeMacBook-Air ~ % mysql --version
mysql  Ver 14.14 Distrib 5.7.34, for osx10.16 (x86_64) using  EditLine wrapper

启动

mysql.server start  # 启动mysql

mysql.server stop # 停止mysql

mysql.server restart # 重启mysql

初始化

任意路径执行命令:mysql_secure_installation,交互过程中不断输入y或者n,可以修改密码。

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: n    // 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的

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      //不接受root远程登录账号

 

... 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) : y     //删除text数据库

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

安装完成

### 如何在 Mac M1安装 TexStudio #### 1. 安装 LaTeX 编译环境 (MacTeX) 为了使 TeXstudio 正常工作,首先需要安装一个完整的 LaTeX 发行版作为其编译环境。推荐使用 MacTeX。 访问官方网站 [https://tug.org/mactex/](https://tug.org/mactex/) 并下载 `MacTeX.pkg` 文件[^1]。该文件体积较大(约 6GB),因此建议在 Wi-Fi 环境下完成下载。双击 `.pkg` 文件并按照提示逐步完成安装过程。 验证安装成功与否可以通过打开终端并输入以下命令: ```bash which pdflatex ``` 如果返回路径 `/usr/local/texlive/YYYY/bin/universal-darwin/pdflatex` 或类似的路径,则说明安装成功[^1]。 --- #### 2. 下载与安装 TeXstudio 接下来,从官方渠道获取 TeXstudio 的最新版本: - **方法一:直接从官网下载** 访问 TeXstudio 官方网站 [http://texstudio.sourceforge.net/](http://texstudio.sourceforge.net/),找到适用于 macOS 的安装包并下载。对于 Mac M1 用户,确保选择支持 Apple Silicon 架构的版本[^3]。 - **方法二:通过 Homebrew Cask 安装** 如果熟悉 Homebrew 工具链,可以执行以下命令快速安装: ```bash brew install --cask texstudio ``` 需要注意的是,Homebrew Cask 方式可能会导致应用程序名称过长(如 `texstudio-4.8.5-osx-m1`),影响用户体验[^2]。在这种情况下,可以选择手动更名或继续使用方法一中的官方安装包。 --- #### 3. Java 运行时环境配置(可选) 某些高级功能可能依赖于外部工具,例如 LanguageTool 文本校正插件。这些工具通常需要 Java 支持。如果尚未安装 JDK,请访问 Oracle 官网 [https://www.oracle.com/java/technologies/downloads/#java8-mac](https://www.oracle.com/java/technologies/downloads/#java8-mac) 下载适合的操作系统版本[^5]。 安装完成后还需确认环境变量已正确设置。具体操作如下: - 打开终端; - 输入 `echo $JAVA_HOME` 检查是否指向有效的 JDK 路径; - 若未定义 `$JAVA_HOME`,可通过编辑 shell 配置文件(如 `.zshrc` 或 `.bash_profile`)添加相应条目: ```bash export JAVA_HOME=$(/usr/libexec/java_home) ``` 重启终端以生效更改。 --- #### 4. 测试安装 最后,启动 TeXstudio 应用程序,并尝试创建一个新的文档进行测试。例如编写一段简单的 LaTeX 代码: ```latex \documentclass{article} \begin{document} Hello, world! \end{document} ``` 点击菜单栏上的绿色箭头按钮运行编译。如果一切正常,应能生成 PDF 输出文件[^1]。 --- #### 注意事项 - 对于跨平台使用的场景,TeXstudio 是理想的选择之一,因为它能够在 Windows 和 macOS 系统间保持一致性的用户体验。 - 如果遇到权限问题无法保存或覆盖现有文件的情况,需右键目标目录选择「Get Info」选项卡调整读写属性[^3]。 ---
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值