MySql don't create these table [duplicate] - mysql

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
1064 error in CREATE TABLE … TYPE=MYISAM
I am trying to install a PHP script named php-stats, this one: http://www.php-stats.it/ that is a Php that provides information about statistic of web site.
I have used it in the past and it is pretty good.
Today I am trying to install it on my server but I have some problem
It need to be installed on the server and use the database...my problem is when it try to create the database table...go into error with many tables...
The errors have the form of the following one (this is related to one specific table):
Error executing: CREATE TABLE php_stats_cache ( user_id varchar(15) NOT NULL default '0', data int(11) NOT NULL default '0', lastpage varchar(255) NOT NULL default '0', visitor_id varchar(32) NOT NULL default '', hits tinyint(3) unsigned NOT NULL default '0', visits smallint(5) unsigned NOT NULL default '0', reso varchar(10) NOT NULL default '', colo varchar(10) NOT NULL default '', os varchar(20) NOT NULL default '', bw varchar(20) NOT NULL default '', host varchar(50) NOT NULL default '', lang varchar(8) NOT NULL default '', giorno varchar(10) NOT NULL default '', level tinyint(3) unsigned NOT NULL default '0', UNIQUE KEY user_id (user_id) ) TYPE=MyISAM
Error string: 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 'TYPE=MyISAM' at line 17
I have also try to access inside the *.sql file that contains the query definition and execute the creation query table inside PHP MyAdmin, for example this query (related to the previus error):
DROP TABLE IF EXISTS php_stats_cache;
CREATE TABLE php_stats_cache (
user_id varchar(15) NOT NULL default '0',
data int(11) NOT NULL default '0',
lastpage varchar(255) NOT NULL default '0',
visitor_id varchar(32) NOT NULL default '',
hits tinyint(3) unsigned NOT NULL default '0',
visits smallint(5) unsigned NOT NULL default '0',
reso varchar(10) NOT NULL default '',
colo varchar(10) NOT NULL default '',
os varchar(20) NOT NULL default '',
bw varchar(20) NOT NULL default '',
host varchar(50) NOT NULL default '',
lang varchar(8) NOT NULL default '',
giorno varchar(10) NOT NULL default '',
level tinyint(3) unsigned NOT NULL default '0',
UNIQUE KEY user_id (user_id)
) TYPE=MyISAM;
Ig I try to execute this query inside PhpMyAdmin I obtain the following error message:
#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 'TYPE=MyISAM' at line 17
I also try to execute it on my local mysql server on my PC but I obtain always the same error message...
Why? What is the problem? How can I do to solve this problem?
Thank you
Andrea

Using TYPE has been deprecated and it was removed in MySQL 5.5. Use ENGINE = MYISAM instead.
CREATE TABLE php_stats_cache (....) ENGINE = MYISAM;

Related

ERROR #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax [duplicate]

This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 3 years ago.
I want to create a table in a database with SQL but a 1064 error appears. Can you help me solve my problem.
CREATE TABLE keys (
`id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`key` varchar(40) NOT NULL,
`level` int(2) NOT NULL,
`ignore_limits` tinyint(1) NOT NULL DEFAULT '0',
`is_private_key` tinyint(1) NOT NULL DEFAULT '0',
`ip_addresses` text,
`date_created` int(11) NOT NULL
)
key and keys are keywords in mysql. You can solve the problem by changing them.
CREATE TABLE mykeys (
`id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`key_value` varchar(40) NOT NULL,
`level` int(2) NOT NULL,
`ignore_limits` tinyint(1) NOT NULL DEFAULT '0',
`is_private_key` tinyint(1) NOT NULL DEFAULT '0',
`ip_addresses` text,
`date_created` int(11) NOT NULL
)

MySQL #1064 - You have an error in your SQL syntax at line 2

