Illegal mix of collations mysql error?

2019-09-16 18:43发布

问题:

I am using geoloaction to find the current location of user which returns the xml data

<geonames>
    <geoname>
        <toponymName>Gulbahar</toponymName>
        <name>Golīmar</name>
        <lat>24.8922</lat>
        <lng>67.0287</lng>
        <geonameId>1346867</geonameId>
        <countryCode>PK</countryCode>
        <countryName>Pakistan</countryName>
        <fcl>P</fcl>
        <fcode>PPLX</fcode>
        <distance>0.14608</distance>
    </geoname>
</geonames>

now i want <name>Golīmar</name> which has a special character and on the basis of that name i have to run the query to fetch more results except this one but it generates some sort of collation errors

SELECT DISTINCT country
FROM   propertydetails
WHERE  country NOT IN ( "Golīmar" )

Error:Illegal mix of collations (latin1_swedish_ci,IMPLICIT) AND (utf8_general_ci,COERCIBLE) FOR operation

i have seen many stack pos but couldnt find a way to resolve

回答1:

Your table collation and your connection collation don't match closely enough to make the query work. Make sure that they are both the same, preferably utf8_general_ci.



回答2:

I have solved my above problem by

SELECT DISTINCT country
FROM   propertydetails
WHERE  country NOT IN ( _latin1 "Golīmar" )

and the charset and collations of both connection and table to latin1 , latin1_swedish_ci