The essence of the problem was that MyISAM tables have this ability and not for innoDB.
There is a table
How to make so that when you insert into a table the values of the user_id, the value for message_id is generated
Should be something like this
Made a trigger before insert which sets the value of the message_id as maximally id + 1,
everything works as it should, but after the insertion I do not know what message_id recorded the trigger.
The option of calculating the message_id and then insert (in two queries) is not suitable.