What's wrong on this code? I receive that message when try to import this sql:
#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 ''codigo' int(11) unsigned NOT NULL auto_increment, 'razao_social' varchar(11) N' at line 2
CREATE TABLE IF NOT EXISTS `char` (
'codigo' int(11) unsigned NOT NULL auto_increment,
'razao_social' varchar(11) NOT NULL DEFAULT '',
'fantasia' varchar(11) NOT NULL DEFAULT '',
'data_de_cadastro' datetime NOT NULL DEFAULT '',
'cep' varchar(11) NOT NULL DEFAULT '',
'logradouro' varchar(11) NOT NULL DEFAULT '',
'numero' varchar(11) NOT NULL DEFAULT '',
'complemento' varchar(11) NOT NULL DEFAULT '',
'bairro' varchar(11) NOT NULL DEFAULT '',
'cidade' varchar(11) NOT NULL DEFAULT '',
'uf' varchar(11) NOT NULL DEFAULT '',
'cnpj' varchar(11) NOT NULL DEFAULT '',
'insc_estadual' varchar(11) NOT NULL DEFAULT '',
'incs_municipal' varchar(11) NOT NULL DEFAULT '',
'telefone01' varchar(11) NOT NULL DEFAULT '',
'telefone02' varchar(11) NOT NULL DEFAULT '',
'contato' varchar(11) NOT NULL DEFAULT '',
'associados' varchar(11) NOT NULL DEFAULT '',
'funcionários' varchar(11) NOT NULL DEFAULT '',
'data_socio' datatime NOT NULL DEFAULT '',
'data_desligamento' datatime NOT NULL DEFAULT '',
'email' varchar(11) NOT NULL DEFAULT '',
'website' varchar(11) NOT NULL DEFAULT '',
'situacao' int(11) NOT NULL DEFAULT '',
PRIMARY KEY (`codigo`),
UNIQUE KEY `razao_social` (`razao_social`),
KEY `fantasia` (`account_id`),
KEY `cnpj` (`cnpj`),
KEY `insc_estadual` (`insc_estadual`),
KEY `incs_municipal` (`incs_municipal`)
) ENGINE=MySQL;
you should use backticks ` in MySQL to escape column name identifiers, not single quotes ' (actually, all identifiers, just like you've done with you table name);
you provide datatime as the datatype for data_socio and
data_desligamento, which is invalid (because it doesn't exist, I think you've meant datetime);
MySQL is not a valid engine option (maybe you've meant MyISAM?), here is a list of storage engines;
'' is not a valid default value for the datetime datatype (data_desligamento, data_socio and data_de_cadastro);
you are creating an index fantasia using a key for the column account_id that doesn't even exist in your table (or it is just a typo and either fantasia column should be called account_id or vice versa? - just guessing here).
SQLFiddle
Do not use single quotes(') in column names, instead use tild symbol (`).
For example:
this column 'razao_social' should be write as `razao_social`

INSERT INTO using SET in SQL

