Table doesn't exist on CREATE TABLE? - mysql

I'm trying to import a SQL dump to another server. It fails on the first line. I'm first creating the exp_actions table and then inserting a bunch of data into it, but I get this really weird error.
SQL query:
--
-- Database: `ee_cmssite`
--
-- --------------------------------------------------------
--
-- Table structure for table `exp_actions`
--
CREATE TABLE `exp_actions` (
`action_id` INT( 4 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`class` VARCHAR( 50 ) NOT NULL DEFAULT '',
`method` VARCHAR( 50 ) NOT NULL DEFAULT '',
PRIMARY KEY ( `action_id` )
) ENGINE = MYISAM DEFAULT CHARSET = latin1 AUTO_INCREMENT =21;
MySQL said:
#1146 - Table 'site_ee.exp_actions' doesn't exist
Why doesn't it exist? I just instructed it to be created. I'm completely baffled. I've tried with and without IF_NOT_EXISTS

If anyone else comes across this seemingly bizarre error - see https://stackoverflow.com/a/11696069 for the solution.
I had the same symptoms and the cause was the same - moving to a new machine I took the old short-cut of simply copying the databases from the mysql/data directory that I needed directly into the new machine, however some were newer InnoDb types. This causes the Create Table throws table doesn't exist error. I had to drop the database and recreate it, then import from an sql dump.

According to the SQL script, the table exists in another database:
--
-- Database: ee_cmssite
-- --------------------------------------------------------
-- Table structure for table exp_actions
try to use ee_cmssite database instead.

While the error is not clear, I think this is related to the missing USE at the beginning of the file. mysqldump doesn't add a USE statement when you dump a single db. So you should add:
USE `ee_cmssite`;

Related

Importing database into WAMP Server

I have a project sent to me by a friend and i am having serious issues importing the database into my WAMP Server. I end up getting Mysql error
Error
SQL query:
--
-- Database: `drivers_endorsements`
--
-- --------------------------------------------------------
--
-- Table structure for table `admin`
--
CREATE TABLE IF NOT EXISTS `admin` (
`admin_id` int(11) NOT NULL,
`username` varchar(30) NOT NULL,
`password` varchar(12) NOT NULL,
`name` varchar(40) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3
MySQL said: Documentation
#1046 - No database selected
Firstly you have to create database manually or select the existing one in phpmyadmin (as mentioned WAMP server is used ) and then import the .sql file in it, and the database name should be same as that of used in application else will not work with desired application to which the database is linked.
It's not really a big deal! The message itself is self-explanatory. You need to select an existing database first & then try your import.
Or you could possibly add the following at the very top of your DB script that you trying to import -
CREATE DATABASE IF NOT EXISTS drivers_endorsements;
USE drivers_endorsements;

cant import an exported file into wampserver

I created a database, linked it to project and even inserted some values in them. nothing seemed wrong. but after I exported the file. and later decided to import it into wamp, I get this error message:
Error
SQL query:
--
-- Database: `dimensioncon`
--
-- --------------------------------------------------------
--
-- Table structure for table `admission_form`
--
DROP TABLE IF EXISTS `admission_form`
MySQL said: Documentation
#1046 - No database selected
please what seems to be the problem? and how do I import the database back please.
use dimensioncon; --your database name
Then use your SQL query
SQL query:
DROP TABLE IF EXISTS `admission_form`
--
-- Table structure for table `admission_form`
--
first use 'Database Name';
use dimensioncon;
SQL query:
DROP TABLE IF EXISTS `admission_form`;
and now imported your sql file.
You just have to use USE dimensioncon; in the starting of your exported file
Something like
USE Your_Database_Name;
CREATE TABLE IF NOT EXISTS `admission_form` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) DEFAULT NULL,
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10001 ;
--
-- Dumping data for table `admission_form`
--
INSERT INTO `admission_form` (`user_id`, `username`) VALUES (1, 'rogers63');

Error #1046 - No database selected SQL import on XAMPP

I am trying to import the SQL database from my Drupal production site into a sandbox testing site on my local machine. I currently use XAMPP on my machine here at work.
I have downloaded my db aipiadxxm_if9DHdr.sql and then I go to the phpMyAdmin on http://localhost/phpmyadmin/index.php then to -> Import.
After I import the db I get this Error:
SQL query:
--
-- Database: `aipiadxxm_if9DHdr.sql`
--
-- --------------------------------------------------------
--
-- Table structure for table `if9d_access`
--
CREATE TABLE IF NOT EXISTS `if9d_access` (
`aid` int( 11 ) NOT NULL AUTO_INCREMENT ,
`mask` varchar( 255 ) NOT NULL default '',
`type` varchar( 255 ) NOT NULL default '',
`status` tinyint( 4 ) NOT NULL default '0',
PRIMARY KEY ( `aid` )
) ENGINE = MYISAM DEFAULT CHARSET = utf8 AUTO_INCREMENT =1;
MySQL said: Documentation
#1046 - No database selected
What is causing this error message: #1046 - No database selected ?
You need to create and/or select the database on your sandbox machine before importing the SQL for the table structure and data.
In phpMyAdmin, this means choosing a database from the sidebar and then using its import tab. If the database you want to fill doesn't exist, you have to create it first using the Create new database form.
After import, you should confirm that the export-import process hasn't affected the anonymous user record (uid 0).

MYSQL relational database

http://www.go4expert.com/forums/showthread.php?t=13386
im following the article above and i am getting error at the first quoted code
#1049 - Unknown database 'library'
CREATE TABLE `library`.`books` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 150 ) NOT NULL ,
`author_id` INT UNSIGNED NOT NULL ,
PRIMARY KEY ( `id` ) ,
INDEX ( `author_id` )
) ENGINE = INNODB
the other one generates with no problem but this one, why?
Your table name is prepended with the database name "library". Probably your DB is named differently. If you're executing within the DB that you're using just remove the "library." prefix.
CREATE TABLE `books` (
...
Remove the "library" part from the CREATE TABLE statement. The other block in that article works because it doesn't reference "library".
Remove the library. - just use what ever database you're using, ie
CREATE TABLE books (...
And while you're at it, remove all those unnecessary backticks - they are only required when using reserved words (which you should avoid like the plague anyway)
The table authors will be created in your default/current database, here the database library is to be used, but it hasn't been created. You should make a library database.
CREATE DATABASE library
Using a differently named database, or removing library from the create table statement may cause problems further down the tutorial.

What does this error in MySQL mean?

I am using the Zymic Database Uploader v1.1 to upload my XAMPP/MySQL database to zymic database.
I followed the instruction carefully until I got this error.
Error at the line 27: ) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci MAX_ROWS=15000;
Query: CREATE TABLE `bmf_chatting` (
`usr_id` int(11) NOT NULL,
`usr_name` varchar(255) collate latin1_general_ci NOT NULL,
`chatto` int(11) NOT NULL,
`timestamp` int(11) NOT NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci MAX_ROWS=15000;
MySQL: Table 'bmf_chatting' already exists
This happened while I was Processing/Importing the database into Zymic but it stopped on error. I have no database yet in my zymic and I have no duplicate table 'bmf_chatting'.
I thought it will be a simple export/import. :(
Check your dump file, if this table didn't get exported twice for whatever reason.
Also make sure, to drop all tables (and maybe the entire database) before you retry with you import. Whatever tables are created above this one, have already been created.
It sounds like you had a table called bmf_chatting in MySQL before and it was improperly deleted (the files were probably deleted without dropping the database).
Try running a drop database query before your create query.