Page 1 of 1

Can't select database for importing sql file

Posted: Mon Sep 01, 2008 3:52 pm
by Sindarin
I want to import an sql file into a database called autocomplete but phpAdmin says that there was no database selected.
I know only one way to select a database and that's through php.

Is there an SQL command that tells it to select a database?

here's the sql file btw

Code: Select all

-- 
-- Table structure for table `countries`
-- 
 
CREATE TABLE `countries` (
  `id` int(6) NOT NULL AUTO_INCREMENT,
  `value` varchar(250) NOT NULL DEFAULT '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=243 ;
 
-- 
-- Dumping data for table `countries`
-- 
 
INSERT INTO `countries` VALUES (1, 'Afghanistan');
INSERT INTO `countries` VALUES (2, 'Aringland Islands');
INSERT INTO `countries` VALUES (3, 'Albania');
INSERT INTO `countries` VALUES (4, 'Algeria');
INSERT INTO `countries` VALUES (5, 'American Samoa');
INSERT INTO `countries` VALUES (6, 'Andorra');

Re: Can't select database for importing sql file

Posted: Mon Sep 01, 2008 4:19 pm
by onion2k
You can specify the database in the SQL by sticking it on the front of the table name.. eg

Code: Select all

CREATE TABLE `autocomplete`.`countries`
It's strange that phpMyAdmin isn't remembering which database you selected though. Does it return an error number?

Re: Can't select database for importing sql file

Posted: Mon Sep 01, 2008 4:40 pm
by califdon
Sindarin wrote:Is there an SQL command that tells it to select a database?
Depending on what database engine you're using, it's use <databasename> or use database <databasename>.

Re: Can't select database for importing sql file

Posted: Mon Sep 01, 2008 5:50 pm
by Sindarin
ah yes USE DATABASE, that's what I was looking for!