Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8668559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:14:37+00:00 2026-06-12T18:14:37+00:00

I have a column which is primary key for my table, which can have

  • 0

I have a column which is primary key for my table, which can have diacritic or normal text.

I have these 2 values:

Håbo and Habo

I want to insert these two column values in my table, but i am getting error:

DBD::mysql::st execute failed: Duplicate entry 'Habo' for key 'PRIMARY'

As i check Håbo is already inserted and it is treating both values same so primary key violation.

My code:

$dbh = DBI->connect($dsn, $user, $pass)
            or die "Unable to connect: $DBI::errstr\n";
$dbh->{'mysql_enable_utf8'}=1;
$dbh->do('SET NAMES utf8');
my $sql = sprintf "INSERT INTO search_term values(%s, %s)", $dbh->quote($search_term), "Data";

My table description

mysql> desc search_term;
+---------------+--------------+------+-----+---------+-------+
| Field         | Type         | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| search        | varchar(200) | NO   | PRI | NULL    |       |
| site          | varchar(500) | NO   |     | NULL    |       |
+---------------+--------------+------+-----+---------+-------+

How can i make MySQL treat both values as different and insert them?
Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:14:38+00:00Added an answer on June 12, 2026 at 6:14 pm

    By default, MySQL “helpfully” converts Unicode into their “equivalent” ASCII using something called Unicode Collation. Like a lot of “convenience” features in MySQL, this would be much handier if it told you. I cannot put enough “quotes” around those “words”.

    Fortunately the fix is pretty simple, but non obvious. First, change the character set of your tables to UTF8 so text is stored in utf8. Then change the collation to utf8_bin so comparisons will be done exactly. I’m not 100% sure utf8_bin is 100% the right thing, but it works.

    ALTER TABLE search_term CONVERT TO CHARACTER SET utf8;
    ALTER TABLE search_term COLLATE utf8_bin;
    

    In the future, when you create tables in MySQL, be sure to append CHARACTER SET utf8 to the creation.

    CREATE TABLE search_term (
        search varchar(200) primary key,
        site varchar(500)
    )
    CHARACTER SET utf8
    COLLATE       utf8_bin;
    

    Finally, so you don’t have to do this for every table, you can create the database with these defaults already in place.

    Here’s a good post on the Unicode gotchas in MySQL and their fixes.

    On the Perl side, be sure to use utf8 so the strings you’re passing to MySQL are encoded utf8.

    Finally, according to the DBD::mysql manual, you need to turn on UTF8 support when you connect, not after. Would be nice if it issued a warning.

    Additionally, turning on this flag tells MySQL that incoming data should be
    treated as UTF-8. This will only take effect if used as part of the call to
    connect(). If you turn the flag on after connecting, you will need to issue
    the command SET NAMES utf8 to get the same effect.
    

    Change your connect to this.

    # I threw in RaiseError because its generally a good idea.
    my $dbh = DBI->connect($dsn, $user, $pass, { mysql_enable_utf8 => 1, RaiseError => 1 });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table Administrator with only one column, adminId which is the primary-key.
I have a table which has the below columns. Ticket_id (Primary key, Int) Attachment1
I have a property column which can have a subset of the following values
How can I find all column values in a column which have trailing spaces?
I have a table GB_Assignor_Assignee. I have a primary key which includes this combination(StateCode,
I have two data tables which have a primary key column in common but
I have an SQL table with basically the following structure: PK (int, primary key),
I have a table where I haven't explicitly defined a primary key, it's not
I want to have a unique constraint on a column which I am going
I have a datagridview in which the first column is a Foreign Key and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.