背景

在windows上安装mysql,通过压缩包的方式安装,也就是解压之后,通过配置安装。在安装过程中,会自动产生密码,后期使用时候要修改密码。这种安装方式下,网上搜到的很靠前的解决办法并不能解决问题。

下面是网上一些办法

整理了以下四种在MySQL中修改root密码的方法,可能对大家有所帮助!方法1: 用SET PASSWORD命令mysql -u rootmysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');方法2:用mysqladminmysqladmin -u root password "newpass"如果root已经设置过密码,采用如下方法mysqladmin -u root password oldpass "newpass"方法3: 用UPDATE直接编辑user表mysql -u rootmysql> use mysql;mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';mysql> FLUSH PRIVILEGES;在丢失root密码的时候,可以这样mysqld_safe --skip-grant-tables&mysql -u root mysqlmysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';mysql> FLUSH PRIVILEGES;

亲手尝试

可以看出mysql安装成功,系统生成了密码。

接下来修改密码

可以看出,上面的操作都失败了。

成功操作

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

by 后面就是要设置的新密码

操作参考

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。D:\>cd "Program Files"D:\Program Files>cd mysql-8.0.15-winx64D:\Program Files\mysql-8.0.15-winx64>cd binD:\Program Files\mysql-8.0.15-winx64\bin>ls
'ls' 不是内部或外部命令,也不是可运行的程序
或批处理文件。D:\Program Files\mysql-8.0.15-winx64\bin>dir驱动器 D 中的卷是 DataDisk卷的序列号是 B628-73B4D:\Program Files\mysql-8.0.15-winx64\bin 的目录2019/01/26  09:29    <DIR>          .
2019/01/26  09:29    <DIR>          ..
2019/01/26  01:28            19,264 echo.exe
2019/01/26  01:28           617,792 harness-library.dll
2019/01/26  01:28         5,098,304 ibd2sdi.exe
2019/01/26  01:28         5,065,536 innochecksum.exe
2019/01/26  01:28         2,110,272 libeay32.dll
2019/01/26  01:28         1,846,592 libmecab.dll
2019/01/26  01:28         4,958,016 lz4_decompress.exe
2019/01/26  01:28         5,353,280 myisamchk.exe
2019/01/26  01:28         5,184,320 myisamlog.exe
2019/01/26  01:28         5,250,880 myisampack.exe
2019/01/26  01:28         5,228,352 myisam_ftdump.exe
2019/01/26  01:28         5,297,472 mysql.exe
2019/01/26  01:28         5,197,120 mysqladmin.exe
2019/01/26  01:28         5,502,272 mysqlbinlog.exe
2019/01/26  01:28         5,209,408 mysqlcheck.exe
2019/01/26  01:28        44,661,568 mysqld.exe
2019/01/26  09:03       390,524,928 mysqld.pdb
2019/01/26  01:28         5,267,264 mysqldump.exe
2019/01/26  08:20             7,902 mysqldumpslow.pl
2019/01/26  08:20            28,713 mysqld_multi.pl
2019/01/26  01:28         5,189,440 mysqlimport.exe
2019/01/26  01:28         5,671,744 mysqlpump.exe
2019/01/26  01:28         5,716,800 mysqlrouter.exe
2019/01/26  01:28         4,927,808 mysqlrouter_plugin_info.exe
2019/01/26  01:29         5,187,904 mysqlshow.exe
2019/01/26  01:29         5,205,312 mysqlslap.exe
2019/01/26  08:20             7,392 mysql_config.pl
2019/01/26  01:29         4,987,200 mysql_config_editor.exe
2019/01/26  01:29         5,188,928 mysql_secure_installation.exe
2019/01/26  01:29         5,016,896 mysql_ssl_rsa_setup.exe
2019/01/26  01:29         4,912,448 mysql_tzinfo_to_sql.exe
2019/01/26  01:29        11,038,528 mysql_upgrade.exe
2019/01/26  01:29         4,970,304 my_print_defaults.exe
2019/01/26  01:29         5,653,312 perror.exe
2019/01/26  01:29           364,352 ssleay32.dll
2019/01/26  01:29         4,932,416 zlib_decompress.exe36 个文件    581,400,039 字节2 个目录 186,679,865,344 可用字节D:\Program Files\mysql-8.0.15-winx64\bin>mysqld --initialize --console
2019-03-19T01:46:39.318148Z 0 [System] [MY-013169] [Server] D:\Program Files\mys
ql-8.0.15-winx64\bin\mysqld.exe (mysqld 8.0.15) initializing of server in progre
ss as process 5004
2019-03-19T01:46:54.443341Z 5 [Note] [MY-010454] [Server] A temporary password i
s generated for root@localhost: !qzy=6kQLYsh
2019-03-19T01:46:58.474643Z 0 [System] [MY-013170] [Server] D:\Program Files\mys
ql-8.0.15-winx64\bin\mysqld.exe (mysqld 8.0.15) initializing of server has compl
etedD:\Program Files\mysql-8.0.15-winx64\bin>mysqld install
Service successfully installed.D:\Program Files\mysql-8.0.15-winx64\bin>net start mysql
MySQL 服务正在启动 ....
MySQL 服务已经启动成功。D:\Program Files\mysql-8.0.15-winx64\bin>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.15Copyright (c) 2000, 2019, 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> set password for root@localhost = password('root');
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 'passw
ord('root')' at line 1
mysql> set password for 'root'@'localhost' =  password('root');
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 'passw
ord('root')' at line 1
mysql> use mysql
ERROR 1820 (HY000): You must reset your password using ALTER USER statement befo
re executing this statement.
mysql> UPDATE user SET Password = PASSWORD('root') WHERE user = 'root';
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 '('roo
t') WHERE user = 'root'' at line 1
mysql> UPDATE user SET Password = 'root' WHERE user = 'root';
ERROR 1046 (3D000): No database selected
mysql> use mysql
ERROR 1820 (HY000): You must reset your password using ALTER USER statement befo
re executing this statement.
mysql> UPDATE mysql.user SET Password=PASSWORD('root') WHERE User='root';
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 '('roo
t') WHERE User='root'' at line 1
mysql> UPDATE mysql.user SET Password=PASSWORD('Huawei@123') WHERE User='root';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 '('Hua
wei@123') WHERE User='root'' at line 1
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.04 sec)mysql>

