Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a stored procedure: setting the character set and collation

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.

like image 500
dotancohen Avatar asked Aug 12 '12 06:08

dotancohen


People also ask

What is character set and collation?

A character set is a set of symbols and encodings. A collation is a set of rules for comparing characters in a character set.

How do you set collation when creating a table?

You can set the collation by adding the T-SQL COLLATE clause to the CREATE TABLE and ALTER TABLE statements. When you use those statements, you define the column and its properties, including any collation settings.

What is character set in MySQL?

The default MySQL server character set and collation are utf8mb4 and utf8mb4_0900_ai_ci , but you can specify character sets at the server, database, table, column, and string literal levels.


2 Answers

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!

like image 77
kellogs Avatar answered Oct 16 '22 19:10

kellogs


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.

like image 4
Naeel Maqsudov Avatar answered Oct 16 '22 21:10

Naeel Maqsudov