mac上mysql root密码忘记或权限错误的解决办法

来源:互联网 发布:免费下载音乐软件 编辑:程序博客网 时间:2024/05/16 07:08

常见问题:

ERROR 1045: Access denied for user: ‘root@localhost’ (Using
password: NO)
ERROR 1045: Access denied for user: ‘root@localhost’ (Using
password: YES)

解决方案 :

重设密码

解决步骤 :

1.关闭数据库

方法1.打开mac的系统偏好设置,选择msyql,手动stop
方法2.sudo /usr/local/mysql/support-files/mysql.server stop

2.执行以下命令

cd /usr/local/mysql/bin
sudo su

然后在sh-3.2#后输入以下命令

./mysqld_safe –skip-grant-tables &

运行结束我们打开mac的系统偏好设置,选择msyql,我们会发现Mysql重新运行了

3.回到终端Command + N 重新打开一个终端

执行 mysql -u -root

这时候发现我们已经能进入mysql了,如下

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
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>

4.重设密码并授权

在mysql> 后运行如下代码

create user ‘root’@’localhost’ identified by ‘admin’
grant all privileges on . to root@’localhost’

上面第一个命令我是创建了一个root用户,密码是admin(可输入自己的)
第二个命令是授权
到这一步你就可以用(root,admin)登录mysql了
最后执行下面的终端命令,验证密码是否可以登录

$mysql -u root -p
输入刚刚设置的admin这个密码就能进入mysql了

阅读全文
0 0
原创粉丝点击