Introduction
A few days ago, I saw Teacher Ye using <span>sed</span>
to modify the mysqld version number, which I thought was very impressive.
However, since this involves restarting the database, many environments may not allow a restart. So what should we do?
Approach
Previously, when we compiled mysqld, we demonstrated how to modify the version number, but it was too complicated and unrealistic for systems that are already online. Directly using sed to modify the version number in the disk file is easier, but it requires restarting the database. If we don’t want to restart the database, we can only modify the version information in memory.
GDB is perfect for modifying parameter variables in memory. This means we just need to find the corresponding variable and then use gdb to modify the value in memory.
Since we are only modifying the value in memory, we still need to change it again on the next restart; otherwise, it will revert back.
So how do we find the relevant variables? We can still use a simple and universal method. Just print all variables and then use <span>grep version</span>
to find it.
Method
For example, we can directly use the following command to save all variables to a file:
echo 'info variables'|gdb -p `pidof mysqld` > /tmp/mysql_variables_t20250113.txt
Then we search for the <span>version</span>
keyword to find the following information:
<data variable, no debug info> server_version;
This (server_version) seems to be the MySQL version value. We just need to modify this value.
During testing, I found that there are differences in this value between versions 5.7 and 8.0, so I will demonstrate them separately.
5.7 Environment
First, let’s check the current value:
gdb -p `pidof mysqld` --batch --ex 'print server_version'
It turns out to be a string format, which makes it very easy to modify.
For example, we can modify it to a very large version:
gdb -p `pidof mysqld` --batch --ex 'print server_version' --ex 'set server_version="5.7.66-log"'
Then log into the database to check the version information, and find that it has indeed been modified successfully. (No more worries about annoying scans)
8.0 Environment
In the 8.0 environment, the server_version value is an integer.
Testing shows that the relationship between the 8.0 version number and server_version is:
server_version = 774909488 + major_version
This means that this value can only modify the major version number. For example, we can change 8.0.28 to 9.0.28 by executing the following command:
gdb -p `pidof mysqld` --batch --ex 'print server_version' --ex 'set server_version=774909488+9'

I haven’t yet found which parameter corresponds to the minor version, so if anyone is interested, you can try it yourself (it is recommended to verify in your own test environment, as modifying some variables may cause the database to crash, and some parameters may even corrupt ibdata1.)
Conclusion
There are always countermeasures against policies.
Before modifying any information, be sure to confirm and verify carefully. It is best to back up. If a backup is not possible, it is best to have multiple people review it before proceeding. (For example, in operations like this tutorial that modify memory, there is no way to back up, so we can only be more careful when reviewing.)