My first post so bear with me.
I need to restore a DB Table from a backup. I have cleaned the SQL up so I only have the the DROP TABLE, CREATE TABLE and INSERT INTO commands. The query is failing when I run it in MYSQl on my server.
The error message is....
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 'id='2',
unitid='1',
optionname='Baby Chair',
customtype='0',
customfeild' at line 3
The query is.....
DROP TABLE IF EXISTS `jos_resman_options`;
CREATE TABLE `jos_resman_options`
(
`id` int(4) NOT NULL AUTO_INCREMENT,
`unitid` int(9) NOT NULL DEFAULT '0',
`optionname` varchar(255) NOT NULL DEFAULT '',
`customtype` tinyint(1) NOT NULL DEFAULT '0',
`customfeild` varchar(150) NOT NULL DEFAULT '',
`moreinformation` varchar(255) NOT NULL DEFAULT '',
`totaloptions` tinyint(1) NOT NULL DEFAULT '0',
`price` decimal(10,2) NOT NULL DEFAULT '0.00',
`minvalue` int(2) NOT NULL DEFAULT '0',
`maxvalue` int(2) NOT NULL DEFAULT '0',
`formobject` int(1) NOT NULL DEFAULT '0',
`enabled` tinyint(1) NOT NULL DEFAULT '0',
`priceoption` int(1) NOT NULL DEFAULT '0',
`taxfree` tinyint(1) NOT NULL DEFAULT '0',
`compulsory` tinyint(1) NOT NULL DEFAULT '0',
`istax` tinyint(1) NOT NULL DEFAULT '0',
`isinsure` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=75;
INSERT INTO `jos_resman_options`
VALUES
id='2',
unitid='1',
optionname='Baby Chair',
customtype='0',
customfeild='',
moreinformation='Baby Chair',
totaloptions='0',
price='0.00',
minvalue='1',
maxvalue='2',
formobject='1',
enabled='1',
priceoption='2',
taxfree='1',
compulsory='0',
istax='0',
isinsure='0';
The table is created, When the CREATE TABLE part runs on it's own there is no error message. I only see the error message when the INSERT INTO part of the query runs.
The INSERT INTO data is directly from a backup of the database and so the data SHOULD be OK??
Many Thanks for any input
Have Tried all of the suggestions...Changing the Auto INCREMENT to DEFAULT Field, Put in the Brackets, All of them fail with error messages. Here's the latest error message... Thanks again all.!
Error
SQL query:
INSERT INTO `jos_resman_options`
SET unitid = '1',
optionname = 'Baby Chair',
customtype = '0',
customfeild = '',
moreinformation = 'Baby Chair',
totaloptions = '0',
price = '0.00',
minvalue = '1',
maxvalue = '2',
formobject = '1',
enabled = '1',
priceoption = '2',
taxfree = '1',
compulsory = '0',
istax = '0',
isinsure = '0'
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 'maxvalue='2',
formobject='1',
enabled='1',
priceoption='2',
taxfree='1',' at line 12
INSERT INTO `jos_resman_options`
VALUES (
id='2',
unitid='1',
optionname='Baby Chair',
customtype='0',
customfeild='',
moreinformation='Baby Chair',
totaloptions='0',
price='0.00',
minvalue='1',
maxvalue='2',
formobject='1',
enabled='1',
priceoption='2',
taxfree='1',
compulsory='0',
istax='0',
isinsure='0');
try to delete id fields becouse id was defined AutoNumber.
So you can not insert a value because it handles the database engine, if you delete the columba will tell you different amount of columns to insert, then try putting id = DEFAULT or omit the id field

MySQL Version Related Syntax Errors

When uploading a SQL script using MySQL version 5.5.23-55 and importing using phpMyadmin version 3.4.11.1, I am getting the following goofy errors:
SQL query:
CREATE TABLE `dp_banks` (
`id` int(11) NOT NULL auto_increment,
`owner` int(11) NOT NULL default '0',
`bname` varchar(128) NOT NULL default '',
`baddress` varchar(128) NOT NULL default '',
`bcity` varchar(64) NOT NULL default '',
`bzip` varchar(16) NOT NULL default '',
`bcountry` char(2) NOT NULL default '',
`bstate` varchar(32) NOT NULL default '',
`bphone` varchar(32) NOT NULL default '',
`bnameacc` varchar(128) NOT NULL default '',
`baccount` varchar(32) NOT NULL default '',
`btype` char(2) NOT NULL default '',
`brtgnum` varchar(9) NOT NULL default '',
`bswift` varchar(32) NOT NULL default '',
`status` tinyint(1) NOT NULL default '0',
`default` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
MySQL said:
#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 'TYPE=MyISAM AUTO_INCREMENT=1' at line 19
Researching on the net, I found an article that recommended changing TYPE=MyISAM to ENGINE=MyISAM. Making this change now gives the following errors:
SQL query:
CREATE TABLE `dp_confirms` (
`id` int(11) NOT NULL auto_increment,
`newuser` varchar(32) NOT NULL default '',
`newpass` varchar(32) NOT NULL default '',
`newquestion` varchar(255) NOT NULL default '',
`newanswer` varchar(255) NOT NULL default '',
`newmail` varchar(255) NOT NULL default '',
`newfname` varchar(32) NOT NULL default '',
`newlname` varchar(32) NOT NULL default '',
`newcompany` varchar(128) NOT NULL default '',
`newregnum` varchar(32) NOT NULL default '',
`newdrvnum` varchar(32) NOT NULL default '',
`newaddress` varchar(128) NOT NULL default '',
`newcity` varchar(64) NOT NULL default '',
`newcountry` char(2) NOT NULL default '',
`newstate` varchar(32) NOT NULL default '',
`newzip` varchar(32) NOT NULL default '',
`newphone` varchar(64) NOT NULL default '',
`newfax` varchar(64) NOT NULL default '',
`sponsor` int(11) NOT NULL default '0',
`confirm` varchar(255) NOT NULL default '',
`cdate` timestamp(14) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `newuser` (`newuser`),
KEY `newmail` (`newmail`)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
MySQL said:
#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 '(14) NOT NULL, PRIMARY KEY (id), UNIQUE KEYnewuser(newuser), KEY ' at line 22
Thanks in advance for all help.
Other than changing TYPE to ENGINE change
`cdate` timestamp(14) NOT NULL,
^^^^
to
`cdate` timestamp NOT NULL,
Here is SQLFiddle demo
) TYPE=MyISAM AUTO_INCREMENT=1 ;
Replace this with
) ENGINE = MYISAM AUTO_INCREMENT =1;
Type has been replaced with engine.
TYPE keyword is depreciated (since 5.0) and not supported in MySQL5.5 (and I think even 5.1). Instead of TYPE keyword use ENGINE keyword.
My experience was that i had to change two things:
TYPE=MyISAM AUTO_INCREMENT=1 ;
Replace this with
ENGINE=MyISAM AUTO_INCREMENT=1;
AND
cdate timestamp(14) NOT NULL,
to
cdate timestamp NOT NULL,
That worked for me

Latest version of MySQL gives error 1064 on code that used to work fine

Many servers now a days have the latest version of MySQL - which is giving an error when running the following piece of code:
$drop_table = mysql_query("DROP TABLE IF EXISTS `$t_ads`");
$sqls[$t_ads] = "CREATE TABLE `$t_ads` (
`adid` int unsigned NOT NULL auto_increment,
`adtitle` varchar(100) NOT NULL default '',
`addesc` longtext NOT NULL,
`area` varchar(50) NOT NULL default '',
`email` varchar(50) NOT NULL default '',
`showemail` enum('0','1','2') NOT NULL default '0',
`password` varchar(50) NOT NULL default '',
`code` varchar(35) NOT NULL default '',
`cityid` smallint unsigned NOT NULL default '0',
`subcatid` smallint unsigned NOT NULL default '0',
`price` DECIMAL( 10, 2 ) NOT NULL default '0',
`othercontactok` enum('0','1') NOT NULL default '0',
`hits` int unsigned NOT NULL default '0',
`ip` varchar(15) NOT NULL default '',
`verified` enum('0','1') NOT NULL default '0',
`abused` int unsigned NOT NULL default '0',
`enabled` enum('0','1') NOT NULL default '0',
`createdon` datetime NOT NULL default '0000-00-00 00:00:00',
`expireson` datetime NOT NULL default '0000-00-00 00:00:00',
`timestamp` timestamp(14) NOT NULL,
`paid` enum('0','1','2') NOT NULL default '2',
PRIMARY KEY (`adid`),
KEY `subcatid` (`subcatid`),
KEY `cityid` (`cityid`),
KEY `verified` (`verified`),
KEY `enabled` (`enabled`),
KEY `paid` (`paid`)
) TYPE=MyISAM;";
Servers with an older version of mysql seem to accept this, but the new version is not accepting it at all and giving an error. I have many errors related to it since the PHP database setup is little bigger. An example of the error is below:
#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 '(14) NOT NULL, paid enum, NOT NULL default '2', PRIMARY KEY (adid), K' at line 21
The plain SQL part of your code looks ok (just tested it with MySQL 5.6), though I'd generally advise not to use keywords like timestamp as a column name. The table will be created in MySQL 5.6, but you'll encounter two warnings:
The syntax TIMESTAMP(14) is deprecated and will be removed in
MySQL 6.0. Please use TIMESTAMP instead
The syntax TYPE=storage_engine is deprecated and will be removed in MySQL
6.0. Please use ENGINE=storage_engine instead
If this doesn't help, please post the actual MySQL version you're working with.
Change your column name it should not be mysql keyword 'timestamp' and
chnage
`timestamp` timestamp(14) NOT NULL,
to
`<SOME OTHERNAME>` timestamp NOT NULL,