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