更改MySQL存储过程'Database Collat​​ion'名称

时间:2023-01-16 16:39:17

I have imported a DB from Local machine to server machine. While importing the Database, the character set values of the DB are set by system default to "Latin". I have changed the character set to "utf8" for the Database. But, the stored procedure of Database collation values are not modified. Currently it is "latin1_swedish_ci". How to change the Database collation values from "latin1_swedish_ci" to "utf8_general_ci" for all the stored procedures.

我已将本地计算机中的数据库导入服务器计算机。导入数据库时​​,DB的字符集值由系统默认设置为“Latin”。我已将数据库的字符集更改为“utf8”。但是,不修改数据库排序规则值的存储过程。目前它是“latin1_swedish_ci”。如何将数据库排序规则值从“latin1_swedish_ci”更改为“utf8_general_ci”以用于所有存储过程。

SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME
FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = DB_Name;

USE DB_Name;
ALTER DATABASE DB_Name
DEFAULT CHARACTER SET = utf8
DEFAULT COLLATE=utf8_general_ci;

SET NAMES UTF8;

Thanks in advance.

提前致谢。

1 个解决方案

#1


7  

As documented under CREATE PROCEDURE and CREATE FUNCTION Syntax (emphasis added):

如CREATE PROCEDURE和CREATE FUNCTION语法中所述(强调添加):

If CHARACTER SET and COLLATE attributes are not present, the database character set and collation in effect at routine creation time are used. To avoid having the server use the database character set and collation, provide explicit CHARACTER SET and COLLATE attributes for character data parameters.

如果不存在CHARACTER SET和COLLATE属性,则使用在例程创建时生效的数据库字符集和排序规则。为避免服务器使用数据库字符集和排序规则,请为字符数据参数提供显式CHARACTER SET和COLLATE属性。

If you change the database default character set or collation, stored routines that use the database defaults must be dropped and recreated so that they use the new defaults.

如果更改数据库缺省字符集或排序规则,则必须删除并重新创建使用数据库缺省值的存储例程,以便它们使用新的缺省值。

#1


7  

As documented under CREATE PROCEDURE and CREATE FUNCTION Syntax (emphasis added):

如CREATE PROCEDURE和CREATE FUNCTION语法中所述(强调添加):

If CHARACTER SET and COLLATE attributes are not present, the database character set and collation in effect at routine creation time are used. To avoid having the server use the database character set and collation, provide explicit CHARACTER SET and COLLATE attributes for character data parameters.

如果不存在CHARACTER SET和COLLATE属性,则使用在例程创建时生效的数据库字符集和排序规则。为避免服务器使用数据库字符集和排序规则,请为字符数据参数提供显式CHARACTER SET和COLLATE属性。

If you change the database default character set or collation, stored routines that use the database defaults must be dropped and recreated so that they use the new defaults.

如果更改数据库缺省字符集或排序规则,则必须删除并重新创建使用数据库缺省值的存储例程,以便它们使用新的缺省值。