mysql error after trying put in SQL - mysql

I'm trying to insert tables from phpmyadmin in SQL, such as:
INSERT INTO users
(
steam VARCHAR(35) NOT NULL DEFAULT '',
name VARCHAR(32) NOT NULL DEFAULT '',
length INT NOT NULL DEFAULT 0,
unban VARCHAR(32) NOT NULL DEFAULT '',
reason VARCHAR(64) NOT NULL DEFAULT '',
banned SMALLINT NOT NULL DEFAULT 0,
leaves SMALLINT NOT NULL DEFAULT 0,
PRIMARY KEY (steam)
);
But I'm getting an 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 'VARCHAR(35) NOT NULL DEFAULT '', name VARCHAR(32) NOT NULL DEFAULT '', length ' at line 3
What am I doing wrong?

Tables need to be exist in db before inserting value in that. so make sure that you are inserting value in that table which have existence in your database.
To create a table you need to fire the below query.
CREATE TABLE users
(
steam VARCHAR(35) NOT NULL DEFAULT '',
name VARCHAR(32) NOT NULL DEFAULT '',
length INT NOT NULL DEFAULT 0,
unban VARCHAR(32) NOT NULL DEFAULT '',
reason VARCHAR(64) NOT NULL DEFAULT '',
banned SMALLINT NOT NULL DEFAULT 0,
leaves SMALLINT NOT NULL DEFAULT 0,
PRIMARY KEY (steam)
);
After creating the table you can directly insert value from you phpmyadmin or you can also do that by executing the below query.
INSERT INTO users VALUES
('steam value', 'name of user', '4', 'any unban value', 'any reason value', '0', '0');
if you want insert value from you php file than you must need to make a database connection & after that you can use mysql_query() function in insert value in you db

You should create table first:
CREATE TABLE users
(
steam VARCHAR(35) NOT NULL DEFAULT '',
name VARCHAR(32) NOT NULL DEFAULT '',
length INT NOT NULL DEFAULT 0,
unban VARCHAR(32) NOT NULL DEFAULT '',
reason VARCHAR(64) NOT NULL DEFAULT '',
banned SMALLINT NOT NULL DEFAULT 0,
leaves SMALLINT NOT NULL DEFAULT 0,
PRIMARY KEY (steam)
);
once it created you can insert:
INSERT INTO users VALUES
('user steam value', 'user name', 3, 'unban value', 'reason value', 0, 0);

Related

MySQL problem when I run install.sql against new DB

