Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table already exists error when trying to import sql file

I am trying to upload a backup sql file through phpMyAdmin.

create the empty db with the same db name as in my import file in phpMyAdmin then use the import function selected from within this empty db.

I get the following error message.

#1050 - Table '`db`.`t`' already exists 

Inside the import file each CREATE TABLE statement is suffixed by IF NOT EXISTS, so why is this being reported as an error?

    --
-- Database: `mbfour`
--

-- --------------------------------------------------------

--
-- Table structure for table `cars`
--

CREATE TABLE IF NOT EXISTS `cars` (
  `car_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `type` varchar(200) NOT NULL,
  `status` varchar(20) NOT NULL,
  `capacity` varchar(5) NOT NULL,
  PRIMARY KEY (`car_id`),
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `cars`
--

INSERT INTO `cars` (`car_id`, `type`, `status`, `capacity`) VALUES
(1, 'automatic', 'built', '4L'),
(2, 'automatic', 'in-production', '2L'),
(3, 'automatic', 'built', '2L'),
(4, 'automatic', 'in-production', '4L');
....
....

Is There Any Magic Happens???

After Trying Two Times Then I Import like same Way, It works

Thanks Folks.....

like image 536
Ganesh Rahul Avatar asked Sep 11 '14 12:09

Ganesh Rahul


People also ask

How do you drop a table if it exists in MySQL?

To remove a table in MySQL, use the DROP TABLE statement. The basic syntax of the command is as follows: DROP [TEMPORARY] TABLE [IF EXISTS] table_name [, table_name] [RESTRICT | CASCADE];

How do you delete a database in MySQL?

To do delete a database you need the command 'DROP DATABASE'. The syntax is similar to creating a database. 'DROP DATABASE <name>;', where <name> is the name of the database you want to delete. The mysql-console is not very helpful here.


1 Answers

Please add this at the top of every query:

DROP TABLE IF EXISTS `cars`;
CREATE TABLE IF NOT EXISTS `cars`
like image 162
Praveen Kumar Purushothaman Avatar answered Nov 15 '22 05:11

Praveen Kumar Purushothaman