mysql-5.5密码是多少_关于mysql-5.5数据库密码的设置和重置
一、mysql-5.5數據庫的密碼長什么樣?
直接打開給你看:
[root@lnmp1 ~]# mysql -uroot -p#在已知密碼的情況想打開數據庫
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use mysql;#切換至mysql庫
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> select host,user,password from user where user='root';#查看root用戶的密碼。
+-----------------------+------+-------------------------------------------+
| host | user | password |
+-----------------------+------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost.localdomain | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ::1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------------------+------+-------------------------------------------+
4 rows in set (0.00 sec)
以上可見,root用戶可以用4種方式登錄數據庫,而密碼……其實我的密碼沒有這么復雜(這么復雜我也記不住不是?)。Mysql的數據庫密碼是經過加密的。通過查詢數據庫看到的密碼,是加密后的樣子。如果你看到自己的數據庫密碼是明文的樣子,打個比方,你設置的密碼是:abc123,設置完之后,經過我以上給出的步驟查詢發現,顯示的還是:abc123,那說明是你設置密碼的方式錯了。比如用下面這種方式:
update user set valuse='abc123' where user='root';
不要問我怎么知道的……
二、設置mysql-5.5數據庫密碼的正確姿勢
在數據庫無密碼狀態下,打開數據庫,按照如下步驟設置密碼:
[root@lnmp1 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>USE mysql#切換使用的數據庫
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> update user set password=password('abc123') where user='root';#設置你需要的密碼,我這里用的密碼是:abc123
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
MariaDB [mysql]> exit#退出數據庫
Bye
[root@lnmp1 ~]# mysql -uroot -p#使用剛剛設置到的密碼登陸。
Enter password:
三、mysql-5.5數據庫密碼的重置
場景一:打開好久不用的數據庫,想不起密碼是什么了,悲催的是,你還沒有記錄的習慣。
場景二:哎呀!好激動啊,數據庫終于可以使用了,保險起見,這次要設置一個安全點的密碼(鬼知道他剛剛經歷了什么……),經過一番折騰,終于設置了一個安全的密碼,結果登錄的時候發現:WC!我剛才設置的密碼是啥???
好吧,希望你們不要遇到以上的情況。即使遇上了,也不用急著跑路,我告訴你一個重置密碼的方法,親測好用。
大致流程是這樣的:
編輯mysql的配置文件,在配置文件中增加這個參數:skip-grant-tables。直譯就是:跳過授權表。
重啟數據庫服務,使參數生效。
到了這一步讓,你就可以不使用密碼打開數據庫了。趕緊按照我在上面第二部分介紹的方法設置密碼吧。
設置完密碼后,是不能直接使用密碼登錄數據庫的。還記得我們第1步做了什么嗎?重新編輯配置文件,將添加的參數注釋掉,或者刪除。
重啟數據庫服務,就可以使用密碼正常登陸了。
以上步驟涉及的命令行如下:
echo skip-grant-tables >> /etc/my.cnf
systemctl restart mariadb
是不是很簡單?
四、注意!
以上所有操作均在MySQL-5.5版本下進行,其他版本未測試,請謹慎使用,切記!!!
在my.cnf文件中增加參數時,注意使用的重定向符號為“>>”,是追加,不是覆蓋。推薦盡量使用vi或vim操作,以防誤操作,導致配置文件原內容被覆蓋,造成丟失。
在保證安全的情況下,做好密碼記錄,可以防止本文中出現的情況,祝各位好運!!!
本文參考了:https://blog.csdn.net/yan13507001470/article/details/70833468
向作者致謝!
總結
以上是生活随笔為你收集整理的mysql-5.5密码是多少_关于mysql-5.5数据库密码的设置和重置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 防ddos攻击系统(DDOS攻击自治系统
- 下一篇: vc mysql 图片_VC连接MySQ