为了开发更多高级功能,接下来开启数据库学习,选择了mysql来作为后端数据库,在安装mysql的过程中并不一帆风顺,把相关安装过程和遇到的问题都记录下,以备后续忘记参考。
安装:
去官网下载mac对应版本的Mysql,尾缀为.dmg的程序包
下载地址
红框为下载版本
下载完毕后,一步步安装即可,安装完后mysql会弹出一个框框,告诉你安装成功以及设置root用户的初始密码。
开启 MySQL 服务,步骤:系统偏好设置 ——> 点击 MySQL ——> 点击Start MySQL Server,点击后按钮变为Stop MySQL Server
图中左上MySQL 8.0.12的灯变绿
如果没有开启 MySQL 服务,直接下面登陆命令就会出现如下错误:
~ mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
确认开启 MySQL 服务后,执行下面登陆命令输入root账号密码显示如下:
~ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12 MySQL Community Server - GPL
Copyright (c) 2000, 2018, 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,使用Navicat来管理数据库,关于Navicat百度查询相关介绍,下面说明下MySQL8连接不上的问题:
首先建立数据库连接,可参考此文档:Navicat for mac如何使用 Navicat for mac使用教程
在建立本地连接时会出现如下权限错误提示:
Client does not support authentication protocol requested by server; consider upgrading MySQL client
解决办法如下:
~ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.12 MySQL Community Server - GPL
Copyright (c) 2000, 2018, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.05 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的root用户密码';
Query OK, 0 rows affected (0.11 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
然后启动Navicat建立的本地连接就没有问题了,如下图所示:
连接测试成功