免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: bill01
打印 上一主题 下一主题

【已解决】Can't connect to local MySQL server through socket '3306' [复制链接]

论坛徽章:
154
2022北京冬奥会纪念版徽章
日期:2015-08-07 17:10:5720周年集字徽章-年
日期:2022-10-26 16:44:2015-16赛季CBA联赛之深圳
日期:2022-11-02 14:02:4515-16赛季CBA联赛之八一
日期:2022-11-28 12:07:4820周年集字徽章-20	
日期:2023-07-19 08:49:4515-16赛季CBA联赛之八一
日期:2023-11-04 19:23:5115-16赛季CBA联赛之广夏
日期:2023-12-13 18:09:34
11 [报告]
发表于 2010-07-15 11:18 |只看该作者
[root@host]# mysql -u root -p -h 127.0.0.1
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 691
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.


--
这个日志不是正常的么

论坛徽章:
154
2022北京冬奥会纪念版徽章
日期:2015-08-07 17:10:5720周年集字徽章-年
日期:2022-10-26 16:44:2015-16赛季CBA联赛之深圳
日期:2022-11-02 14:02:4515-16赛季CBA联赛之八一
日期:2022-11-28 12:07:4820周年集字徽章-20	
日期:2023-07-19 08:49:4515-16赛季CBA联赛之八一
日期:2023-11-04 19:23:5115-16赛季CBA联赛之广夏
日期:2023-12-13 18:09:34
12 [报告]
发表于 2010-07-15 11:19 |只看该作者
我看你修改了主机名成host了,,
我头也被大了

论坛徽章:
0
13 [报告]
发表于 2010-07-15 11:32 |只看该作者
我看你修改了主机名成host了,,
我头也被大了
shang2010 发表于 2010-07-15 11:19



    不是 那个 主机名 不是这个 是我复制到cu的时候改的  

论坛徽章:
0
14 [报告]
发表于 2010-07-15 11:32 |只看该作者
看下hosts文件吧

论坛徽章:
0
15 [报告]
发表于 2010-07-15 11:32 |只看该作者
回复 11# shang2010


    我想知道的是 为啥 直接 mysql -u root -p
或者mysql -u root -p -h localhost
不行呢

论坛徽章:
0
16 [报告]
发表于 2010-07-15 11:33 |只看该作者
mysql对于localhost 和 127.0.0.1的处理方式是不一样的!
使用localhost的话 会采用unix socket去连接 而不是我们所期望的tcp/ip

unix socket是同一台机器上不同进程间的通信机制
而ip socket是网络上不同主机之间进程的通讯机制

论坛徽章:
0
17 [报告]
发表于 2010-07-15 11:34 |只看该作者
回复 14# xiao7ng
  1. less /etc/hosts
  2. # Do not remove the following line, or various programs
  3. # that require network functionality will fail.
  4. 127.0.0.1              host180 localhost.localdomain localhost
  5. ::1             localhost6.localdomain6 localhost6
复制代码

论坛徽章:
0
18 [报告]
发表于 2010-07-15 11:36 |只看该作者
mysql对于localhost 和 127.0.0.1的处理方式是不一样的!
使用localhost的话 会采用unix socket去连接 而不 ...
ubuntuer 发表于 2010-07-15 11:33



    那请问这位该咋样才能两种方式都可以连接呢
另外不解的是
在PHP程序中用localhost是正常的

论坛徽章:
8
综合交流区版块每周发帖之星
日期:2015-12-02 15:03:53数据库技术版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-09-14 06:20:00金牛座
日期:2014-10-10 11:23:34CU十二周年纪念徽章
日期:2013-10-24 15:41:34酉鸡
日期:2013-10-19 10:17:1315-16赛季CBA联赛之北京
日期:2017-03-06 15:12:44
19 [报告]
发表于 2010-07-15 12:29 |只看该作者
配置文件中有socket指定路径么?

