When i try to import my DB i get this error. I don't know what I should do, please help.
--
-- Database: oddjobexchange
--
-- ---------------------------------------------------- --
--
TABLE structure FOR TABLE admin --
CREATE TABLE IF NOT EXISTS admin (
Email varchar( 30 ) NOT NULL ,
Password varchar( 35 ) NOT NULL ,
PRIMARY KEY ( Email )
) ENGINE = InnoDB DEFAULT CHARSET = latin1;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Table structure for table admin
CREATE TABLE IF NOT EXISTS admin (
`Em' at line 10
help!
There needs to be a space after the first two dashes. Otherwise it is not a valid comment:
------------------------------------------------------ --
should be:
-- ---------------------------------------------------- --
Just need to add the follwing to top of file.
CREATE DATABASE databasename;
USE databasename;
Related
I have a problem with MySQL.
I had successfully set up MySQL, as well as created a database (named "Users").
I am able to CREATE DATABASE (such as the one named "Users"), but when I'm onto creating tables using the command CREATE TABLE, MySQL returns the statement:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL, password NOT NULL)' at line 2
Here's my code:
-- First, I'll set the database to "Users":
USE users
-- Then, I'll make a table within the database Users:
CREATE TABLE users (
user NOT NULL,
password NOT NULL
);
Your syntax for creating a table in MySQL is not correct. You have to provide the data type for every column you create inside a table, Like if your user and password is varchar type then:
CREATE TABLE users (
user VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL
);
Also read link for reference.
You miss the data type for your columns, try this one (obviously you can change the column type as for your requirements):
CREATE TABLE users (
user VARCHAR(24) NOT NULL,
password VARCHAR(24) NOT NULL
);
how to fix this error when i import database into phpmyadmin cpanel:
SQL query:
--
-- Database: `news_letter`
--
-- --------------------------------------------------------
--
-- Table structure for table `banner_tbl`
--
CREATE TABLE IF NOT EXISTS `banner_tbl` (
`ban_id` INT( 11 ) NOT NULL ,
`banner_img` VARCHAR( 255 ) NOT NULL ,
`date` VARCHAR( 255 ) NOT NULL
) ENGINE = INNODB AUTO_INCREMENT =158 DEFAULT CHARSET = latin1;
MySQL said: Documentation
#1046 - No database selected
add the following lines on top of your .sql file
CREATE DATABASE IF NOT EXISTS `news_letter`;
USE `news_letter`;
At the site Sea Quail Database Diagram Tool which is great for creating database diagrams I just created a MySQL database schema diagram - very basic one to get a feel of it.
I created the script to run from PHPMyadmin to add this all to a database created there to see if importing would work OK, but I ran into this error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '--------------------------------------------------------------------------------' at line 2
Here is a snippet of the SQL data that was generated for me.
-- Create Table: name_fields
--------------------------------------------------------------------------------
CREATE TABLE name_fields
(
`` VARCHAR(250) NULL
)
ENGINE=INNODB
-- Create Table: name_api
--------------------------------------------------------------------------------
CREATE TABLE name_api
(
`` VARCHAR(250) NULL
)
ENGINE=INNODB
-- Create Table: name_users
--------------------------------------------------------------------------------
CREATE TABLE name_users
(
`ID` BIGINT NULL
,`user_login` VARCHAR(250) NULL
,`user_name` VARCHAR(250) NULL
,`user_password` VARCHAR(250) NULL
)
ENGINE=INNODB
-- Create Table: name_options
--------------------------------------------------------------------------------
CREATE TABLE name_options
(
`` VARCHAR(250) NULL
)
ENGINE=INNODB
-- Create Table: name_ideal
Not sure what is wrong with the syntax here. Is there an easy way to debug this in MySQL?
Yes you have syntax error
First of all the
-- Create Table: name_fields
-------------------------------------------------------------------------------
Should be in one line you need to check this
something like
-- Create Table: name_fields ------------------------------------------------------
2nd thing
CREATE TABLE name_fields
(
`` VARCHAR(250) NULL
)
ENGINE=INNODB
Where is the column name ? you have just specified ``. The same is for name_api table too, correct these and it should work.
I try to import a MySQL database on the localhost through phpmyadmin and i receive this error. what it means? and how can i solve it? any ideas?
SQL query:
--
-- Database: `casasdl_mag`
--
--
-- Database: `casasdl`
--
-- --------------------------------------------------------
--
-- Table structure for table `admin_assert`
--
CREATE TABLE IF NOT EXISTS `admin_assert` (
`assert_id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Assert ID',
`assert_type` VARCHAR( 20 ) DEFAULT NULL COMMENT 'Assert Type',
`assert_data` TEXT COMMENT 'Assert Data',
PRIMARY KEY ( `assert_id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 COMMENT = 'Admin Assert Table' AUTO_INCREMENT =1;
MySQL said: Documentation
#1046 - No database selected
When you create a table you need to select a database for that table to insert into
USE databaseName;
run this before your script
USE casasdl;
CREATE TABLE IF NOT EXISTS `admin_assert` (
`assert_id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Assert ID',
`assert_type` VARCHAR( 20 ) DEFAULT NULL COMMENT 'Assert Type',
`assert_data` TEXT COMMENT 'Assert Data',
PRIMARY KEY ( `assert_id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 COMMENT = 'Admin Assert Table' AUTO_INCREMENT =1;
Like you can read in error, you have to select your database.
Add USE yourDatabase; at the beginning of the code.
mysql or each db backend should import your tables into a Database , so it needs you introduce a db name , indeed you should tell to mysql :
use mydbname;
you can create it from :
mysqladmin -uroot -p create mydbname
mysql -uroot -p mydbname < mysqlfile.sql
if you are using external php, then do not use use database syntax or mysql-select_db("database"); syntax. Instead use mysqli_connect which accept database name.
The USE db_name statement tells MySQL to use the db_name database as the default (current) database for subsequent statements. The database remains the default until the end of the session or another USE statement is issued.
Refer: http://dev.mysql.com/doc/refman/5.6/en/use.html
Another option is within phpmyadmin Select DB from the left sidebar and inside it import will work.
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`;