当前位置: 首页 > news >正文

mysql socket文件丢失处理或者mysql.sock被删除

为了数据库安全,限制了MySQL中root用户只能本地登录,其他用户不得拥有授权权限。结果悲剧了,登录到一台服务器上发现unix_socket文件不见了。root用户无法登陆。

怎办?情急之下请出DBA用户伪造一个root@127.0.0.1,原地复活。

[plain] view plain copy

  1. <span style="font-size:18px;color:#000099;">mysql> select user,host,password from user;  
  2. +----------+-----------+-------------------------------------------+  
  3. | user     | host      | password                                  |  
  4. +----------+-----------+-------------------------------------------+  
  5. | root     | localhost | *548E9BC80642113DD04156ED194459C8EAC2A08E |  
  6. | xm_dba   | 192.168.% | *548E9BC80642113DD04156ED194459C8EAC2A08E |  
  7. | rep_user | 192.168.% | *548E9BC80642113DD04156ED194459C8EAC2A08E |  
  8. +----------+-----------+-------------------------------------------+  
  9. 3 rows in set (0.00 sec)  
  10.   
  11. mysql> exit  
  12. Bye  
  13. [root@localhost data]# mysql -uroot -p -hlocalhost -P3306   
  14. Enter password:   
  15. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  16. Your MySQL connection id is 4  
  17. Server version: 5.5.18-log Source distribution  
  18.   
  19. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.  
  20.   
  21. Oracle is a registered trademark of Oracle Corporation and/or its  
  22. affiliates. Other names may be trademarks of their respective  
  23. owners.  
  24.   
  25. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  26.   
  27. mysql> \s  
  28. --------------  
  29. mysql  Ver 14.14 Distrib 5.5.18, for Linux (x86_64) using readline 5.1  
  30.   
  31. Connection id:          4  
  32. Current database:  
  33. Current user:           root@localhost  
  34. SSL:                    Not in use  
  35. Current pager:          stdout  
  36. Using outfile:          ''  
  37. Using delimiter:        ;  
  38. Server version:         5.5.18-log Source distribution  
  39. Protocol version:       10  
  40. Connection:             Localhost via UNIX socket  
  41. Server characterset:    utf8  
  42. Db     characterset:    utf8  
  43. Client characterset:    utf8  
  44. Conn.  characterset:    utf8  
  45. UNIX socket:            /tmp/mysql3306.sock  
  46. Uptime:                 30 min 18 sec  
  47.   
  48. Threads: 3  Questions: 64  Slow queries: 2  Opens: 48  Flush tables: 1  Open tables: 41  Queries per second avg: 0.035  
  49. --------------  
  50.   
  51. mysql> exit  
  52. Bye  
  53. [root@localhost data]# ll  
  54. total 8  
  55. drwxr-xr-x. 3 root  root  4096 Jan 22 20:40 logs  
  56. drwxr-xr-x. 3 mysql mysql 4096 Jan 22 17:31 mysql  
  57. [root@localhost data]# cd /tmp/  
  58. [root@localhost tmp]# ll  
  59. total 20  
  60. srwxrwxrwx. 1 mysql mysql    0 Jan 22 20:45 mysql3306.sock  
  61. drwx------. 2 root  root  4096 Jan 22 16:30 ssh-kLGZrU1461  
  62. drwxr-xr-x. 2 root  root  4096 Jan 23  2013 vmware-config0  
  63. drwxrwxrwt. 2 root  root  4096 Jan 23  2013 VMwareDnD  
  64. drwxr-xr-x. 2 root  root  4096 Jan 23  2013 vmware-fonts0  
  65. drwx------. 2 root  root  4096 Jan 22 16:28 vmware-root  
  66. -rw-------. 1 root  root     0 Jan 22  2013 yum.log  
  67. [root@localhost tmp]# rm -f mysql3306.sock   
  68. [root@localhost tmp]# ll  
  69. total 20  
  70. drwx------. 2 root root 4096 Jan 22 16:30 ssh-kLGZrU1461  
  71. drwxr-xr-x. 2 root root 4096 Jan 23  2013 vmware-config0  
  72. drwxrwxrwt. 2 root root 4096 Jan 23  2013 VMwareDnD  
  73. drwxr-xr-x. 2 root root 4096 Jan 23  2013 vmware-fonts0  
  74. drwx------. 2 root root 4096 Jan 22 16:28 vmware-root  
  75. -rw-------. 1 root root    0 Jan 22  2013 yum.log  
  76. [root@localhost tmp]# mysql -uroot -p -hlocalhost -P3306  
  77. Enter password:   
  78. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql3306.sock' (2)  
  79. [root@localhost tmp]# mysql -uroot -p -h127.0.0.1 -P3306  
  80. Enter password:   
  81. ERROR 1130 (HY000): Host '127.0.0.1' is not allowed to connect to this MySQL server  
  82. [root@localhost tmp]# mysql -uroot -P -P3306              
  83. Unknown suffix '-' used for variable 'port' (value '-P3306')  
  84. mysql: Error while setting value '-P3306' to 'port'  
  85. [root@localhost tmp]# mysql -uroot -p -P3306  
  86. Enter password:   
  87. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql3306.sock' (2)  
  88. [root@localhost tmp]# ll  
  89. total 20  
  90. drwx------. 2 root root 4096 Jan 22 16:30 ssh-kLGZrU1461  
  91. drwxr-xr-x. 2 root root 4096 Jan 23  2013 vmware-config0  
  92. drwxrwxrwt. 2 root root 4096 Jan 23  2013 VMwareDnD  
  93. drwxr-xr-x. 2 root root 4096 Jan 23  2013 vmware-fonts0  
  94. drwx------. 2 root root 4096 Jan 22 16:28 vmware-root  
  95. -rw-------. 1 root root    0 Jan 22  2013 yum.log  
  96. [root@localhost tmp]# mysql -uxm_dba -p -h192.168.161.82 -P3306  
  97. Enter password:   
  98. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  99. Your MySQL connection id is 6  
  100. Server version: 5.5.18-log Source distribution  
  101.   
  102. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.  
  103.   
  104. Oracle is a registered trademark of Oracle Corporation and/or its  
  105. affiliates. Other names may be trademarks of their respective  
  106. owners.  
  107.   
  108. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  109.   
  110. mysql> use mysql;  
  111. Reading table information for completion of table and column names  
  112. You can turn off this feature to get a quicker startup with -A  
  113.   
  114. Database changed  
  115. mysql> select user,host,password from user;  
  116. +----------+-----------+-------------------------------------------+  
  117. | user     | host      | password                                  |  
  118. +----------+-----------+-------------------------------------------+  
  119. | root     | localhost | *548E9BC80642113DD04156ED194459C8EAC2A08E |  
  120. | xm_dba   | 192.168.% | *548E9BC80642113DD04156ED194459C8EAC2A08E |  
  121. | rep_user | 192.168.% | *548E9BC80642113DD04156ED194459C8EAC2A08E |  
  122. +----------+-----------+-------------------------------------------+  
  123. 3 rows in set (0.00 sec)  
  124.   
  125. mysql> FLUSH PRIVILEGES;  
  126. Query OK, 0 rows affected (0.00 sec)  
  127.   
  128. mysql> create table test.user(select * from mysql.user where user='root');  
  129. Query OK, 1 row affected (0.02 sec)  
  130. Records: 1  Duplicates: 0  Warnings: 0  
  131.   
  132. mysql> select * from test.user\G  
  133. *************************** 1. row ***************************  
  134.                   Host: localhost  
  135.                   User: root  
  136.               Password: *548E9BC80642113DD04156ED194459C8EAC2A08E  
  137.            Select_priv: Y  
  138.            Insert_priv: Y  
  139.            Update_priv: Y  
  140.            Delete_priv: Y  
  141.            Create_priv: Y  
  142.              Drop_priv: Y  
  143.            Reload_priv: Y  
  144.          Shutdown_priv: Y  
  145.           Process_priv: Y  
  146.              File_priv: Y  
  147.             Grant_priv: Y  
  148.        References_priv: Y  
  149.             Index_priv: Y  
  150.             Alter_priv: Y  
  151.           Show_db_priv: Y  
  152.             Super_priv: Y  
  153.  Create_tmp_table_priv: Y  
  154.       Lock_tables_priv: Y  
  155.           Execute_priv: Y  
  156.        Repl_slave_priv: Y  
  157.       Repl_client_priv: Y  
  158.       Create_view_priv: Y  
  159.         Show_view_priv: Y  
  160.    Create_routine_priv: Y  
  161.     Alter_routine_priv: Y  
  162.       Create_user_priv: Y  
  163.             Event_priv: Y  
  164.           Trigger_priv: Y  
  165. Create_tablespace_priv: Y  
  166.               ssl_type:   
  167.             ssl_cipher:   
  168.            x509_issuer:   
  169.           x509_subject:   
  170.          max_questions: 0  
  171.            max_updates: 0  
  172.        max_connections: 0  
  173.   max_user_connections: 0  
  174.                 plugin:   
  175.  authentication_string:   
  176. 1 row in set (0.00 sec)  
  177.   
  178. mysql> update test.user set host='127.0.0.1';  
  179. Query OK, 1 row affected (0.01 sec)  
  180. Rows matched: 1  Changed: 1  Warnings: 0  
  181.   
  182. mysql> insert into mysql.user select * from test.user;  
  183. Query OK, 1 row affected (0.00 sec)  
  184. Records: 1  Duplicates: 0  Warnings: 0  
  185.   
  186. mysql> select user,host,password from user;  
  187. +----------+-----------+-------------------------------------------+  
  188. | user     | host      | password                                  |  
  189. +----------+-----------+-------------------------------------------+  
  190. | root     | localhost | *548E9BC80642113DD04156ED194459C8EAC2A08E |  
  191. | root     | 127.0.0.1 | *548E9BC80642113DD04156ED194459C8EAC2A08E |  
  192. | xm_dba   | 192.168.% | *548E9BC80642113DD04156ED194459C8EAC2A08E |  
  193. | rep_user | 192.168.% | *548E9BC80642113DD04156ED194459C8EAC2A08E |  
  194. +----------+-----------+-------------------------------------------+  
  195. 4 rows in set (0.00 sec)  
  196.   
  197. mysql> FLUSH PRIVILEGES;  
  198. Query OK, 0 rows affected (0.00 sec)  
  199.   
  200. mysql> exit  
  201. Bye  
  202. [root@localhost tmp]# mysql -uroot -p -h127.0.0.1 -P3306             
  203. Enter password:   
  204. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  205. Your MySQL connection id is 7  
  206. Server version: 5.5.18-log Source distribution  
  207.   
  208. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.  
  209.   
  210. Oracle is a registered trademark of Oracle Corporation and/or its  
  211. affiliates. Other names may be trademarks of their respective  
  212. owners.  
  213.   
  214. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  215.   
  216. mysql> \s  
  217. --------------  
  218. mysql  Ver 14.14 Distrib 5.5.18, for Linux (x86_64) using readline 5.1  
  219.   
  220. Connection id:          7  
  221. Current database:  
  222. Current user:           root@127.0.0.1  
  223. SSL:                    Not in use  
  224. Current pager:          stdout  
  225. Using outfile:          ''  
  226. Using delimiter:        ;  
  227. Server version:         5.5.18-log Source distribution  
  228. Protocol version:       10  
  229. Connection:             127.0.0.1 via TCP/IP  
  230. Server characterset:    utf8  
  231. Db     characterset:    utf8  
  232. Client characterset:    utf8  
  233. Conn.  characterset:    utf8  
  234. TCP port:               3306  
  235. Uptime:                 41 min 30 sec  
  236.   
  237. Threads: 3  Questions: 106  Slow queries: 8  Opens: 50  Flush tables: 1  Open tables: 42  Queries per second avg: 0.042  
  238. --------------  
  239.   
  240. mysql> show grants for 'root'@'127.0.0.1';  
  241. +----------------------------------------------------------------------------------------------------------------------------------------+  
  242. | Grants for root@127.0.0.1                                                                                                              |  
  243. +----------------------------------------------------------------------------------------------------------------------------------------+  
  244. | GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY PASSWORD '*548E9BC80642113DD04156ED194459C8EAC2A08E' WITH GRANT OPTION |  
  245. +----------------------------------------------------------------------------------------------------------------------------------------+  
  246. 1 row in set (0.00 sec)  
  247. >mysql> show grants for 'xm_dba'@'192.168.%';  
  248. +------------------------------------------------------------------------------------------------------------------------+  
  249. | GRANT ALL PRIVILEGES ON *.* TO 'xm_dba'@'192.168.%' IDENTIFIED BY PASSWORD '*548E9BC80642113DD04156ED194459C8EAC2A08E' |  
  250. +------------------------------------------------------------------------------------------------------------------------+  
  251. 1 row in set (0.00 sec)</span>  

