简体   繁体   中英

MySQL case sensitive insert

I have created a database with case sensitive character set:

Create database Grupo88 character set utf8 collate utf8_bin;

CREATE TABLE Grupo88.Usuarios(
    nombreUsuario varchar(30) primary key,
    clave varchar(120) not null);

INSERT INTO usuarios(nombreUsuario,clave)
       VALUES('guy','pass');
INSERT INTO usuario(nombreUsuario, clave)
       VALUES('Guy', 'password');

The first insert goes well, but the second one says that the value "Guy" already exists. Setting my database to be case sensitive is not enough? How can I do to allow case sensitive inserts?

EDIT: Apparently the problem was in the stored procedure that was inserting into the table 'usuarios'. Scripts posted here work perfectly

Try using the binary keyword when you create the table:

CREATE TABLE Grupo88.Usuarios (
    nombreUsuario varchar(30) binary primary key,
    clave varchar(120) not null
);

Here is a SQL Fiddle.

use BINARY in creating the table

mysql>     CREATE TABLE Grupo88.Usuarios
    ->     (
    ->         nombreUsuario varchar(30) BINARY,
    ->         clave varchar(120) not null);
    ->     );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM