mac 安装 mysql

Mac 安装Mysql

下载mysql

第一步:打开网址,https://www.mysql.com,点击downloads之后跳转到https://www.mysql.com/downloads/选择Community选项
第二步: 第一步结束后程序会跳转到https://dev.mysql.com/downloads/网址,点击MySQL Community Server进入下面的页面,再点击5.7版本的数据库
第三步:mac操作系统 点击5.7版本之后会跳转到https://dev.mysql.com/downloads/mysql/5.7.html downloads 网址,下载macOS 10.14 (x86, 64-bit), DMG Archive 第一个类型,直接是dmg格式
第四步:可以不用登陆或者注册,直接点击No thanks,just start my download就可以下载了。
第五步:双击下载好的dmg文件,会弹出pkg弹框,再双击pkg图标,进入安装界面
第六步:在安装界面上一路继续,最后就安装成功了。

配置环境变量

第一步 :在终端切换到根目录,编辑./.bash_profile文件
cd ~
vim ./.bash_profile
第二步 :进入vim 编辑环境。 按下i 进入 insert 模式 ,输入
export PATH=$PATH:/usr/local/mysql/bin
export PATH=$PATH:/usr/local/mysql/support-files
第三步 :按下esc 退出 insert 模式,输入:wq保存配置文件。
:wq
第四步 :在终端界面下输入以下命令,让配置文件的修改生效,并查看环境变量是否设置成功
source ~/.bash_profile 
echo $PATH

查看mysql服务语句

停止MySQL服务
sudo mysql.server stop

重启MySQL服务
sudo mysql.server restart

查看MySQL服务状态
sudo mysql.server status

提示密码错误,需修改配置文件,重置密码

输入:
sudo /usr/local/mysql/support-files/mysql.server stop回车
提示:
Shutting down MySQL
. SUCCESS!
输入:
cd /usr/local/mysql/bin/回车
提示:
bin
输入:
sudo su回车
提示:
sh-3.2#
输入:
./mysqld_safe --skip-grant-tables &回车
提示:
[1] 10016
sh-3.2# 2019-08-27T13:17:00.6NZ mysqld_safe Logging to '/usr/local/mysql-5.7.27-macos10.14-x86_64/data/zhangshandeMacBook-Pro.local.err'.
2019-08-27T13:17:00.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-5.7.27-macos10.14-x86_64/data
输入:
./mysql回车
提示:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 5.7.27 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
输入:
FLUSH PRIVILEGES;回车
提示:
Query OK, 0 rows affected (0.01 sec)
输入:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');回车
提示:
Query OK, 0 rows affected, 1 warning (0.01 sec)
设置密码
输入:
exit回车
退出mysql
输入:
exit回车
退出su权限
输入:
sudo /usr/local/mysql/support-files/mysql.server restart回车
重启服务
Password:
输入:
密码本机密码
提示:
Shutting down MySQL
..2019-08-27T13:21:49.6NZ mysqld_safe mysqld from pid file /usr/local/mysql-5.7.27-macos10.14-x86_64/data/zhangshandeMacBook-Pro.local.pid ended
 SUCCESS! 
停止mysql成功
Starting MySQL
. SUCCESS!
启动mysql成功
输入:
/usr/local/mysql/bin/mysql -uroot -p回车
Enter password: 
输入:
登录数据库的密码123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 29
Server version: 5.7.27 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成功
输入:
select user();

卸载mysql

1、备份数据库
在终端工具中使用mysqldump备份你的数据库将文本文件!
或者用Navicat premium工具去备份数据库脚本和数据
推荐使用mysqldump备份
2、停止数据库服务器
3、删除一下目录
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*
posted @ 2019-08-29 08:01  挂机兄  阅读(2292)  评论(0编辑  收藏  举报