15

When creating a MySQL stored procedure how does one set the character set and collation? The MySQL documentation does not provide any examples and to the general syntax is slightly unclear.

mysql> show procedure status\G

*************************** 1. row ***************************
                  Db: MslLandingSequence
                Name: DeploySkycrane
                Type: PROCEDURE
             Definer: curiosity@localhost
            Modified: 2012-08-04 00:05:16
             Created: 2011-11-12 00:02:45
       Security_type: DEFINER
             Comment: 
character_set_client: latin1
collation_connection: latin1_swedish_ci
  Database Collation: latin1_swedish_ci

The last three items should be Unicode. Thanks.

4
  • Not a duplicate question per se, but probably the same problem: stackoverflow.com/questions/4375957/… Aug 28, 2013 at 13:46
  • @StephenO'Flynn: Thanks. It is not quite the same problem, but some information in the links from that page are relevant. Thank you.
    – dotancohen
    Aug 28, 2013 at 14:04
  • Stephen: Pretty unrelated stuff actually. dotancoh: uhm, got answers :) ?
    – kellogs
    Oct 15, 2013 at 13:13
  • I wish that I did have an answer. I don't!
    – dotancohen
    Oct 15, 2013 at 13:25

2 Answers 2

20

character_set_client is the session value of the character_set_client system variable when the routine was created. collation_connection is the session value of the collation_connection system variable when the routine was created. Database Collation is the collation of the database with which the routine is associated. These columns were added in MySQL 5.1.21.

http://dev.mysql.com/doc/refman/5.1/en/show-procedure-status.html

In short, open a mysql command line, type in

SET NAMES UTF8;

then drop and reimport the stored procedures. This fixed my problem. I don't even want to think about pre 5.1.21 users. They are fumbling in the dark!

3
  • 3
    Thank you! SET NAMES utf8 does in fact affect character_set_client and collation_connection, but not Database Collation. I suspect that the last one must be set, as the name implies, when creating the database and might not actually be a property of the Stored Procedure itself. Nice find!
    – dotancohen
    Oct 15, 2013 at 16:55
  • take note: UTF8 does not work. it works for me when I set to lowercase. SET NAMES utf8;
    – StanLe3
    Jun 28, 2018 at 9:03
  • 1
    SET NAMES utf8mb4; worked for me (Wanted to use Smileys) Feb 12, 2020 at 14:42
4

Pay attention to the bug report. It shows that procedure and its parameters are not associated with default character set of the database, but always with Binary String.

So you have to explicitly specify Character set attribute for parameters.

Simple recreate procedure might not solve the problem.

1
  • 1
    I spent all the night to find out the solution of «Incorrect string value: '\xD0\x9C\xD0\xB0\xD0\xBA...' for column 'p_name' at row 1» error. And only thanks to your question I found that MySQL bug :) So, thank you Apr 30, 2015 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.