JIYIK CN >

Current Location:Home > Learning > DATABASE > MySQL >

Changing max_allowed_packet Size in MySQL Server

Author:JIYIK Last Updated:2025/04/22 Views:

This article explains how to change the max_allowed_packet size in MySQL server. To understand this, we will use two operating systems, Windows 10 and Linux (Ubuntu).


Changing max_allowed_packet Size in MySQL Server

If we try to upload a file larger than the default value of max_allowed_packet, we will receive an error message stating that packets larger than max_allowed_packet are not allowed.

To get rid of this error, we need to change the size of max_allowed_packet. But before that, let's check its default value as shown below.

mysql> SHOW VARIABLES LIKE 'max_allowed_packet';

Output:

+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+--------------------+---------+
1 row in set (0.06 sec)

Now, the max_allowed_packet size is 4MB, which is equal to 4194304 bytes. Considering the MySQL documentation, the MySQL client and server have their own max_allowed_packet size.

We saw the value above using SHOW VARIABLES LIKE 'max_allowed_packet'; query is the value on the MySQL Server side. If we want to handle larger packets, it is necessary to increase the max_allowed_packet value.

Let's say we want to change it to 50MB. We can do this by updating the configuration files on the server side (the section of the my.ini file named [mysqld]) and the client side (the section of the my.ini file named [mysql] or [client]).

If we have the SUPER privilege (permission), we can also change this using SQL queries. How? Let's look at the two solutions below.


Changing the max_allowed_packet size in MySQL server using Windows operating system

  1. Open a Windows command line and browse to the installation path. If you did not change the default location, MySQL Server is installed at C:\Program Files\MySQL\MySQL Server 8.0.
  2. Go to the bin folder using cd bin.
  3. Type mysql -u root -p password to log in to the MySQL server. We are logging in as the root user; you can use your username and password.
  4. Once inside, execute the following query to change the max_allowed_packet size in MySQL server.
    mysql> SET GLOBAL max_allowed_packet=52428800;
    
  5. Execute the following query again to confirm the changes.
    mysql> SHOW VARIABLES LIKE 'max_allowed_packet';
    
    Output:
    +--------------------+---------+
    | Variable_name      | Value   |
    +--------------------+---------+
    | max_allowed_packet | 52428800|
    +--------------------+---------+
    1 row in set (0.00 sec)
    

If you have installed MySQL server in the default location, the solution given below is to use the configuration file located in the default path. The configuration file path is C:\ProgramData\MySQL\MySQL Server 8.0\my.ini.

  1. Open the my.ini file.
  2. Search for the [mysqld] section and add the following line under this section.
    max_allowed_packet=50M
    
  3. Save and close the file.
  4. Restart the MySQL server to see the changes.

Changing max_allowed_packet size in MySQL server using Ubuntu OS

Once inside the MySQL server, we can use the same queries on Ubuntu as we do on Windows OS. The steps are as follows.

  1. Open the Ubuntu terminal and log in as superuser using sudo su.
  2. Also, log in to the MySQL server.
  3. It is always a good idea to check the default or previous value of a variable before making any changes. To do this, we can use the following query.
    mysql> SHOW VARIABLES LIKE 'max_allowed_packet';
    
    Output:
    +--------------------+---------+
    | Variable_name      | Value   |
    +--------------------+---------+
    | max_allowed_packet | 67108864|
    +--------------------+---------+
    1 row in set (0.00 sec)
    

    Execute the following query to update the value of max_allowed_packet to 70MB, which is 73400320 bytes.

    mysql> SET GLOBAL max_allowed_packet=73400320;
    
  4. We can run the SHOW VARIABLES LIKE 'max_allowed_packet'; query to confirm that the change occurred.

If you are someone who is very good at editing configuration files, then the following solution is especially for you.

  1. Open the configuration file located in the /etc/mysql/mysql.conf.d/mysqld.cnf path.
    $ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
    
  2. Under the section named [mysqld] search for max_allowed_packet and change its value to your choice. If it does not exist, add the following line under [mysqld].

    Remember, we are changing it to 70M. However, you can write down your phone number.

    max_allowed_packet=70M
    
  3. Save and exit the file.
  4. Restart MySQL Server using systemctl restart mysql and execute the following command to ensure the update.
    mysql> SHOW VARIABLES LIKE 'max_allowed_packet';
    
    Output:
    +--------------------+---------+
    | Variable_name      | Value   |
    +--------------------+---------+
    | max_allowed_packet | 73400320|
    +--------------------+---------+
    1 row in set (0.03 sec)
    

Previous:Installing MySQL Client in Linux

Next: None

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Installing MySQL Client in Linux

Publish Date:2025/04/22 Views:186 Category:MySQL

MySQL is an abbreviation for Structured Query Language which is a relational database management system. It is an open source database which is freely available and used for both large and small applications. The use cases are in school app

Subtraction in MySQL

Publish Date:2025/04/21 Views:140 Category:MySQL

MINUS Operator is used in SQL to find unique elements in table A that are not present in table B. Through this tutorial, we will see how to emulate the operator in MySQL MINUS to get the desired result. We will understand it by using NOT IN

INTERSECT Operator in MySQL

Publish Date:2025/04/21 Views:99 Category:MySQL

This article will help you understand INTERSECT the operator. Although MySQL does not support INTERSECT and MINUS / EXCEPT , there are other ways to simulate this functionality. We will see INTERSECT what is , its benefits, and learn variou

Deleting using Join in MySQL

Publish Date:2025/04/21 Views:158 Category:MySQL

This tutorial article will show you how to use MySQL JOIN methods to delete data from multiple tables. This is useful when you are simultaneously deleting records from one table that are related to a specific record in another table. DELETE

MySQL using LIKE in case insensitive search

Publish Date:2025/04/21 Views:131 Category:MySQL

This tutorial article will show you how to use LIKE the operator to search a column. We will show you how to use it correctly to include all results that meet certain criteria, regardless of whether the value is uppercase or lowercase. LIKE

Loop PHP MySQLi Get Array Function

Publish Date:2025/04/21 Views:105 Category:MySQL

MySQLi fetch function is used to access data from the database server. After fetching the data, you can also iterate over it MySQLi with queries. In this article, we will see mysqli_fetch_array() the use of functions and methods to iterate

Generate a random and unique string in MySQL

Publish Date:2025/04/21 Views:78 Category:MySQL

Today, we will learn to use various functions in MySQL to generate random and unique strings. These functions include MD5() , RAND() , , SUBSTR() and UUID() . There is no inbuilt method to generate random string in MySQL, but there are many

Changing MySQL root password on Mac

Publish Date:2025/04/21 Views:161 Category:MySQL

This article teaches you how to change the MySQL user password on OS X. root We will be using XAMPP so that you can change the password using the MySQL console. Installing XAMPP for OSX First, download and install XAMPP for OSX from Apache

Using CURRENT_TIMESTAMP as a default value in MySQL

Publish Date:2025/04/21 Views:196 Category:MySQL

This article teaches you how to use as 5.6.5 in MySQL versions lower than . Thus, you can prevent MySQL error 1293. CURRENT_TIMESTAMP DEFAULT Our approach involves reordering table columns and using DEFAULT 0 and time values. Reproduce the

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial