(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 ...
随机推荐
- 面试中的TCP协议
TCP的三次握手和四次挥手 三次握手 TCP连接是通过三次握手来连接的. 第一次握手 当客户端向服务器发起连接请求时,客户端会发送同步序列标号SYN到服务器,在这里我们设SYN为x,等待服务器确认,这 ...
- [DeeplearningAI笔记]改善深层神经网络1.1_1.3深度学习使用层面_偏差/方差/欠拟合/过拟合/训练集/验证集/测试集
觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.1 训练/开发/测试集 对于一个数据集而言,可以将一个数据集分为三个部分,一部分作为训练集,一部分作为简单交叉验证集(dev)有时候也成为验 ...
- 06_Linux系统常用命令
一.命令使用方法 Linux命令格式 command [-option] [parameter1] [parameter2]... command:相应功能的英文单词或者单词的缩写 option:可用 ...
- iOS-image图片压缩
///压缩图片 + (NSData *)imageCompressToData:(UIImage *)image{ NSData *data=UIImageJPEGRepresentation(ima ...
- iOS-属性字符串添加下划线、删除线
常用到的属性字符串 ///定义属性字符串NSMutableAttributedString *att = [[NSMutableAttributedString alloc]initWithStrin ...
- 1.C和C++区别,以及const分析
从本章起开始从0学习C++,本章主要内容: 1)C和C++的基本区别 2)C和C++的const区别 1.C++和C区别 1.1 C++更强调语言的实用性,所有变量都可以在需要时再定义 比如: ;i& ...
- BZOJ 2388: 旅行规划 [分块 凸包 等差数列]
传送门 题意: 区间加和询问一段区间内整体前缀和的最大值 刚才还在想做完这道题做一道区间加等差数列结果发现这道就是.... 唯一的不同在于前缀和一段区间加上等差数列后,区间后面也要加上一个常数!!! ...
- [偏序关系与CDQ分治]【学习笔记】
组合数学真是太棒了 $CDQ$真是太棒了(雾 参考资料: 1.<组合数学> 2.论文 课件 很容易查到 3.sro __stdcall 偏序关系 关系: 集合$X$上的关系是$X$与$X$ ...
- xftp上传失败之解决办法
修改/usr/local 文件夹权限 rwx 为不可读不可写第三方不可访问 报错 传输状态 恢复文件夹/usr/local 读写第三方访问权限 成功上传
- Golang Linux Shell编程(一)
1.调用系统命令 exec包执行外部命令,它将os.StartProcess进行包装使得它更容易映射到stdin和stdout,并且利用pipe连接i/o func Command(name stri ...