Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS安装/卸载MySQL 8.0.16 #121

Open
Qingquan-Li opened this issue May 23, 2019 · 0 comments
Open

macOS安装/卸载MySQL 8.0.16 #121

Qingquan-Li opened this issue May 23, 2019 · 0 comments
Labels

Comments

@Qingquan-Li
Copy link
Owner

Qingquan-Li commented May 23, 2019

环境:

  • mysql Ver 8.0.16 for macos10.14 on x86_64 (MySQL Community Server - GPL)

  • macOS 10.12.6


一、下载安装 MySQL 8.0.16

参考:

下载 .dmg 安装包,进行包安装,安装过程中全部选择默认即可。

注意:
MySQL 8.0 默认的密码机制是 caching_sha2_password (Strong),这一步不建议选择默认,建议选回 mysql_native_password (Legacy)。

附:
也可以使用包管理器 Homebrew 安装 MySQL (不建议):

$ brew install mysql

二、启动 MySQL 8.0.16

$ cd /usr/local/mysql
$ sudo ./bin/mysqld_safe

把 mysql 的安装路径加入到 shell 中

为了在终端(这里是 iTerm2 )使用 mysql 命令,而不用每次都 cd 进入 mysql 的安装路径,建议把 mysql 的安装路径加入到 shell 中(注意:这里的 shell 是 oh-my-zsh 而不是默认的 bash ):

前往文件夹: ~/.zshrc 添加 MySQL 路径(或 vim ~/.zshrc ):

export PATH="/usr/local/mysql/bin:$PATH"

执行以下命令测试是否添加路径成功

$ echo $PATH

查看 mysql 版本:

$ mysql -V

附:使用 alias 添加别名指向相应的 mysql 路径

除了“把 mysql 的安装路径加入到 shell 中”,还可以使用 alias 的方式,添加别名指向相应的 mysql 路径(不建议)。

在 shell 的资源文件中添加别名,以便更容易从命令行访问常用程序,如 mysql 和 mysqladmin ( bash 或 zsh ):

$ alias mysql=/usr/local/mysql/bin/mysql
$ alias mysqladmin=/usr/local/mysql/bin/mysqladmin

三、连接 MySQL 8.0.16

参考:https://dev.mysql.com/doc/refman/8.0/en/connecting-disconnecting.html

语法:
$ mysql -h host -u user -p
在运行着 mysql 的用户名为 root 的本机电脑上连接 mysql:
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.16 MySQL Community Server - GPL

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>

四、卸载 MySQL 8.0.16

参考:

打开「系统偏好设置」=> 停止 MySQL 服务 => 卸载 MySQL => 再逐条执行以下命令(因为上一步卸载 MySQL 时已经自动删除了一些文件,所以执行下面命令时可能会提示找不到文件)。

To uninstall MySQL and completely remove it (including all databases) from your Mac do the following:

  • Open a terminal window
  • Use mysqldump to backup your databases to text files!
  • Stop the database server
  • sudo rm /usr/local/mysql
  • sudo rm -rf /usr/local/mysql*
  • sudo rm -rf /Library/StartupItems/MySQLCOM
  • sudo rm -rf /Library/PreferencePanes/My*
  • edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
  • rm -rf ~/Library/PreferencePanes/My*
  • sudo rm -rf /Library/Receipts/mysql*
  • sudo rm -rf /Library/Receipts/MySQL*
  • sudo rm -rf /private/var/db/receipts/*mysql*
@Qingquan-Li Qingquan-Li changed the title macOS安装MySQL macOS安装MySQL 8.0.16 Dec 3, 2019
@Qingquan-Li Qingquan-Li changed the title macOS安装MySQL 8.0.16 macOS安装/卸载MySQL 8.0.16 Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant