600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > mysql修改root用户的密码

mysql修改root用户的密码

时间:2022-05-31 11:04:14

相关推荐

mysql修改root用户的密码

背景

在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) 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 的目录/01/26 09:29 <DIR>./01/26 09:29 <DIR>../01/26 01:28 19,264 echo.exe/01/26 01:28 617,792 harness-library.dll/01/26 01:28 5,098,304 ibd2sdi.exe/01/26 01:28 5,065,536 innochecksum.exe/01/26 01:28 2,110,272 libeay32.dll/01/26 01:28 1,846,592 libmecab.dll/01/26 01:28 4,958,016 lz4_decompress.exe/01/26 01:28 5,353,280 myisamchk.exe/01/26 01:28 5,184,320 myisamlog.exe/01/26 01:28 5,250,880 myisampack.exe/01/26 01:28 5,228,352 myisam_ftdump.exe/01/26 01:28 5,297,472 mysql.exe/01/26 01:28 5,197,120 mysqladmin.exe/01/26 01:28 5,502,272 mysqlbinlog.exe/01/26 01:28 5,209,408 mysqlcheck.exe/01/26 01:28 44,661,568 mysqld.exe/01/26 09:03 390,524,928 mysqld.pdb/01/26 01:28 5,267,264 mysqldump.exe/01/26 08:20 7,902 mysqldumpslow.pl/01/26 08:20 28,713 mysqld_multi.pl/01/26 01:28 5,189,440 mysqlimport.exe/01/26 01:28 5,671,744 mysqlpump.exe/01/26 01:28 5,716,800 mysqlrouter.exe/01/26 01:28 4,927,808 mysqlrouter_plugin_info.exe/01/26 01:29 5,187,904 mysqlshow.exe/01/26 01:29 5,205,312 mysqlslap.exe/01/26 08:20 7,392 mysql_config.pl/01/26 01:29 4,987,200 mysql_config_editor.exe/01/26 01:29 5,188,928 mysql_secure_installation.exe/01/26 01:29 5,016,896 mysql_ssl_rsa_setup.exe/01/26 01:29 4,912,448 mysql_tzinfo_to_sql.exe/01/26 01:29 11,038,528 mysql_upgrade.exe/01/26 01:29 4,970,304 my_print_defaults.exe/01/26 01:29 5,653,312 perror.exe/01/26 01:29 364,352 ssleay32.dll/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-03-19T01:46:39.318148Z 0 [System] [MY-013169] [Server] D:\Program Files\mysql-8.0.15-winx64\bin\mysqld.exe (mysqld 8.0.15) initializing of server in progress as process 5004-03-19T01:46:54.443341Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: !qzy=6kQLYsh-03-19T01:46:58.474643Z 0 [System] [MY-013170] [Server] D:\Program Files\mysql-8.0.15-winx64\bin\mysqld.exe (mysqld 8.0.15) initializing of server has completedD:\Program Files\mysql-8.0.15-winx64\bin>mysqld installService successfully installed.D:\Program Files\mysql-8.0.15-winx64\bin>net start mysqlMySQL 服务正在启动 ....MySQL 服务已经启动成功。D:\Program Files\mysql-8.0.15-winx64\bin>mysql -u root -pEnter password: ************Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 8Server version: 8.0.15Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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 thatcorresponds to your MySQL server version for the right syntax to use near 'password('root')' at line 1mysql> set password for 'root'@'localhost' = password('root');ERROR 1064 (42000): You have an error in your SQL syntax; check the manual thatcorresponds to your MySQL server version for the right syntax to use near 'password('root')' at line 1mysql> use mysqlERROR 1820 (HY000): You must reset your password using ALTER USER statement before 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 thatcorresponds to your MySQL server version for the right syntax to use near '('root') WHERE user = 'root'' at line 1mysql> UPDATE user SET Password = 'root' WHERE user = 'root';ERROR 1046 (3D000): No database selectedmysql> use mysqlERROR 1820 (HY000): You must reset your password using ALTER USER statement before 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 thatcorresponds to your MySQL server version for the right syntax to use near '('root') WHERE User='root'' at line 1mysql> 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 thatcorresponds to your MySQL server version for the right syntax to use near '('Huawei@123') WHERE User='root'' at line 1mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';Query OK, 0 rows affected (0.04 sec)mysql>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。