Mac电脑上安装mysql

方式一:官网下载安装包

登录MySQL官方网站 Mysql官网,然后进入下载页面:https://www.mysql.com/downloads/,我们下载Community版本
这里写图片描述

这里写图片描述

这里,我们选择5.7版本dmg格式下载
这里写图片描述

这里写图片描述

安装

dmg文件安装过程这里省略,比较简单。

安装过程中有个地方要注意下,就是会有一个临时生成的密码,需要记住,建议复制到文本编辑器中

打开MySql服务

系统偏好设置中点击MySql服务,并开启即可。

笔者MySql服务已经是开启状态

这里写图片描述

这里写图片描述

环境变量配置

打开 .bash_profile 文件

kuangaiyongs-MacBook-Pro:~ kay$ vim ~/.bash_profile

将mysql服务路径添加到环境变量中,添加内容如下:

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

然后保存(vim 中先按 Esc键,在输入 :wq )

再在命令行输入如下命令,让刚刚配置的环境变量生效

kuangaiyongs-MacBook-Pro:~ kay$ source ~/.bash_profile

MySql的环境变量就配置好了。

修改密码

在安装MySql过程中,默认生成了一个非常难记的密码,我们需要修改成便于我们记忆和输入的密码。

在命令行输入

kuangaiyongs-MacBook-Pro:~ kay$ mysql -uroot -p
Enter password:

输入之前保存的密码登录mysql,登录成功会看到如下信息:

kuangaiyongs-MacBook-Pro:~ kay$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 5.7.22 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控制台模式下,输入如下内容即可修改密码

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

这里newpass为你需要修改的密码

方式二:命令行安装

在命令行输入

brew install mysql  

brew 包管理工具会自行安装 MySQL

猜你喜欢

转载自blog.csdn.net/kuangay/article/details/80915007