Code Monkey home page Code Monkey logo

本程序配置mysql地址为127,且mysql绑定到127时,本程序报2002错误,但是写个php文件测试mysql是能正常连接并查询的,或者当mysql不绑定127(即绑定到0.0.0.0时),本程序可正常使用 about tieba-cloud-sign HOT 6 CLOSED

Weltolk avatar Weltolk commented on August 18, 2024
本程序配置mysql地址为127,且mysql绑定到127时,本程序报2002错误,但是写个php文件测试mysql是能正常连接并查询的,或者当mysql不绑定127(即绑定到0.0.0.0时),本程序可正常使用

from tieba-cloud-sign.

Comments (6)

BANKA2017 avatar BANKA2017 commented on August 18, 2024

define('DB_HOST','127.0.0.7:3306');

请确定不是 127.0.0.1 或者 localhost

from tieba-cloud-sign.

Weltolk avatar Weltolk commented on August 18, 2024

define('DB_HOST','127.0.0.7:3306');

请确定不是 127.0.0.1 或者 localhost

1.127无法连,localhost可连,localhost:3306能连,可以问一下是什么原因吗?

2.另外请问如果是填ip,那么怎么配置端口呢(在示例config.php里未找到)?是'DB_PORT'吗?

3.请问config.php的全部配置项有文档或者示例吗?

from tieba-cloud-sign.

n0099 avatar n0099 commented on August 18, 2024

mysql配置文件my.cnf:
[mysqld]
performance_schema_max_table_instances=400 #影响不大
table_definition_cache=400 #最小400,对内存占用影响大
table_open_cache=500 #影响不大
secure_file_priv=NULL
bind-address=127.0.0.1
mysqlx-bind-address=127.0.0.1

根据其文档:https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html

可以存储在表定义缓存中的表定义数。如果你使用大量的表,你可以创建一个大的表定义缓存来加速表的打开。与普通的表缓存不同,表定义缓存占用更少的空间并且不使用文件描述符。最小值为 400。默认值基于以下公式,上限为 2000:
MIN(400 + table_open_cache / 2, 2000)
对于InnoDB,该 table_definition_cache 设置充当对字典对象缓存中的表实例数量和一次可以打开的每表文件表空间数量的软限制。

如果字典对象缓存中的表实例数量超过 table_definition_cache限制,LRU 机制开始将表实例标记为逐出,并最终将它们从字典对象缓存中删除。table_definition_cache由于具有外键关系的表实例未放在 LRU 列表中,因此 具有缓存元数据的打开表的数量可能高于 限制。

一次可以打开的 file-per-table 表空间的数量受 table_definition_cacheinnodb_open_files设置的限制。如果设置了两个变量,则使用最高设置。如果两个变量都没有设置 table_definition_cache ,则使用具有更高默认值的设置。如果打开的表空间的数量超过 table_definition_cacheor 定义的限制innodb_open_files,LRU 机制会在 LRU 列表中搜索已完全刷新且当前未扩展的表空间文件。每次打开新表空间时都会执行此过程。只有不活动的表空间被关闭。

表定义缓存与字典对象缓存 的表定义缓存分区并行存在 。两个缓存都存储表定义,但服务于 MySQL 服务器的不同部分。一个缓存中的对象不依赖于另一个缓存中对象的存在。有关更多信息,请参阅 第 14.4 节,“字典对象缓存”

我的评价是如果您需要节省mysql所吃的内存您不如去调整innodb_buffer_pool_sizeredologsize

from tieba-cloud-sign.

n0099 avatar n0099 commented on August 18, 2024

bind-address=127.0.0.1
mysqlx-bind-address=127.0.0.1

https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_bind_address

服务器处理不同类型的地址如下:

如果地址为*,则服务器在所有服务器主机 IPv4 接口上接受 TCP/IP 连接,如果服务器主机支持 IPv6,则在所有 IPv6 接口上接受 TCP/IP 连接。使用此地址可允许所有服务器接口上的 IPv4 和 IPv6 连接。此值为默认值。如果变量指定了多个值的列表,则不允许使用此值。

如果地址是0.0.0.0,则服务器接受所有服务器主机 IPv4 接口上的 TCP/IP 连接。如果变量指定了多个值的列表,则不允许使用此值。

如果地址是::,则服务器接受所有服务器主机 IPv4 和 IPv6 接口上的 TCP/IP 连接。如果变量指定了多个值的列表,则不允许使用此值。

如果地址是 IPv4 映射地址,则服务器接受该地址的 TCP/IP 连接,采用 IPv4 或 IPv6 格式。例如,如果服务器绑定到::ffff:127.0.0.1,客户端可以使用--host=127.0.0.1或 进行连接--host=::ffff:127.0.0.1。

如果地址是“常规” IPv4 或 IPv6 地址(例如127.0.0.1或 ::1),则服务器仅接受该 IPv4 或 IPv6 地址的 TCP/IP 连接。

https://dev.mysql.com/doc/refman/8.0/en/x-plugin-options-system-variables.html#sysvar_mysqlx_bind_address
根据 https://www.percona.com/blog/2019/01/07/understanding-mysql-x-all-flavors/ ,tc并不使用mysqlx协议来与mysql服务端通讯,因此这个变量的值与问题无关

from tieba-cloud-sign.

n0099 avatar n0099 commented on August 18, 2024

define('DB_HOST','127.0.0.7:3306');

请确定不是 127.0.0.1 或者 localhost

1.127无法连,localhost可连,localhost:3306能连,可以问一下是什么原因吗?

2.另外请问如果是填ip,那么怎么配置端口呢(在示例config.php里未找到)?是'DB_PORT'吗?

3.请问config.php的全部配置项有文档或者示例吗?

  1. 建议cat /etc/hosts看看您的localhost是不是没解析为127.0.0.1而是127.0.0.7
  2. 根据
    $m = new S(DB_HOST, DB_USER, DB_PASSWD, DB_NAME, LONGSQL); //以后直接使用$m->函数()即可操作数据库
    应该是直接写在DB_HOST里,如127.0.0.1:3306
  3. 没有

from tieba-cloud-sign.

Weltolk avatar Weltolk commented on August 18, 2024

define('DB_HOST','127.0.0.7:3306');

请确定不是 127.0.0.1 或者 localhost

1.127无法连,localhost可连,localhost:3306能连,可以问一下是什么原因吗?
2.另外请问如果是填ip,那么怎么配置端口呢(在示例config.php里未找到)?是'DB_PORT'吗?
3.请问config.php的全部配置项有文档或者示例吗?

  1. 建议cat /etc/hosts看看您的localhost是不是没解析为127.0.0.1而是127.0.0.7
  2. 根据
    $m = new S(DB_HOST, DB_USER, DB_PASSWD, DB_NAME, LONGSQL); //以后直接使用$m->函数()即可操作数据库

    应该是直接写在DB_HOST里,如127.0.0.1:3306
  3. 没有

感谢这么详细的解答,已解决

from tieba-cloud-sign.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.