mysql修改root用户的密码相关推荐

  1. linux下 mysql 的root用户忘记密码解决方案

    一. MySQL密码的恢复方法之一 1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 ...

  2. Linux学习之CentOS(二十二)--单用户模式下修改Root用户的密码

    在上一篇随笔里面详细讲解了Linux系统的启动过程 (Linux学习之CentOS(二十一)--Linux系统启动详解),我们知道Linux系统的启动级别一共有6种级别,通过 /etc/inittab ...

  3. MySQL修改root用户密码

    目录 知道密码 忘记密码 知道密码 在清楚的知道密码的情况之下可以使用以下几种方式修改MySQL的密码. 方式一 登录mysql执行以下语句 mysql -u root -p 按回车确认, 如果安装正 ...

  4. 重设MYSQL数据库ROOT用户的密码

    一. 在已知MYSQL数据库的ROOT用户密码的情况下,修改密码的方法: 1. 在SHELL环境下,使用mysqladmin命令设置:mysqladmin –u root –p password &q ...

  5. mysql的root用户添加密码

    刚安装的mysql没有进行配置,默认root用户没有密码,可以使用如下命令为root用户设置密码: #mysqladmin -u root password ******** 转载于:https:// ...

  6. Linux修改root用户登录密码

    echo root:123456 |chpasswd root ---- 登录名 123456 ---- 新登录密码 可以调用system函数,实现在应用程序中修改root用户的登录密码,限制teln ...

  7. mysql 修改root用户密码

    首先我想说一句话: 我极度鄙视国内搞IT的人,简直无语,同样是解决这个问题,几乎一模一样,都是抄来的.更有甚者,抛出的错误是:Access denied for user 'root'@'localh ...

  8. MySQL修改root用户密码 报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

    修改 root 密码 alter user user() identified by '数字 & 大写字母 & 小写字母 & 特殊符号'; 是不是觉得密码又难有复杂 没事还有办 ...

  9. Centos系统mysql 忘记root用户的密码

    第一步:(停掉正在运行的mysql) [root@maomao ~]# service mysqld stop Stopping MySQL:                              ...

最新文章

  1. golang 数组与切片
  2. javax消息队列_java实现消息队列的两种方式(小结)
  3. python中yield的用法
  4. .net html5页面缓存,详解HTML5中的manifest缓存使用
  5. 一个USB HUB电路分享
  6. 关于 block的一些浅识
  7. 解决 吃货阶段02 0928
  8. 授人以渔:stm32资料查询技巧
  9. 【nginx】关于fastcgi_cache
  10. 是的,我们真的在遭遇有史以来最大的DDoS攻击,并且还在加剧
  11. SAP的Abap培训
  12. Xcode调试技巧总结
  13. iOS8 web下载ipa install App via OTA
  14. 2022-2028年中国智慧教育行业发展策略分析及投资前景研究报告
  15. 科技护肤品,买还是不买
  16. PyTorch的参数固定以及detach clone
  17. 神经网络(四)-vanishing gradient problem
  18. 特征选择:11 种特征选择策略总结!
  19. 【22物联网国赛样题】zigbee点对点呼吸灯,按键长按双击效果,物联网竞赛今年历年国赛样题真题代码
  20. 一个关于APP开发者的复兴之路 区块连

热门文章

  1. Django 一些 简单 配置
  2. 深渊水妖 模拟,贪心 牛客白月赛44
  3. mysql创建数据库schooldb_MySQL 创建数据表
  4. java excel导入去重_如何把日志导入到excel文档图文教程(含url去重)
  5. java 操作 ldap_JAVA操作LDAP总结
  6. telegram电脑一直显示连接中_小事不求人!学会这个方法,一个电脑连接多个显示器不再是问题...
  7. linux加载虚拟sriov网卡,如何配置BroadCOM网卡的SR-IOV功能
  8. ups容量计算和配置方法_干货 | ups的空开、电缆及电池的配置计算
  9. pythondict增加-python字典键值对的添加和遍历方法
  10. 13-Qt6 QMap