mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
這個問題是因為在嘗試使用命令行連接MySQL時,使用了明文密碼,這是不安全的。同時,由于某種原因,您的root用戶被拒絕訪問。這里有幾個解決方案:
方法1:使用配置文件來存儲密碼
1. 創建或編輯名為`my.cnf`(Linux)或`my.ini`(Windows)的配置文件。通常可以在以下位置找到它們:
/etc/my.cnf
/etc/mysql/my.cnf
$MYSQL_HOME/my.cnf
~/.my.cnf
2. 在`[mysqld]`部分添加以下內容:
skip-grant-tables
3. 保存并關閉文件。
4. 重啟MySQL服務。
5. 使用無密碼登錄:
mysql -u root
6. 設置新密碼:
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_pas