论坛徽章:
0
20 [报告]
发表于 2010-07-15 12:38 |只看该作者
  1. # Example MySQL config file for large systems.
  2. #
  3. # This is for a large system with memory = 512M where the system runs mainly
  4. # MySQL.
  5. #
  6. # You can copy this file to
  7. # /etc/my.cnf to set global options,
  8. # mysql-data-dir/my.cnf to set server-specific options (in this
  9. # installation this directory is /var/lib/mysql) or
  10. # ~/.my.cnf to set user-specific options.
  11. #
  12. # In this file, you can use all long options that a program supports.
  13. # If you want to know which options a program supports, run the program
  14. # with the "--help" option.

  15. # The following options will be passed to all MySQL clients
  16. [client]
  17. #password       = your_password
  18. port            = 3306
  19. socket          = /var/lib/mysql/mysql.sock

  20. # Here follows entries for some specific programs

  21. # The MySQL server
  22. [mysqld]
  23. port            = 3306
  24. socket          = /var/lib/mysql/mysql.sock
  25. skip-locking
  26. key_buffer = 256M
  27. max_allowed_packet = 1M
  28. table_cache = 256
  29. sort_buffer_size = 1M
  30. read_buffer_size = 1M
  31. read_rnd_buffer_size = 4M
  32. myisam_sort_buffer_size = 64M
  33. thread_cache_size = 8
  34. query_cache_size= 16M
  35. # Try number of CPU's*2 for thread_concurrency
  36. thread_concurrency = 8

  37. # Don't listen on a TCP/IP port at all. This can be a security enhancement,
  38. # if all processes that need to connect to mysqld run on the same host.
  39. # All interaction with mysqld must be made via Unix sockets or named pipes.
  40. # Note that using this option without enabling named pipes on Windows
  41. # (via the "enable-named-pipe" option) will render mysqld useless!
  42. #
  43. #skip-networking

  44. # Disable Federated by default
  45. skip-federated

  46. # Replication Master Server (default)
  47. # binary logging is required for replication
  48. log-bin=mysql-bin

  49. # required unique id between 1 and 2^32 - 1
  50. # defaults to 1 if master-host is not set
  51. # but will not function as a master if omitted
  52. server-id       = 1

  53. # Replication Slave (comment out master section to use this)
  54. #
  55. # To configure this host as a replication slave, you can choose between
  56. # two methods :
  57. #
  58. # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
  59. #    the syntax is:
  60. #
  61. #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
  62. #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
  63. #
  64. #    where you replace <host>, <user>, <password> by quoted strings and
  65. #    <port> by the master's port number (3306 by default).
  66. #
  67. #    Example:
  68. #
  69. #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
  70. #    MASTER_USER='joe', MASTER_PASSWORD='secret';
  71. #
  72. # OR
  73. #
  74. # 2) Set the variables below. However, in case you choose this method, then
  75. #    start replication for the first time (even unsuccessfully, for example
  76. #    if you mistyped the password in master-password and the slave fails to
  77. #    connect), the slave will create a master.info file, and any later
  78. #    change in this file to the variables' values below will be ignored and
  79. #    overridden by the content of the master.info file, unless you shutdown
  80. #    the slave server, delete master.info and restart the slaver server.
  81. #    For that reason, you may want to leave the lines below untouched
  82. #    (commented) and instead use CHANGE MASTER TO (see above)
  83. #
  84. # required unique id between 2 and 2^32 - 1
  85. # (and different from the master)
  86. # defaults to 2 if master-host is set
  87. # but will not function as a slave if omitted
  88. #server-id       = 2
  89. #
  90. # The replication master for this slave - required
  91. #master-host     =   <hostname>
  92. #
  93. # The username the slave will use for authentication when connecting
  94. # to the master - required
  95. #master-user     =   <username>
  96. #
  97. # The password the slave will authenticate with when connecting to
  98. # the master - required
  99. #master-password =   <password>
  100. #
  101. # The port the master is listening on.
  102. # optional - defaults to 3306
  103. #master-port     =  <port>
  104. #
  105. # binary logging - not required for slaves, but recommended
  106. #log-bin=mysql-bin

  107. # Point the following paths to different dedicated disks
  108. #tmpdir         = /tmp/         
  109. #log-update     = /path-to-dedicated-directory/hostname

  110. # Uncomment the following if you are using BDB tables
  111. #bdb_cache_size = 64M
  112. #bdb_max_lock = 100000

  113. # Uncomment the following if you are using InnoDB tables
  114. #innodb_data_home_dir = /var/lib/mysql/
  115. #innodb_data_file_path = ibdata1:10M:autoextend
  116. #innodb_log_group_home_dir = /var/lib/mysql/
  117. #innodb_log_arch_dir = /var/lib/mysql/
  118. # You can set .._buffer_pool_size up to 50 - 80 %
  119. # of RAM but beware of setting memory usage too high
  120. #innodb_buffer_pool_size = 256M
  121. #innodb_additional_mem_pool_size = 20M
  122. # Set .._log_file_size to 25 % of buffer pool size
  123. #innodb_log_file_size = 64M
  124. #innodb_log_buffer_size = 8M
  125. #innodb_flush_log_at_trx_commit = 1
  126. #innodb_lock_wait_timeout = 50

  127. [mysqldump]
  128. quick
  129. max_allowed_packet = 16M

  130. [mysql]
  131. no-auto-rehash
  132. # Remove the next comment character if you are not familiar with SQL
  133. #safe-updates

  134. [isamchk]
  135. key_buffer = 128M
  136. sort_buffer_size = 128M
  137. read_buffer = 2M
  138. write_buffer = 2M

  139. [myisamchk]
  140. key_buffer = 128M
  141. sort_buffer_size = 128M
  142. read_buffer = 2M
  143. write_buffer = 2M

  144. [mysqlhotcopy]
  145. interactive-timeout
复制代码
这是配置文件
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP