Can't select database for importing sql file

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Can't select database for importing sql file

Post 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');
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Can't select database for importing sql file

Post 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?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Can't select database for importing sql file

Post 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>.
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: Can't select database for importing sql file

Post by Sindarin »

ah yes USE DATABASE, that's what I was looking for!
Post Reply