Mysql Database not creating table [messy code] - mysql

I tried to add this:
-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Nov 09, 2013 at 04:43 PM
-- Server version: 5.5.16
-- PHP Version: 5.3.8
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `rezzion`
--
-- --------------------------------------------------------
--
-- Table structure for table `punishments`
--
CREATE TABLE IF NOT EXISTS `punishments` (
`username` varchar(20) NOT NULL AUTO_INCREMENT,
`punisher` varchar(20) NOT NULL,
`server` varchar(15) NOT NULL,
`type` int(255) NOT NULL,
`date` varchar(1024) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
to my database "rezzion" & for some reason i'm getting this error:
Anyone know why it's doing this? I have my database set to utf8-bin & it's name is rezzion... I'm confused why the code above isn't working?

Your error starts, at least, here:
`username` varchar(20) NOT NULL AUTO_INCREMENT,
This is not allowed in MySQL. And, besides, you're declaring primary key with another column:
PRIMARY KEY (`id`)

Auto Increment can only be used on a INT change it to a integer and your problem is solved

AUTO_INCREMENT my only be used with number types. You are applying it to a VARCHAR column. Also, you specify an "id" column as your primary key which does not exist.
You probably want it to look like this:
CREATE TABLE IF NOT EXISTS `punishments` (
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` varchar(20) NOT NULL,
`punisher` varchar(20) NOT NULL,
`server` varchar(15) NOT NULL,
`type` int(255) NOT NULL,
`date` varchar(1024) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Related

MySQL why AUTO_INCREMENT does not start at 0 when using CREATE TABLE in MySQL Workbench (8.0)

Using MySQL Workbench 8.0, I'm using table table create statements based on an existing (database) table containers.
DROP TABLE IF EXISTS `containers`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `containers` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`customer_id` int(10) NOT NULL,
`waste_id` int(10) DEFAULT NULL,
[.. etc etc ..]
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL,
`removed` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4293 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
/*!40103 SET TIME_ZONE=#OLD_TIME_ZONE */;
Why is this statement generating an ENGINE=InnoDB AUTO_INCREMENT=4293 that starts at value 4293?
Since it is a table CREATE statement, is it always expecting that one copies existing records in the old table to the newly created tables? And continues working with the newly created table?
I would expect it to start at the value 0 when creating an new table.
Any idea what I'm missing? Thanks!

how can i change with timestamp mysql in a date

I have here MySQL code for my table but I want to change this date but I do not want time but just date what should I do I have already searched a lot on the internet but still found nothing. and I also have a week overview here how I would apply that.
I hope you can help me
regards stefaan
``-- phpMyAdmin SQL Dump
-- version 4.4.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Dec 12, 2017 at 10:59 AM
-- Server version: 5.6.26
-- PHP Version: 5.5.28
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `phpcurdpdo`
--
-- --------------------------------------------------------
--
-- Table structure for table `tblusers`
--
CREATE TABLE IF NOT EXISTS `tblusers` (
`id` int(11) NOT NULL,
`Auditeur` varchar(150) NOT NULL,
`Zone` varchar(120) NOT NULL,
`NOKOK01` char(11) NOT NULL,
`NOKOK02` char(11) NOT NULL,
`NOKOK03` char(11) NOT NULL,
`NOKOK04` char(11) NOT NULL,
`Bericht` varchar(255) NOT NULL,
`PostingDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Week` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `tblusers`
--
INSERT INTO `tblusers` (`id`, `Auditeur`, `Zone`, `NOKOK01`, `NOKOK02`, `NOKOK03`, `NOKOK04`, `Bericht`, `PostingDate`) VALUES
(1, 'Stefaan', 'Zone 2060', 'NOK', 'OK', 'OK', 'NOK', 'graag een verandering', '2017-12-12 06:27:53');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `tblusers`
--
ALTER TABLE `tblusers`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `tblusers`
--
ALTER TABLE `tblusers`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=7;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;

SQL Syntax Error - Can't Import

I have been trying to import this query but it doesn't seem to work?
-- --------------------------------------------------------
-- Host: 127.0.0.1
-- Server versie: 10.1.21-MariaDB - mariadb.org binary distribution
-- Server OS: Win64
-- HeidiSQL Versie: 9.3.0.4984
-- --------------------------------------------------------
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8mb4 */;
/*!40014 SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
-- Databasestructuur van gta5_gamemode_essential wordt geschreven
CREATE DATABASE IF NOT EXISTS `gta5_gamemode_essential` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `gta5_gamemode_essential`;
-- Structuur van tabel gta5_gamemode_essential.bans wordt geschreven
CREATE TABLE IF NOT EXISTS `bans` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`banned` varchar(50) NOT NULL DEFAULT '0',
`banner` varchar(50) NOT NULL,
`reason` varchar(150) NOT NULL DEFAULT '0',
`expires` datetime NOT NULL,
`timestamp` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Data exporteren was gedeselecteerd
-- Structuur van tabel gta5_gamemode_essential.users wordt geschreven
CREATE TABLE IF NOT EXISTS `users` (
`identifier` varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT '',
`group` varchar(50) NOT NULL DEFAULT '0',
`permission_level` int(11) NOT NULL DEFAULT '0',
`money` double NOT NULL DEFAULT '0',
`weapons` varchar(5000) CHARACTER SET utf8 NOT NULL,
`personalvehicle` varchar(10000) CHARACTER SET utf8 NOT NULL,
`withdraw_cost` int(10) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Data exporteren was gedeselecteerd
/*!40101 SET SQL_MODE=IFNULL(#OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(#OLD_FOREIGN_KEY_CHECKS IS NULL, 1, #OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
`withdraw_cost` int(10) NOT NULL, -- Remove this comma
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
users needs a PRIMARY KEY. Or maybe you are missing the PRIMARY KEY clause??

How to solve duplicate mySQL entry?

I'm pulling stats down from an external source but the external source has changed how it handles things which is causing me problems, everything else works but for 1 section of the database which is giving me duplicate entries, as nothing is being pulled the database enters the value of 0 so the next field would also have a value of 0, I tried auto increment but I still end up with a duplicate entry.
-- phpMyAdmin SQL Dump
-- version 3.4.11.1deb2+deb7u6
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 27, 2016 at 02:44 AM
-- Server version: 5.5.52
-- PHP Version: 5.6.26-1~dotdeb+zts+7.1
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `forum`
--
-- --------------------------------------------------------
--
-- Table structure for table `xf_yfl_rival_stats`
--
CREATE TABLE IF NOT EXISTS `xf_yfl_rival_stats` (
`match_id` bigint(30) NOT NULL,
`player_ea_id` bigint(60) NOT NULL,
`persona_name` varchar(50) NOT NULL,
`club_id` bigint(20) NOT NULL,
`assists` int(2) NOT NULL,
`cleansheetsany` int(2) NOT NULL,
`cleansheetsdef` int(2) NOT NULL,
`cleansheetsgk` int(2) NOT NULL,
`goals` int(2) NOT NULL,
`goalsconceded` int(2) NOT NULL,
`mom` int(1) NOT NULL,
`passattempts` int(3) NOT NULL,
`passesmade` int(3) NOT NULL,
`pos` int(3) NOT NULL,
`rating` double(4,2) NOT NULL,
`redcards` int(2) NOT NULL,
`saves` int(3) NOT NULL,
`shots` int(3) NOT NULL,
`tackleattempts` int(3) NOT NULL,
`tacklesmade` int(3) NOT NULL,
`yellowcards` int(2) NOT NULL DEFAULT '0',
PRIMARY KEY (`player_ea_id`),
UNIQUE KEY `match_id` (`match_id`,`player_ea_id`),
KEY `club_id` (`club_id`),
KEY `player_ea_id` (`player_ea_id`),
KEY `match_id_2` (`match_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
I'm getting the duplicate entry for the field player_ea_id is there any possible way to bypass this?
My understanding of mySQL isn't the greatest, for example I pull down the match_id or persona_name and both of these fields have the same entry for the players however the player_ea_id is supposed to be unique, how do I get around this?
I dont see where you're using AUTO_INCREMENT. But that is indeed what you need if you are not getting that column from your source.
Change the player_ea_id line of your table creation to this.
`player_ea_id` bigint(60) NOT NULL AUTO_INCREMENT,
#Strawberry, every other part of that database works, its collects stats from the EA sports title FIFA 17, and the 4.2 is related to the players overall match rating which works fine.
#TheValyreanGroup I already tried auto increment it still ends up giving me a duplicate error although not on 0 but on 6 for example or 10, or 15 just whenever it decides to break down. I can run a query and show you what it does on auto increment compared to how it is now if you like?

Cannot add foreign key constraint

First, here's my main reference table mysql dump
-- phpMyAdmin SQL Dump
-- version 4.1.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Nov 17, 2015 at 03:15 AM
-- Server version: 5.6.17
-- PHP Version: 5.5.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */; /*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */; /*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */;
--
-- Database: `j_inventory`
--
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(200) COLLATE utf8_unicode_ci NOT NULL, `password` varchar(500) COLLATE utf8_unicode_ci NOT NULL, `real_password` varchar(250) COLLATE utf8_unicode_ci NOT NULL, `role` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `full_name` varchar(250) COLLATE utf8_unicode_ci NOT NULL, `remember_token` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `status` varchar(100) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=44 ;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
and the second table where the hopefully the foreign key resides
-- phpMyAdmin SQL Dump
-- version 4.1.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Nov 17, 2015 at 03:14 AM
-- Server version: 5.6.17
-- PHP Version: 5.5.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */; /*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */; /*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */;
--
-- Database: `j_inventory`
--
-- --------------------------------------------------------
--
-- Table structure for table `user_details`
--
CREATE TABLE IF NOT EXISTS `user_details` ( `id` int(11) NOT NULL AUTO_INCREMENT, `phone` varchar(200) NOT NULL, `age` int(100) NOT NULL, `gender` varchar(50) NOT NULL, `address` varchar(250) NOT NULL, `course` varchar(250) NOT NULL, `college` varchar(200) NOT NULL, `year` int(11) NOT NULL, `user_id` int(100) NOT NULL, `updated_at` timestamp NOT NULL, `created_at` timestamp NOT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
the foreign key (not set up due to mysql error "Cannot add foreign key constraint ") in the users_details is the 'user_id' and the reference table is the 'users' table where the reference key for the foreign key is the 'user_id' on the users table and I tried this
ALTER TABLE user_details ADD FOREIGN KEY fk1(user_id) REFERENCES
users(user_id) ON DELETE CASCADE ON UPDATE NO ACTION;
but sadly and unfortunately it throws me an error
Error SQL query:
ALTER TABLE user_details ADD CONSTRAINT fk1 FOREIGN KEY
(user_id) REFERENCES j_inventory.users(user_id) ON DELETE
CASCADE ON UPDATE NO ACTION; MySQL said: Documentation
1215 - Cannot add foreign key constraint Documentation
any help, clues, ideas, suggestions, recommendations please?
Your user id is unsigned on the users table. Remove 'unsigned' from this field in your users table create statement and see if it works. I think what you're seeing is an error caused by a mismatch between the user_id field types on your users and user_details tables