Tamanho da sentença(SQL) no MySQL

Forum sobre SQL.

Moderador: Moderadores

Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Tamanho da sentença(SQL) no MySQL

Mensagem por Itamar M. Lins Jr. »

Olá!
Qual é o tamanho máximo da STRING->sentença em Mysql ?

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Tamanho da sentença(SQL) no MySQL

Mensagem por JoséQuintas »

max_allowed_packed

O default começou em 4MB, mas em versões mais novas pode ser 16MB.
Pode ser aumentado até 2GB se não me engano.

Isso também afeta o limite pra salvar binários, imagens, etc.

Por exemplo: salvo o EXE em base64.
insert into .... value 'xxxxx'
Se o default for 4MB, não vou poder salvar EXE com mais de 3MB (base64 fica maior)
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Tamanho da sentença(SQL) no MySQL

Mensagem por JoséQuintas »

Uso isto

Código: Selecionar todos

      BEGIN SEQUENCE WITH __BreakBlock()
         :Execute( "SELECT @@global.max_allowed_packet AS QTD" )
         IF :Number( "QTD" ) < 16000000
            Errorsys_WriteErrorLog( ;
               "Max Allowed Packet=" + NumberSQL( :Number( "QTD" ) ) + hb_Eol() + ;
               "Alterar seção [mysqld] em my.ini no servidor" + hb_Eol() + ;
               "max_allowed_packet=32M", 2 )
            cnSQL:Execute( "SET @@global.max_allowed_packet=" + NumberSQL( 16 * 1024 * 1024 ) )
         ENDIF
      ENDSEQUENCE
O novo valor fica até que o servidor seja reiniciado.
Aí coloquei pra registrar como erro, pra me lembrar aonde preciso mexer em servidor.
VALE PRA TODOS OS TERMINAIS, não apenas aonde foi executado o comando.
Dá pra ir quebrando o galho assim.
No máximo vai ser uma vez por dia, aonde desliga servidor.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
alxsts
Colaborador
Colaborador
Mensagens: 3092
Registrado em: 12 Ago 2008 15:50
Localização: São Paulo-SP-Brasil

Tamanho da sentença(SQL) no MySQL

Mensagem por alxsts »

Olá!
MySQL 8.4 Reference Manual / ... / Packet Too Large

B.3.2.8 Packet Too Large

A communication packet is a single SQL statement sent to the MySQL server, a single row that is sent to the client, or a binary log event sent from a replication source server to a replica.

The largest possible packet that can be transmitted to or from a MySQL 8.4 server or client is 1GB.

When a MySQL client or the mysqld server receives a packet bigger than max_allowed_packet bytes, it issues an ER_NET_PACKET_TOO_LARGE error and closes the connection. With some clients, you may also get a Lost connection to MySQL server during query error if the communication packet is too large.

Both the client and the server have their own max_allowed_packet variable, so if you want to handle big packets, you must increase this variable both in the client and in the server.

If you are using the mysql client program, its default max_allowed_packet variable is 16MB. To set a larger value, start mysql like this:

Código: Selecionar todos

$> mysql --max_allowed_packet=32M
That sets the packet size to 32MB.

The server's default max_allowed_packet value is 64MB. You can increase this if the server needs to handle big queries (for example, if you are working with big BLOB columns). For example, to set the variable to 128MB, start the server like this:

Código: Selecionar todos

$> mysqld --max_allowed_packet=128M
You can also use an option file to set max_allowed_packet. For example, to set the size for the server to 128MB, add the following lines in an option file:

Código: Selecionar todos

[mysqld]
max_allowed_packet=128M
It is safe to increase the value of this variable because the extra memory is allocated only when needed. For example, mysqld allocates more memory only when you issue a long query or when mysqld must return a large result row. The small default value of the variable is a precaution to catch incorrect packets between the client and server and also to ensure that you do not run out of memory by using large packets accidentally.

You can also get strange problems with large packets if you are using large BLOB values but have not given mysqld access to enough memory to handle the query. If you suspect this is the case, try adding ulimit -d 256000 to the beginning of the mysqld_safe script and restarting mysqld.
https://dev.mysql.com/doc/refman/8.4/en/packet-too-large.html
[]´s
Alexandre Santos (AlxSts)
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Tamanho da sentença(SQL) no MySQL

Mensagem por Itamar M. Lins Jr. »

Olá!
Em SQLMIX.
Captura de tela 2025-03-07 100707.png
Captura de tela 2025-03-07 100707.png (10.33 KiB) Exibido 2427 vezes

Código: Selecionar todos

dbUseArea( , , "SELECT @@global.max_allowed_packet AS nMA",'ma' ) 
hwg_msginfo('Max_allowed_packet: ' + hb_ntos(nMA))
FechaDb('ma')
Lembrando que nMA é um field do DBF VIRTUAL. Fechou o DBF, a variável->(virtual do virtual rsrs) deixa de existir.
Tive que subir para 20MB por conta do wordpress.(penso que é isso), fiz para o outro programador, front-end(php).

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Responder