linux下mysql密碼錯誤的解決方法:
#前言
今天在伺服器安裝mysql之後,登入發現密碼錯誤,但是我沒有設定密碼呀,最後百度之後得知,mysql在5.7版本之後會自動建立初始密碼。
報錯如下:
[root@mytestlnx02 ~]# mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
修改密碼
1. 檢查mysql
服務是否啟動,如果啟動,關閉mysql
服務
//查看mysql服务状态 [root@mytestlnx02 ~]# ps -ef | grep -i mysql root 22972 1 0 14:18 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql mysql 23166 22972 0 14:18 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock root 23237 21825 0 14:22 pts/0 00:00:00 grep -i mysql //关闭服务 [root@mytestlnx02 ~]# service mysql stop [root@mytestlnx02 ~]#
2. 修改mysql
的設定檔my.cnf
my.cnf
設定檔的位置,一般在/etc/my.cnf
,有些版本在/etc/mysql/my.cnf
在設定檔中,增加2行程式碼
[mysqld] skip-grant-tables
作用是登入mysql的時候跳過密碼驗證
然後啟動mysql服務,並進入mysql
[root@mytestlnx02 ~]# service mysqld start [root@mytestlnx02 ~]# [root@mytestlnx02 ~]# mysql -u root Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
3. 修改密碼
連接mysql這個資料庫,修改使用者密碼
mysql> 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 mysql> update mysql.user set authentication_string=password('root_password') where user='root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit
4. 重啟mysql服務
先將先前加在設定檔裡面的2句程式碼註解或刪除掉,然後重新啟動mysql服務,就可以使用剛剛設定的密碼登入了。
[root@mytestlnx02 ~]# service mysql start [root@mytestlnx02 ~]# [root@mytestlnx02 ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. p.s.
在CentOS上的操作方式有所不同。
執行修改密碼的指令一直報錯
mysql> update user set authentication_string=password('xxxxxxxx') 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 '('root_password') where User='root'' at line 1
不可能是語法問題,檢查了很多遍,最後發現CentOS下應該這樣操作:
查看初始密碼
[root@VM_0_8_centos ~]# grep 'temporary password' /var/log/mysqld.log 2018-09-26T04:25:54.927944Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: DN34N/=?aIfZ
可以看到初始密碼為DN34N/=?aIfZ
使用初始密碼登入
[root@VM_0_8_centos ~]# 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.12 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
修改密碼
mysql> ALTER USER 'root' IDENTIFIED BY 'xxxxxxxxx'; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxxxxxx'; Query OK, 0 rows affected (0.11 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> exit Bye 重启服务
就生效了
[root@VM_0_8_centos ~]# service mysqld stop Redirecting to /bin/systemctl stop mysqld.service [root@VM_0_8_centos ~]# service mysqld start Redirecting to /bin/systemctl start mysqld.service
推薦教學: 《linux教學》
以上是解決linux下mysql密碼錯誤的問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本文探討如何在Debian系統上提升Hadoop數據處理效率。優化策略涵蓋硬件升級、操作系統參數調整、Hadoop配置修改以及高效算法和工具的運用。一、硬件資源強化確保所有節點硬件配置一致,尤其關注CPU、內存和網絡設備性能。選擇高性能硬件組件對於提升整體處理速度至關重要。二、操作系統調優文件描述符和網絡連接數:修改/etc/security/limits.conf文件,增加系統允許同時打開的文件描述符和網絡連接數上限。 JVM參數調整:在hadoop-env.sh文件中調整

本指南將指導您學習如何在Debian系統中使用Syslog。 Syslog是Linux系統中用於記錄系統和應用程序日誌消息的關鍵服務,它幫助管理員監控和分析系統活動,從而快速識別並解決問題。一、Syslog基礎知識Syslog的核心功能包括:集中收集和管理日誌消息;支持多種日誌輸出格式和目標位置(例如文件或網絡);提供實時日誌查看和過濾功能。二、安裝和配置Syslog(使用Rsyslog)Debian系統默認使用Rsyslog。您可以通過以下命令安裝:sudoaptupdatesud

選擇適合Debian系統的Hadoop版本,需要綜合考慮以下幾個關鍵因素:一、穩定性與長期支持:對於追求穩定性和安全性的用戶,建議選擇Debian穩定版,例如Debian11(Bullseye)。該版本經過充分測試,擁有長達五年的支持週期,能夠確保系統穩定運行。二、軟件包更新速度:如果您需要使用最新的Hadoop功能和特性,則可以考慮Debian的不穩定版(Sid)。但需注意,不穩定版可能存在兼容性問題和穩定性風險。三、社區支持與資源:Debian擁有龐大的社區支持,可以提供豐富的文檔和

本文介紹如何在Debian系統上使用TigerVNC共享文件。你需要先安裝TigerVNC服務器,然後進行配置。一、安裝TigerVNC服務器打開終端。更新軟件包列表:sudoaptupdate安裝TigerVNC服務器:sudoaptinstalltigervnc-standalone-servertigervnc-common二、配置TigerVNC服務器設置VNC服務器密碼:vncpasswd啟動VNC服務器:vncserver:1-localhostno

配置Debian郵件服務器的防火牆是確保服務器安全性的重要步驟。以下是幾種常用的防火牆配置方法,包括iptables和firewalld的使用。使用iptables配置防火牆安裝iptables(如果尚未安裝):sudoapt-getupdatesudoapt-getinstalliptables查看當前iptables規則:sudoiptables-L配置

在Debian郵件服務器上安裝SSL證書的步驟如下:1.安裝OpenSSL工具包首先,確保你的系統上已經安裝了OpenSSL工具包。如果沒有安裝,可以使用以下命令進行安裝:sudoapt-getupdatesudoapt-getinstallopenssl2.生成私鑰和證書請求接下來,使用OpenSSL生成一個2048位的RSA私鑰和一個證書請求(CSR):openss

在Debian系統上配置郵件服務器的虛擬主機通常涉及安裝和配置郵件服務器軟件(如Postfix、Exim等),而不是ApacheHTTPServer,因為Apache主要用於Web服務器功能。以下是配置郵件服務器虛擬主機的基本步驟:安裝Postfix郵件服務器更新系統軟件包:sudoaptupdatesudoaptupgrade安裝Postfix:sudoapt

要配置Debian郵件服務器的DNS設置,您可以按照以下步驟進行操作:打開網絡配置文件:使用文本編輯器(例如vi或nano)打開網絡配置文件/etc/network/interfaces。 sudonano/etc/network/interfaces查找網絡接口配置:在配置文件中找到要修改的網絡接口。通常情況下,以太網接口的配置位於ifaceeth0區塊中。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

WebStorm Mac版
好用的JavaScript開發工具

禪工作室 13.0.1
強大的PHP整合開發環境

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Dreamweaver CS6
視覺化網頁開發工具