Altering Mysql Table column to be case sensitive

后端 未结 4 2055
轮回少年
轮回少年 2020-12-08 01:10

I have a table in my Mysql database, which is used for authentication. And now, I need to make the authentication case sensitive. Googling around, I have realized Mysql col

相关标签:
4条回答
  • 2020-12-08 01:36

    Please see http://dev.mysql.com/doc/refman/5.0/en/charset-conversion.html

    Example:

    ALTER TABLE some_table MODIFY some_column BLOB;
    ALTER TABLE some_table MODIFY some_column VARCHAR(50) BINARY;
    

    The first line converts to a binary data type (attempt to minimize character loss) and the second converts back to the VARCHAR type with BINARY collation.

    It may actually be preferable to store as one of the binary types (BLOB, BINARY, or VARBINARY) rather than simply collating BINARY. I would suggest you compare a bit, your mileage may vary depending on your actual data and the queries you need to run.

    0 讨论(0)
  • 2020-12-08 01:41

    Rather than altering your table, you can still perform case sensitive queries on your table when authenticating, use the BINARY option as follows:

    SELECT BINARY * FROM USERS where USER_ID = 2 AND USER_NAME = 'someone' LIMIT 1;
    

    Does this help?

    0 讨论(0)
  • 2020-12-08 01:47

    You should be able to do something like this:

    Edit: Misread what you intended to do:

        ALTER TABLE USERS MODIFY
            USER_NAME VARCHAR(50)
              CHARACTER SET binary;
    
    0 讨论(0)
  • 2020-12-08 01:50
    ALTER TABLE USERS CHANGE USER_NAME USER_NAME VARCHAR(50) BINARY NOT NULL;
    
    0 讨论(0)
提交回复
热议问题