Friday, March 1, 2013

Mysql database restore issue

When you see database restore issue such as below.

[root@titan src]# mysql cec25_db12 < cec_db.sql ERROR 1146 (42S02) at line 175856: Table 'cec_db.student_course' doesn't exist What the error actually means? The mysql server is trying to restore/modify a table of a database and it cannot see it created. Here mysql server check the database “cec_db” and a table “student_course” in that database. We might be restoring the database to a newly created database called username_newdb or username_cec_db specifically. Why this is happening? In these cases, you need to check the sql code which you are trying to restore. You can see the sql code contain the below lines. This means the sql code will check the database cec_db during the restore time, but it does not exist. CREATE ALGORITHM=UNDEFINED DEFINER=`cec_u`@`%` SQL SECURITY DEFINER VIEW `cec_db`.`location_salon_schedule_used` AS select `cec_db`.`student_course`.`location_salon_shedule_id` AS `location_salon_schedule_id`,count(`cec_db`.`student_course`.`location_salon_shedule_id`) AS `capacity_used` from `cec_db`.`student_course` where ((`cec_db`.`student_course`.`status` = 1) and (`cec_db`.`student_course`.`location_salon_shedule_id` > 0)) group by `cec_db`.`student_course`.`location_salon_shedule_id`;


How can we correct this? We can correct this by changing the occurrences of cec_db with the name of the database that we are restoring, in this example cec25_db12 using sed. Run mysql restore again.

sed -i 's/cec_db/cec25_db12/g' /path/to/cec_db.sql

No comments:

Post a Comment