Linux Mysql 提示 Access denied for user ‘jira‘@‘localhost‘ (using password: YES)
·
问题
刚刚在 Linux安装数据库 MySql,选择的是直接登录,没有输入密码。
mysql -uroot -p
use mysql;
后面配置号数据库后,会提示下面问题:

原因
网上查看,可能原因如下:
- mysql 的服务器停止
- 用户的端口号或者IP导致
- mysql 的配置文件错误——my.cnf等文件
- root用户的密码错误
解决办法1
首先要确认自己在配置 mysql 的时候有没有配置 jira 用户
[root@localhost ~]# mysql -ujira -p
Enter password:****
ERROR 1045 (28000): Access denied for user 'jira'@'localhost' (using password: YES)
如果没有,那么大概率是用户名或者密码错误导致的。需要重新修改密码或者更换 用户再尝试。
大概率也有可能是 jira 用户默认是没配置密码的。
mysql -ujira -p
Enter password: #这里直接敲回车,尝试是否没有配置密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 35571
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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>
解决办法2
查找配置文件
Step1:首先找到 mysqld 的路径,如下:
[root@localhost ~]# which mysqld
/usr/sbin/mysqld
Step2:敲命令:/usr/sbin/mysqld --verbose --help |grep -A 1 ‘Default options’ 找到配置文件,如下:
[root@localhost ~]# /usr/sbin/mysqld --verbose --help |grep -A 1 'Default options'
2021-07-20 02:12:05 0 [Note] /usr/sbin/mysqld (mysqld 5.6.51) starting as process 8201 ...
2021-07-20 02:12:05 8201 [Note] Plugin 'FEDERATED' is disabled.
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
2021-07-20 02:12:05 8201 [Note] Binlog end
2021-07-20 02:12:05 8201 [Note] Shutting down plugin 'MyISAM'
2021-07-20 02:12:05 8201 [Note] Shutting down plugin 'CSV
其中 /etc/my.cnf 就是排序第一的配置文件。

Step3:修改 /etc/my.cnf 配置文件
在[mysqld]后添加 skip-grant-tables(使用 set password for设置密码无效,且此后登录无需键入密码)
skip-grant-tables #在my.cnf,[mysqld]下添加一行,使其登录时跳过权限检查

重启数据库
systemctl restart mysql
重新连接测试

小结
- Mysql 配置文件:my.cnf ;
- Mysql 跳过登录验证,skip-grant-tables ;
- 配置修改完毕需要重启Mysql ;
参考
更多推荐
所有评论(0)