(28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)
在一台测试服务器测试Python脚本时,执行Python脚本时报如下错误:
主要错误信息为“operation the sql fail!1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)”。 部分测试脚本如下所示,如下所,mysql.connector.connect的host为127.0.0.1 其它账号信息做了脱敏处理.
def record_server_info():
try:
server_ip = get_host_ip();
server_name= str.strip(get_host_name());
server_system=platform.system();
linux_dis =platform.linux_distribution();
os_version =''
os_version = ' '.join(linux_dis)
os_bitinfo = platform.architecture()
os_bit =os_bitinfo[0][0:2]
processor = str.strip(commands.getoutput("cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c"))
cpu_slot= commands.getoutput("cat /proc/cpuinfo | grep 'model name' | sort | uniq | wc -l");
cpu_core = multiprocessing.cpu_count();
processor_core =int(cpu_core)/int(cpu_slot);
memory = get_physical_memory()
disk_space = get_disk_info()["capacity"]/1024/1024;
dbcon = mysql.connector.connect(
host='127.0.0.1',
user='root',
passwd='123456',
database='mysql'
)
cursor = dbcon.cursor()
sql_tex =( "insert into db_server_info("
"factory_cd ,"
"server_name ,"
"server_ip ,"
"server_type ,"
"server_system ,"
"is_production ,"
"os_version ,"
"os_patch ,"
"os_bit ,"
"processors ,"
"cpu_slot ,"
"processors_core ,"
"memory ,"
"disk_space ,"
"server_purpose) "
"values(%(factory_cd)s,%(server_name)s,%(server_ip)s,%(server_type)s,%(server_system)s,%(is_production)s,%(os_version)s,%(os_patch)s,%(os_bit)s,%(processors)s,%(cpu_slot)s,%(processors_core)s,%(memory)s,%(disk_space)s,%(server_purpose)s)")
data={'factory_cd':factory_cd, 'server_name':server_name, 'server_ip':server_ip,"server_type":server_type,"server_system":server_system,"is_production":is_productin,"os_version":os_version, "os_patch":'',"os_bit":int(os_bit), "processors":processor,"cpu_slot":cpu_slot, "processors_core":processor_core,"memory":memory,"disk_space":disk_space,"server_purpose":''}
cursor.execute('truncate table db_server_info')
dbcon.commit()
cursor.execute(sql_tex, data)
dbcon.commit()
except mysql.connector.Error as e:
print('operation the sql fail!{0}'.format(e))
finally:
cursor.close;
dbcon.close;
mysql -u root -p 测试登录MySQ发现没有问题,但是一检查发现,如果不指定host的情况下,当前用户为root@localhost,而root@'127.0.0.1'的密码为空。
mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> show grants for root@'localhost';
+---------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*9B67EF98D94F2B81011D6D2CEDE4' WITH GRANT OPTION|
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> show grants for root@'127.0.0.1';
+---------------------------------------------------------------------+
| Grants for root@127.0.0.1 |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
立即检查my.cnf的配置,发现可能某次测试时,设置了参数 skip-name-resolve, 后面忘记取消了。由于启动mysqld时使用了'--skip-name-resolve'参数,此种情况下由于不做域名解析,127.0.0.1和localhost对mysql数据库来讲,是不同的主机,而root@'127.0.0.1'为空密码,所以Python脚本执行时,访问MySQL报错“(28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)”
(28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)的更多相关文章
- ERROR 1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)
我的原因是在配置文件my.ini [mysqld]项,在其后加入了一句:skip-name-resolve 导致授权出现这个错误,把skip-name-resolve这项屏蔽了就好了. 场景2:对所有 ...
- Ubuntu下MySQL报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
在Ubuntu下 想要登录mysql数据库 root@JD:~# mysql -uroot -p 报错 ERROR 1045 (28000): Access denied for user 'root ...
- MySQL密码正确却无法本地登录,ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
MySQL密码正确却无法本地登录 报错如下: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password ...
- Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
案例环境: 操作系统 :Red Hat Enterprise Linux Server release 5.7 (Tikanga) 64 bit 数据库版本 : Mysql 5.6.19 64 bit ...
- MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)的真正原因
在博客Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: N ...
- 【转载】重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor ...
- centos7 上安装mysql5.7后登录报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Yes 或者No)
原文转载自以下链接:https://blog.csdn.net/keepd/article/details/77151006 安装完mysql后会有个临时密码去日志查看,但是查看登录修改密后还是不行 ...
- ERROR 1698 (28000): Access denied for user 'root'@'localhost' 解决方法
之前MySQL服务端本机上使用密码登陆root账号是没有问题的,但是今天不知道是因为动了哪里,登陆失败并有这个错误代码: ~$ mysql -u root -p Enter password: ERR ...
- mac下mysql 1045 (28000): Access denied for user 'root'@'localhost' (using password:
新入了mac pro,安装好mysql后,用终端进入mysql遇到个问题: 1045 (28000): Access denied for user 'root'@'localhost' (using ...
随机推荐
- 端口扫描命令nmap
转:http://www.osyunwei.com/archives/2004.html 下面教大家在CentOS中用nmap查看主机端口: 一.安装nmap yum install nmap -y ...
- Node.js--安装express以及创建第一个express项目(windows)
1.根据新版的express出现了安装器的概念,安装express需要两个步骤(命令行找到nodejs目录全局安装): (1)npm install -g express@4.15.0 (也可省略 ...
- 跨进程的mutex
1.操作系统分为ring0(内核层)和ring3(应用层)两层. ring0层出错会蓝屏,ring3层出错程序就会挂了. event和mutex创建他的指针是应用层,但是它的内部是ring0层,rin ...
- 使用open-falcon监控Nginx
一.介绍 前段时间部署试用了open-falcon v0.2,官方文档很详细,难度也不是很大.监控Nginx也参考了文档推荐的方式,文档地址:http://book.open-falcon.org/z ...
- LANMP系列教程之php编译安装CentOS7环境
前提:必须先安装好MySQL以及Apache 1.准备好源码包并配置好yum源,需要的源码包包括: libmcrypt-2.5.8-9.el6.x86_64.rpm libmcrypt-devel ...
- JDK,JRE,JVM的区别与联系
JDK : Java Development ToolKit(Java开发工具包).JDK是整个JAVA的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工 ...
- [原]开源的视频转换器,支持gpu,绝对好用ffmpeg的GUI==》dmMediaConverter最新版本2.3
dmMediaConverter is a crossplatform FFmpeg frontend (GUI) exposing some of its features. It is inten ...
- jira + confluence 安装和破解
Window环境: 环境准备 安装JAVA1.8以上版本 安装SQL SERVER 或 MySQL: jira安装和破解 下载安装包 https://downloads.atlassian.com/s ...
- hbuilder ios 打包失败,无法导入p12证书的解决方案
问题描述: 在profile文件和私钥证书通过hbuilder ios 打包成功过的前提下,突然遇到打包失败的问题,问题详情是无法导入p12证书. 探索过程: 本着遇到问题先自省的态度,重复打包了几次 ...
- python学习:设计一个算法将缺失的数字找出来。
算法题 已知整型数值 a[99], 包含的所有99个元素都是从1-100中随机取值,并且这99个数两两互不相等,也就是说从1到100这100个数字有99个在数值内,有一个缺失.请设计一个算法将缺失 ...