Qingquan-Li / blog

My Blog
https://Qingquan-Li.github.io/blog/
132 stars 16 forks source link

macOS安装/连接MySQL 5.7.28 #138

Open Qingquan-Li opened 4 years ago

Qingquan-Li commented 4 years ago

环境:


一、安装 MySQL 5.7.28

参考:

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

安装过程中会为 root@localhost 生成一个临时密码,请记好。

使用该临时密码,很多的 MySQL 操作都不能正常进行,所以需要修改密码。

请设置密码策略为 MEDIUM (中等),满足:数字、小写字母、大写字母 、特殊字符、长度至少8位。太简单的密码可能会影响 MySQL 部分操作。

在软件包安装程序过程中,/usr/local/mysql 将自动创建指向安装过程中创建的特定于版本/平台的目录的符号链接 。

# 查看 MySQL 版本
$ mysql -V
mysql  Ver 14.14 Distrib 5.7.28, for macos10.14 (x86_64) using  EditLine wrapper


MySQL 启动/关闭/查看状态

参考:https://coolestguidesontheplanet.com/start-stop-mysql-from-the-command-line-terminal-osx-linux/ 也可以在“系统偏好设置“中启动或关闭 MySQL。

# On macOS Sierra & OSX to start/stop/restart MySQL post 5.7  from the command line:
$ sudo launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
$ sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
# On OS X to start/stop/restart MySQL pre 5.7  from the command line:
$ sudo /usr/local/mysql/support-files/mysql.server start  # 启动
$ sudo /usr/local/mysql/support-files/mysql.server stop   # 关闭
$ sudo /usr/local/mysql/support-files/mysql.server status # 查看状态
# Run the server in safe mode(注意不要漏了字母“l“)
$ sudo mysqld_safe
# Run the server in safe mode with privilege bypass
$ sudo mysqld_safe --skip-grant-tables

# 退出mysqld_safe(需新建终端窗口)
$ /usr/local/mysql/bin/mysqladmin -u root -p shutdown 


二、连接 MySQL 5.7.28

参考:

语法:

$ 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 795
Server version: 5.7.28

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> QUIT;
Bye