相关文章:

  • 欧拉计划详解第506题:钟摆序列
  • 《Python3 网络爬虫开发实战》:二、HTML消息结构
  • 调试接口小技巧-通过接口调试工具去下载上传文件
  • 【C指针详解】进阶篇
  • 惊奇发现业务移动端在往小程序化发展
  • 啸叫检测的方法:基于DSP的实现
  • java中比较两个map是否相同
  • C/C++编程工具及实用小软件推荐
  • [项目管理-15]:项目执行中的三大管理者:项目活动管理、职能部门管理、产品架构设计。
  • Code For Better 谷歌开发者之声——基于改进 EfficientDet 的电网线路的识别与检测的设计实现
  • 【for lovelier】IDEA + LeetCode Editor 最佳实践
  • React Native 0.70 版本发布,Hermes 成为默认引擎
  • 【Java基础】时间日期类之Date类、SimplDateFormat类、Calendar类及二月天案例
  • 2023计算机毕业设计SSM最新选题之javaEE的仓库管理系统93c6b
  • 编程路学习书单推荐
  • 【140天】尚学堂高淇Java300集视频精华笔记(86-87)
  • 10个确保微服务与容器安全的最佳实践
  • 78. Subsets
  • C++入门教程(10):for 语句
  • Consul Config 使用Git做版本控制的实现
  • gcc介绍及安装
  • Git学习与使用心得(1)—— 初始化
  • HTTP中GET与POST的区别 99%的错误认识
  • JavaScript工作原理(五):深入了解WebSockets,HTTP/2和SSE,以及如何选择
  • JAVA多线程机制解析-volatilesynchronized
  • Java应用性能调优
  • JSONP原理
  • Laravel Telescope:优雅的应用调试工具
  • Protobuf3语言指南
  • Shell编程
  • Webpack 4x 之路 ( 四 )
  • 官方新出的 Kotlin 扩展库 KTX,到底帮你干了什么?
  • 技术:超级实用的电脑小技巧
  • 简单数学运算程序(不定期更新)
  • 模型微调
  • 融云开发漫谈:你是否了解Go语言并发编程的第一要义?
  • 腾讯大梁:DevOps最后一棒,有效构建海量运营的持续反馈能力
  • 推荐一个React的管理后台框架
  • 想晋级高级工程师只知道表面是不够的!Git内部原理介绍
  • Redis4.x新特性 -- 萌萌的MEMORY DOCTOR
  • TPG领衔财团投资轻奢珠宝品牌APM Monaco
  • (1)Map集合 (2)异常机制 (3)File类 (4)I/O流
  • (4.10~4.16)
  • (6)STL算法之转换
  • (C语言)输入一个序列,判断是否为奇偶交叉数
  • (Java数据结构)ArrayList
  • (Redis使用系列) Springboot 实现Redis 同数据源动态切换db 八
  • (二)WCF的Binding模型
  • (转)Scala的“=”符号简介
  • (转)VC++中ondraw在什么时候调用的
  • (转)全文检索技术学习(三)——Lucene支持中文分词
  • .NET Conf 2023 回顾 – 庆祝社区、创新和 .NET 8 的发布
  • .net core 3.0 linux,.NET Core 3.0 的新增功能
  • .NET 使用 ILRepack 合并多个程序集(替代 ILMerge),避免引入额外的依赖
  • .Net 中Partitioner static与dynamic的性能对比