I'm trying to import an sql file to a new MySQL database, but get error:
ERROR 1265 (01000) at line 65: Data truncated for column 'for_PlayerPlayerActions' at row 1
I have zero MySQL knowledge to be honest.
I've been using the url https://bitbucket.org/Maverick_of_UC/hlstatsx-community-edition/wiki/Install which allows to me to run a stats site for a gaming server. I had it all running on a Windows 2003 (MySQL & IIS) server for years, but have rebuilt the server on Windows 2012R2 and I can't run the install.sql file against the database called hlstatsx.
Log into MySQL
mysql> create database hlstatsx;
Then in a command prompt:
C:\hlstatsx\sql>mysql -uroot -p hlstatsx < install.sql
Enter password: *********
ERROR 1265 (01000) at line 65: Data truncated for column
'for_PlayerPlayerActions' at row 1
if I open install.sql in Notepad++:
CREATE TABLE IF NOT EXISTS `hlstats_Actions` (
`id` int(10) unsigned NOT NULL auto_increment,
`game` varchar(32) NOT NULL default 'valve',
`code` varchar(64) NOT NULL default '',
`reward_player` int(11) NOT NULL default '10',
`reward_team` int(11) NOT NULL default '0',
`team` varchar(64) NOT NULL default '',
`description` varchar(128) default NULL,
`for_PlayerActions` enum('0','1') NOT NULL default '0',
`for_PlayerPlayerActions` enum('0','1') NOT NULL default '0',
`for_TeamActions` enum('0','1') NOT NULL default '0',
`for_WorldActions` enum('0','1') NOT NULL default '0',
`count` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `gamecode` (`code`,`game`,`team`),
KEY `code` (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Dumping data for table `hlstats_Actions`
--
and go to line 65 I see:
INSERT INTO `hlstats_Actions` (`game`, `code`, `reward_player`, `reward_team`, `team`, `description`, `for_PlayerActions`, `for_PlayerPlayerActions`, `for_TeamActions`, `for_WorldActions`) VALUES
('tf', 'flagevent_defended', 1, 0, '', 'Defended the flag', '1', '', '', ''),
('tf', 'flagevent_captured', 5, 1, '', 'Captured the flag', '1', '', '', ''),
('tf', 'flagevent_dropped', -2, 0, '', 'Dropped the flag (while alive)', '1', '', '', ''),
...
I got this all working years ago but took no notes, any ideas?
Thanks
Based on your table definition:
`for_PlayerPlayerActions` enum('0','1') NOT NULL default '0',
the column definition requires a value for that column and the data for that column you are attempting to load is a null/empty string.
Notice:
('tf', 'flagevent_defended', 1, 0, '', 'Defended the flag', '1', '', '', ''),
All those '' are empty strings/NULL and thus are outside the allowable range of the enum, which must be '0' or '1'.
It looks like you actually have a number of columns with the same problem. You can get around this problem in loading these, to remove the NOT NULL definition for the columns and rerun your sql script.
Afterwards, update all the NULL values for the columns in this table to 0 and then change the structure back and you should be fine with any dumps and loads in the future.
This likely occurred because NULLs were allowed for these columns at some point, or the table definition was added after rows existed prior to those columns being added.

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 don't create these table [duplicate]

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;

MySQL "World" database for MS SQL Server

Does anyone know where there might be a copy of the MySQL "World" example database online somewhere that is Microsoft SQL compatible? I don't have a running MySQL server on hand, just the SQL text file that SQL Server 2008 rejects.
It is now :-) http://pastebin.com/6ATaLuNs
I have been able to load the database into my own SQL Server installation by converting the data types from MySql to SQL Server version, removing MySql-specific code (such as engine specification), and using CHECK constraints in place of the enum's. Here's my rough attempt at converting the table structure script:
BEGIN TRANSACTION
CREATE TABLE city (
ID int NOT NULL,
Name char(35) NOT NULL DEFAULT '',
CountryCode char(3) NOT NULL DEFAULT '',
District char(20) NOT NULL DEFAULT '',
Population int NOT NULL DEFAULT '0',
PRIMARY KEY (ID)
)
CREATE TABLE country (
Code char(3) NOT NULL DEFAULT '',
Name char(52) NOT NULL DEFAULT '',
Continent varchar(20) CHECK(Continent in ('Asia','Europe','North America','Africa','Oceania','Antarctica','South America')) NOT NULL DEFAULT 'Asia',
Region char(26) NOT NULL DEFAULT '',
SurfaceArea decimal(10,2) NOT NULL DEFAULT '0.00',
IndepYear smallint DEFAULT NULL,
Population int NOT NULL DEFAULT '0',
LifeExpectancy decimal(3,1) DEFAULT NULL,
GNP decimal(10,2) DEFAULT NULL,
GNPOld decimal(10,2) DEFAULT NULL,
LocalName char(45) NOT NULL DEFAULT '',
GovernmentForm char(45) NOT NULL DEFAULT '',
HeadOfState char(60) DEFAULT NULL,
Capital int DEFAULT NULL,
Code2 char(2) NOT NULL DEFAULT '',
PRIMARY KEY (Code)
)
CREATE TABLE countrylanguage (
CountryCode char(3) NOT NULL DEFAULT '',
Language char(30) NOT NULL DEFAULT '',
IsOfficial char(1) CHECK(IsOfficial IN ('T','F')) NOT NULL DEFAULT 'F',
Percentage decimal(4,1) NOT NULL DEFAULT '0.0',
PRIMARY KEY (CountryCode,Language)
)
COMMIT TRANSACTION
You can run the INSERT statements as-is if you make the following changes (you will have to manually pull out the INSERT statements by removing the CREATE TABLE code in the MySql script):
Remove all instances of back-tick (`) (Find-Replace ` with nothing in an editor)
Replace all instances of \' with '' for SQL Server's quote escaping