- $ vim ~/.bash_profile
- $ vim ~/.zshrc
-
- # 辅助:查看 mysql 本地路径
- $ ps -ef|grep mysql
-
- # 辅助:如果两个配置文件不存在,可以手动创建
- $ cd ~
- $ touch .zshrc
- $ vim .zshrc
-
- # 辅助:如果不想走命令行的方式修改环境变量,也可以直接打开文件进行可视化修改,不支持 Linux 可视化
- $ open ~/.zshrc
-
- export PATH=$PATH:/usr/local/mysql/bin
- export PATH=$PATH:/usr/local/mysql/support-files
-
- :wq
-
- $ source ~/.bash_profile
- $ echo $PATH
-
- $ mysql -V
-
- 开启MySQL服务(需要输入电脑密码,不是数据库登录密码)
- sudo mysql.server start
-
- 停止MySQL服务
- sudo mysql.server stop
-
- 重启MySQL服务
- sudo mysql.server restart
-
- 查看MySQL服务状态
- sudo mysql.server status
-
- $ sudo mysql.server start
-
启动如果报错ERROR! The server quit without updating PID file (/usr/local/mysql/data/dengzemiaodeMacBook-Air.local.pid).这边是因为安装了就默认启动了,已经有进程在了,所以报错,关掉重启就没问题了。还有别的原因也会这样,比如没有读写权限等。- $ mysql -u root -p
-
- dengzemiaodeMacBook-Pro:~ dengzemiao$ mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 466
- Server version: 5.7.28 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
- mysql> exit
- Bye
- dengzemiaodeMacBook-Pro:~ dengzemiao$
-
- set password = password('123456');
-
- dengzemiaodeMacBook-Pro:~ dengzemiao$ mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 466
- Server version: 5.7.28 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> set password = password('123456');
-
回车,然后会提示设置成功。- exit
-
- /usr/local/mysql
-