|
1.查看要删除instance的id号。本例中为“11”
mysql> use nova;
mysql> select id, vm_state, display_name from instances;
2.删除security_group_instance_association中关联数据
mysql> delete from security_group_instance_association where id='11';
3. 删除instance_info_caches中关联数据
mysql> select id,instance_uuid from instance_info_caches;
+----+--------------------------------------+
| id | instance_uuid |
+----+--------------------------------------+
| 9 | 1f58e354-44c8-4819-95ba-47a55303d7c1 |
| 3 | 3c394ace-7a7d-4537-be26-5904731c0659 |
| 14 | 43f0f739-d29a-49e7-b13b-d46088a8a3f9 |
| 4 | 48bf080e-70be-4534-94e0-1c949a5c5987 |
| 11 | 4997f3d0-3b8d-47ef-b3c0-6f979afac985 |
| 1 | 53f916ae-840b-49b9-b59d-9028976ca9ce |
| 13 | 5a795c94-cba7-48a7-aeed-5fc88ca8ad9d |
| 8 | 5d561b4a-1f68-452b-8668-ce65b1c360a3 |
| 6 | 8cfb0ecf-64c6-441a-b955-77117b518612 |
| 12 | 8d1694ec-6b69-4d63-9371-834b38b3467e |
| 10 | 8f92e86a-6e57-40bb-b425-c4fe8b35dc49 |
| 5 | b9915110-895b-46ed-8b55-386f51431d99 |
| 7 | d1dc8617-b206-4c41-86e3-4e8840c51fbb |
| 2 | e4c7a74f-98a7-47da-aa08-9c0ca9f331c6 |
+----+--------------------------------------+
14 rows in set (0.00 sec)
mysql> delete from instance_info_caches where id='11';
4.删除instance中数据
mysql> delete from instances where id='11';
进行删除instance数据时可能报以下错误:
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`nova`.`block_device_mapping`, CONSTRAINT `block_device_mapping_instance_uuid_fkey` FOREIGN KEY (`instance_uuid`) REFERENCES `instances` (`uuid`))
这可能是MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据。可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况。
mysql> set foreign_key_checks=0;
mysql> delete from instances where id='11';
mysql> set foreign_key_checks=1;
mysql> select id,vm_state,hostname,uuid from instances;
+----+----------+-------------------+--------------------------------------+
| id | vm_state | hostname | uuid |
+----+----------+-------------------+--------------------------------------+
| 1 | deleted | centos-6.5-test-1 | 53f916ae-840b-49b9-b59d-9028976ca9ce |
| 2 | deleted | centos-6.5-test-2 | e4c7a74f-98a7-47da-aa08-9c0ca9f331c6 |
| 3 | deleted | centos-6.5-test-3 | 3c394ace-7a7d-4537-be26-5904731c0659 |
| 4 | deleted | centos-6.5-test-4 | 48bf080e-70be-4534-94e0-1c949a5c5987 |
| 5 | deleted | centos-6.5-test-5 | b9915110-895b-46ed-8b55-386f51431d99 |
| 6 | deleted | cirros-test-1 | 8cfb0ecf-64c6-441a-b955-77117b518612 |
| 7 | deleted | cirros-test-2 | d1dc8617-b206-4c41-86e3-4e8840c51fbb |
| 8 | deleted | cirros-test-3 | 5d561b4a-1f68-452b-8668-ce65b1c360a3 |
| 9 | deleted | cirros-test-4 | 1f58e354-44c8-4819-95ba-47a55303d7c1 |
| 10 | deleted | cirros-test-5 | 8f92e86a-6e57-40bb-b425-c4fe8b35dc49 |
| 14 | deleted | cirros-test-6 | 43f0f739-d29a-49e7-b13b-d46088a8a3f9 |
+----+----------+-------------------+--------------------------------------+
11 rows in set (0.00 sec)
5.删除instance镜像文件
cd /var/lib/nova/instances/
rm -f 实例ID
错误操作:mysql> delete from instances where id = 11;
错误提示: ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`nova`.`security_group_instance_association`, CONSTRAINT `security_group_instance_association_ibfk_2` FOREIGN KEY (`instance_id`) REFERENCES `instances` (`id`))
解决方法:
mysql> delete from security_group_instance_association where id=11;
Query OK, 1 row affected (0.06 sec)
mysql> delete from instance_info_caches where id=11;
Query OK, 1 row affected (0.06 sec)
mysql> delete from instances where id = 11;
Query OK, 1 row affected (0.05 sec)
|
|