MySQL problem when I run install.sql against new DB - mysql

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.

Related

mysql error after trying put in SQL

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);

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

Drupal encoding and node insert

I have a CCK type for storing mentions (Social Media search mentions). Some of the mentions I believe are ASCII (My knowledge of this stuff is little).
I retrieve data from API's, which I then using node_save to save to Drupal.
My question is, what should I use to safely convert whatever I am getting into a format Drupal and MySQL are happy with?
The particular db_query error I get is unhelpfull "Warning in test1\includes\common.inc on line 3538". Nice. I have traced it to be encoding, as I used the following code to make the input safe, but it is not working with all input.
$node->title = htmlentities($item['title'], ENT_COMPAT, 'UTF-8');
It worked well for some ASCII characters, like those square ones [] etc, but not for this "行けなくてもずっとユーミンは聴きつづけます".
I'm really stuck. :(
UPDATE: The EXACT error I get from PHP is "Warning in D:\sites\test1\includes\common.inc on line 3538", and the line reads "if (db_query($query, $values)) {".
UPDATE 2: I've confirmed that the encoding of the data I am receiving is UTF8. This really doesn't make sense now, and I've confirmed that the collation in the db is utf8_general_ci.
UPDATE 3: One of the title's is: How Much Does A Facebook Fan Cost?� $1.07
The output of:
var_export(array_map('ord', str_split($node->title))
gave me the character 160 for the funny question mark (which is a square like [] in eclipse).
UPDATE 4: MySQL version is 5.1.41, and the collation on the columns is utf8_general_ci.
UPDATE 5: I managed to get Drupal to print the query with db_queryd. Funny thing is now I get the exact error message and not "Warning in", but Drupal still doesn't have this error in the log! WTF. So the exact sql is:
INSERT INTO node (vid, type, language, title, uid, status, created, changed, comment, promote, moderate, sticky, tnid, translate) VALUES (0, 'sm_mention', '', 'How Much Does A Facebook Fan Cost?� $1.07 (Geoffrey A. Fowler/Digits)', 1, 1, 1298395302, 1298395302, 0, 0, 0, 0, 0, 0)
And the error given is: Incorrect string value: '\xA0 $1.0...' for column 'title' at row 1
This honestly sounds like something doesn't like extended ascii characters.
UPDATE 6:
SHOW CREATE TABLE node:
CREATE TABLE `node` (
`nid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`vid` int(10) unsigned NOT NULL DEFAULT '0',
`type` varchar(32) NOT NULL DEFAULT '',
`language` varchar(12) NOT NULL DEFAULT '',
`title` varchar(255) NOT NULL DEFAULT '',
`uid` int(11) NOT NULL DEFAULT '0',
`status` int(11) NOT NULL DEFAULT '1',
`created` int(11) NOT NULL DEFAULT '0',
`changed` int(11) NOT NULL DEFAULT '0',
`comment` int(11) NOT NULL DEFAULT '0',
`promote` int(11) NOT NULL DEFAULT '0',
`moderate` int(11) NOT NULL DEFAULT '0',
`sticky` int(11) NOT NULL DEFAULT '0',
`tnid` int(10) unsigned NOT NULL DEFAULT '0',
`translate` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`nid`),
UNIQUE KEY `vid` (`vid`),
KEY `node_changed` (`changed`),
KEY `node_created` (`created`),
KEY `node_moderate` (`moderate`),
KEY `node_promote_status` (`promote`,`status`),
KEY `node_status_type` (`status`,`type`,`nid`),
KEY `node_title_type` (`title`,`type`(4)),
KEY `node_type` (`type`(4)),
KEY `uid` (`uid`),
KEY `tnid` (`tnid`),
KEY `translate` (`translate`)
) ENGINE=InnoDB AUTO_INCREMENT=1700 DEFAULT CHARSET=utf8
\xA0 is not a valid start of a UTF8 sequence.
The character known as NO-BREAK SPACE having the Unicode codepoint 0x00A0 should be encoded as 0xC2A0 in UTF8.
Thus said, your input string is broken, it's not a valid UTF8.