当前位置: 首页 » 网站建设 » 网站建设知识 » 正文

mysql root密码忘了怎么办?(MAC,也适用与unix和windows)

发布时间:2025-07-22 以下文章来源于网友投稿,内容仅供参考!

mysql root密码忘了怎么办?(MAC,也适用与unix和windows)。我相信无数安装mysql的同学和我一样,对于mysql那个极不人道的临时root密码极为不满。

我在mysql官网下载的mac版本的安装包,我用的是dmg格式的,版本是5.7.18。

附上官网链接:https://dev.mysql/downloads/mysql/

我的手比较贱,觉得dmg安装时傻瓜式的,一直按呀按,最后连临时root密码也没记得,根据官网介绍,这个临时密码如果你没记清楚,你就找不到了,而且你用wordkbench链接mysql时必须要用这个root密码,所以开始了辛酸的reset密码的过程。网上关于如何重置root密码的教程可谓是多如牛毛,但是我TM就一个也没试验成功的,为啥呢?后来我才明白,mysql版本不断的更新,reset密码的步骤一直在变,网上的那些教程都太老了,对于像5.7.18这样的新版本不适用。在对网上给出的那些教程彻底失望之后,我还是老老实实的到官网manual中寻找最新的解决方案,

我试验成功的解决步骤:

1,关掉已经在运行的mysql,MAC上可以在偏好设置里直接关掉或者通过命令行

sudo /usr/local/mysql/support-files/mysql.server stop

2,进入目录

cd /usr/local/mysql/bin

3,获取权限

sudo su

4,使用下面的命令可以跳过验证直接启动服务器

./mysqld_safe --skip-grant-tables

5,重新开个新终端

6,输入命令mysql

mysql

7,输入命令FLUSH PRIVILEGES; 注意带上后面的";"号

FLUSH PRIVILEGES;

8,输入一下命令(凡是版本大于等于5.7.6的都这么输入,老版本的请看文章最后附上官网介绍),MyNewPass就是你的新密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

现在你已经完成了root密码的重置,在workbench中连接吧。

B.5.3.2.3Resetting the Root Password: Generic Instructions

The preceding sections provide password-resetting instructions specifically for Windows and Unix and Unix-like systems. Alternatively, on any platform, you can reset the password using themysqlclient (but this approach is less secure):

Stop the MySQL server if necessary, then restart it with the--skip-grant-tablesoption. This enables anyone to connect without a password and with all privileges, and disables account-management statements such asALTER USERandSET PASSWORD. Because this is insecure, you might want to use--skip-grant-tablesin conjunction with--skip-networkingto prevent remote clients from connecting.

Connect to the MySQL server using themysqlclient; no password is necessary because the server was started with--skip-grant-tables:

shell> mysql

In themysqlclient, tell the server to reload the grant tables so that account-management statements work:

mysql> FLUSH PRIVILEGES;

Then change the'root'@'localhost'account password. Replace the password with the password that you want to use. To change the password for arootaccount with a different host name part, modify the instructions to use that host name.

MySQL 5.7.6 and later:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

MySQL 5.7.5 and earlier:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

You should now be able to connect to the MySQL server asrootusing the new password. Stop the server and restart it normally (without the--skip-grant-tablesand--skip-networkingoptions).

If theALTER USERstatement fails to reset the password, try repeating the procedure using the following statements to modify theusertable directly:

UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPass')

WHERE User = 'root' AND Host = 'localhost';

FLUSH PRIVILEGES;

  • • MySql-InnoDB数据库引擎

    MySql数据库的结构Mysql采用单进程多线程系统结构,Mysql采用插件结构,将对数据库表的操作和管理交个数据库引擎完成。核心组件

  • • MySQL修改索引名称

    MySQL修改索引名称。对于MySQL 5.7及以上版本,可以执行以下命令:ALTER TABLE tbl_name RENAME INDEX old_index_name TO new_ind

  • • mysqlgroupby组内排序方法

    mysqlgroupby组内排序方法。mysql的group by语法可以根据指定的规则对数据进行分组,分组就是将一个数据集划分成若干个小区域,

  • • MySQL基本操作

    初步知识数据库是一个以某种有组织方式存储的数据的集合 DBMS是数据库管理系统也叫数据库软件 MySQL是一种DBMS SQL语句是DBMS用

  • • mysql(七)mysql安装步骤

    mysql(七)mysql安装步骤。注:我的运行环境是widnows xp professional + MySQL5.0一, 创建用户: 命令:CREATE USER 'usernam

  • 今年哪天霜降-今日霜降是几点几分
    霜降节气的特点和风俗-霜降节气风俗大全
    2025大寒是阳历几月几日?2025大寒是哪一天
    2025万圣节是几号?今年万圣节是几月几日
    今年的霜降是几月几号?2025霜降是哪一天
    铁路12306密码格式有什么要求_铁路12306密码设置规则说明
    2025年中国的重阳节是农历的哪一天
    2025年重阳节是几月几日?2025年重阳节是哪一天
    万圣节对中国人危害?中国禁止过万圣节原因
    万圣节是哪个国家的节日?万圣节源自于哪个国家