mac上mysql启动和安装

前言

如果没有出现设置密码的选项,而是出现了下面的选项

mac上mysql启动和安装_第1张图片

1、停止MySQL服务。

可能在使用MySQLWorkBench之前,你就开启了MySQL服务,所以这里需要关闭MySQL服务。
关闭MySQL服务的操作:
苹果->系统偏好设置->最下边点MySQL 在弹出页面中 关闭mysql服务(点击stop mysql server)

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZKtXWHJc-1587534711751)(https://raw.githubusercontent.com/HealerJean/HealerJean.github.io/master/blogImages/[email protected])]

2、进入终端,指令重启MySQL服务。

0、打开终端:
1、输入指令1:(进入到mysql的bin目录下)
输入:cd /usr/local/mysql/bin/
2、输入指令2:
输入:sudo ./mysqld_safe --skip-grant-tables
3、输入指令2,会提示输入密码:(Mac账户的root用户密码)

4、输入密码后:会出现一堆提示:

Logging to '/usr/local/mysql-5.7.18-macos10.12-x86_64/data/ShiXiongweideMacBook-Pro.local.err'.
2017-06-17T06:35:38.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-5.7.18-macos10.12-x86_64/data

5、然后会发现,MySQL会自动重启。

附:第二步步骤,我这边终端上指令代码,罗列如下:

ShiXiongweideMacBook-Pro:~ shixiongwei$ cd /usr/local/mysql/bin/
ShiXiongweideMacBook-Pro:bin shixiongwei$ sudo ./mysqld_safe --skip-grant-tables
Password:
Logging to '/usr/local/mysql-5.7.18-macos10.12-x86_64/data/ShiXiongweideMacBook-Pro.local.err'.
2017-06-17T06:35:38.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-5.7.18-macos10.12-x86_64/data

3、另外开一个终端,设置MySQL密码。

0、另外再开一个终端:
1、输入指令1:(进入到mysql的bin目录下)
输入:cd /usr/local/mysql/bin/
2、输入指令2:
输入:./mysql
3、进入到mysql命令状态下:(mysql>是mysql命令状态提示)
输入:mysql> FLUSH PRIVILEGES;
4、设置密码admin123
输入:mysql> SET PASSWORD FOR ‘root’@‘localhost’ = PASSWORD(‘admin123’);

附:第三步步骤,我这边终端上指令代码,罗列如下:

ShiXiongweideMacBook-Pro:~ shixiongwei$ cd /usr/local/mysql/bin/
ShiXiongweideMacBook-Pro:bin shixiongwei$ ./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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)

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 

4、启动mysql

启动MySQL服务
sudo /usr/local/MySQL/support-files/mysql.server start

停止MySQL服务
sudo /usr/local/mysql/support-files/mysql.server stop

重启MySQL服务
sudo /usr/local/mysql/support-files/mysql.server restart


ContactAuthor

你可能感兴趣的:(Mac)