Mac 下安装mysql,并更改初始密码
1、mac 10.13.6 安装mysql
下载地址:https://downloads.mysql.com/archives/community/
选择适合的版本,我的Mac是10.13.6,适合的版本是5.7.23
下载完成后,根据提示正常安装就行!
但是!!!
当安装完成是,会生成一个初始密码!一定要记住这个初始密码!!!
接下来就可以使用密码登入了
首先需要启动mysql(需要输入用户密码):
sudo /usr/local/mysql/support-files/mysql.server start
也可以通过偏好设置找到mysql,手动开启服务
登入mysql
export PATH=$PATH:/usr/local/mysql/bin
mysql -u root -p
按回车需要输入刚刚的初始密码
用完可以关闭mysql服务
sudo /usr/local/mysql/support-files/mysql.server stop
同样也可以通过偏好设置找到mysql,手动开启服务
2、更改初始密码
1、首先确保mysql服务已关闭,如果开启,请关闭
2、进入mysql的bin目录执行如下命令
cd /usr/local/mysql/bin
sudo su
之后输入管理员密码会看到
sh-3.2#
3、之后我们输入下面命令以安全模式运行mysql
./mysqld_safe --skip-grant-tables &
运行结束我们打开mac的系统偏好设置,选择msyql,我们会发现Mysql重新运行了如图
4、回到终端点击Command + N 重新打开一个终端 输入
export PATH=$PATH:/usr/local/mysql/bin
mysql -u -root
这时候我们不需要密码就能进入mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 5.7.23 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>
5、接下来修改密码!
5-1、首先执行下面命令为了能够修改任意的密码
FLUSH PRIVILEGES;
5-2、之后执行修改密码的SQL语句,这里的****可以替换你自己想要修改的密码
SET PASSWORD FOR root@'localhost' = PASSWORD('****');
5-3、最后刷新
FLUSH PRIVILEGES;
6、Control+D推出mysql,关闭当前窗口,回到原来窗口。然后关闭安全模式数据库,这里要输入你刚才设置数据密码就好啦
/usr/local/mysql/bin/mysqladmin -u root -p shutdown
7、exit退出,返回当前用户。到这里密码就更改完成啦!
8、重启mysql,并用新密码登入!!!
启动mysql(需要输入用户密码):
sudo /usr/local/mysql/support-files/mysql.server start
进入mysql
export PATH=$PATH:/usr/local/mysql/binmysql -u root -p
输入新密码
Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 24 Server version: 5.7.23 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>
进入成功!!!