mysql修改root用户的密码
生活随笔
收集整理的這篇文章主要介紹了
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) 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用户的密码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 服务端的缓存简介
- 下一篇: 【解决】Authentication p