Migrating from MySQL to TiDB: Handling MySQL Database Names with Hyphens

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 从mysql迁移到tidb,mysql库的名称带中划线

| username: TiDBer_FMWXa7ja

【TiDB Usage Environment】Poc
【TiDB Version】
【Reproduction Path】
【Encountered Problem: Problem Phenomenon and Impact】Task configuration item - db-name: “analysis-service”, the status is running when queried through query-status, but the analysis-service database is not created in the target TiDB.
【Resource Configuration】
【Attachments: Screenshots/Logs/Monitoring】

| username: db_user | Original post link

Are you referring to using DM for migration? Please send the migration configuration file.

| username: TiDBer_FMWXa7ja | Original post link

name: testdm9
task-mode: all

target-database:
host: “192.168.84.3”
port: 4000
user: “root”
password: “”

mysql-instances:

  • source-id: “mysql-01”
    block-allow-list: “ba-rule9”

block-allow-list:
ba-rule9:
do-tables:
- db-name: “analysis_service
tbl-name: “g_station”

| username: 裤衩儿飞上天 | Original post link

In the configuration file, it is an underscore.

| username: db_user | Original post link

The db-name you configured has underscores, so it definitely didn’t sync. If you want to create a database with underscores in TiDB, you can add routing configurations in the settings.

| username: TiDBer_FMWXa7ja | Original post link

My configuration file is written like this because the upstream MySQL database name contains a hyphen.

| username: TiDBer_FMWXa7ja | Original post link

I also tried this way of writing, but it didn’t work either.

| username: db_user | Original post link

Add a do-dbs above do-tables here and see.
Below ba-rule, above do-tables
do-dbs: [“analysis-service”]

If it still doesn’t work, try removing the backticks.

| username: TiDBer_FMWXa7ja | Original post link

Still not working :joy:

| username: 裤衩儿飞上天 | Original post link

Try using “test*” as the database name with the * in the regex to see if it matches, skipping special characters - :rofl:
This is kind of a hack :crazy_face:

| username: 考试没答案 | Original post link

Could you copy the error log for us to take a look? I also have an issue with hyphens at the database level. db-name. Unable to execute the query select * from db-name.table_name;.

| username: TiDBer_FMWXa7ja | Original post link

Isn’t this error log related to DM migration?

| username: TiDBer_FMWXa7ja | Original post link

The migration error log should be this file, right?

| username: 考试没答案 | Original post link

Yes.

| username: okenJiang | Original post link

Take a look and see if this is the issue: DM迁移报错 - #8,来自 okenJiang - TiDB 的问答社区

| username: db_user | Original post link

As the expert mentioned above, check the corresponding logs of DM. Normally, executing with backticks should not be an issue. I’m not sure if backticks are being filtered out in DM.

| username: 考试没答案 | Original post link

Is it resolved? Add me as a friend. Let me take a look, I’ve been working on this recently as well.

| username: 考试没答案 | Original post link

Take a look at this configuration.

| username: TiDBer_FMWXa7ja | Original post link

How can I add you as a friend?

| username: 考试没答案 | Original post link

I have finished testing this issue and found a problem. It may require official maintenance. This is just my guess for now.