mac下mysql忘记了密码怎么办

  1. 关闭mysql服务
    sudo /usr/local/mysql/support-files/mysql.server stop 或者系统偏好里有个 MySQL 里关闭

2.来到mysql目录下
cd /usr/local/mysql/bin

3.得到权限
sudo su

4.重启mysql服务
./mysqld_safe --skip-grant-tables & 或者在系统编号中开启

5.重开终端
mysql -uroot -p (提示输入密码时随便输入即可

  1. 拿到权限(可以修改密码)
    flush privileges;

7.修改密码
set password for 'root'@'localhost'=password('新密码');

set password for 'root'@'localhost'=password('新密码');

  1. 关闭mysql服务
    sudo /usr/local/mysql/support-files/mysql.server stop 或者系统偏好里有个 MySQL 里关闭

2.来到mysql目录下
cd /usr/local/mysql/bin

3.得到权限
sudo su

4.重启mysql服务
./mysqld_safe --skip-grant-tables & 或者在系统编号中开启

5.重开终端
mysql -uroot -p (提示输入密码时随便输入即可

  1. 拿到权限(可以修改密码)
    flush privileges;

7.修改密码
set password for 'root'@'localhost'=password('新密码');

set password for 'root'@'localhost'=password('新密码');

  1. 关闭mysql服务
    sudo /usr/local/mysql/support-files/mysql.server stop 或者系统偏好里有个 MySQL 里关闭

2.来到mysql目录下
cd /usr/local/mysql/bin

3.得到权限
sudo su

4.重启mysql服务
./mysqld_safe --skip-grant-tables & 或者在系统编号中开启

5.重开终端
mysql -uroot -p (提示输入密码时随便输入即可

  1. 拿到权限(可以修改密码)
    flush privileges;

7.修改密码
set password for 'root'@'localhost'=password('新密码');

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'password(’root‘)' at line 1

解决:mysql8 要求先建用户,后授权

新增用户、授权

mysql> create user root@'%' identified by 'root';

mysql> GRANT all on . TO root@'%';

mysql> flush privileges;

取消授权

msyql> revoke all ON . FROM root@'%';

你可能感兴趣的:(mac下mysql忘记了密码怎么办)