Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Please help, I need to create a database for car dealership. Database has to contain all the employees in the shop and all cars in the shop. Also base has to contain info on which car is sold and which employee has sold that car.
I have made the table, but i cannnot connect sold car and employee that sold that car.
Script:
CREATE DATABASE IF NOT EXISTS `classicmodels` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `classicmodels`;
-- MySQL dump 10.13 Distrib 5.6.13, for Win32 (x86)
--
-- Host: localhost Database: classicmodels
-- ------------------------------------------------------
-- Server version 5.1.73-community
/*!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 */;
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!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' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `cars`
--
DROP TABLE IF EXISTS `cars`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `cars` (
`carID` int(11) NOT NULL AUTO_INCREMENT,
`manufacturerName` varchar(50) NOT NULL,
`modelName` varchar(50) NOT NULL,
`price` int(11) NOT NULL,
PRIMARY KEY (`carID`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `cars`
--
LOCK TABLES `cars` WRITE;
/*!40000 ALTER TABLE `cars` DISABLE KEYS */;
INSERT INTO `cars` VALUES (1,'Volkswagen','Jetta',13300),(2,'Renault','Laguna',14700),(3,'Ford','Focus',13600),(4,'Daewoo','Tico',1100),(5,'Toyota','Avensis',14500),(6,'Alfa Romeo','156',8700),(7,'Volkswagen','Passat',22200),(8,'Renault','Clio',6400),(9,'Ford','Fiesta',6900),(10,'Daewoo','Cielo',3600),(11,'Toyota','Rav4',24900),(12,'Alfa Romeo','147',7500),(13,'Volkswagen','Golf',16700),(14,'Renault','Megane',11400),(15,'Ford','Mondeo',14600),(16,'Daewoo','Matiz',1700),(17,'Toyota','Yaris',7400),(18,'Alfa Romeo','159',17000),(19,'Volkswagen','Polo',6500),(20,'Renault','Scenic',6800),(21,'Ford','Escort',2000),(22,'Daewoo','Espero',2500),(23,'Toyota','Corolla',10300),(24,'Alfa Romeo','166',5200);
/*!40000 ALTER TABLE `cars` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `employees`
--
DROP TABLE IF EXISTS `employees`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `employees` (
`employeeID` int(11) NOT NULL,
`lastName` varchar(50) NOT NULL,
`name` varchar(50) NOT NULL,
`email` varchar(100) NOT NULL,
`position` varchar(50) NOT NULL,
PRIMARY KEY (`employeeID`),
KEY `prodaja_idx` (`employeeID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `employees`
--
LOCK TABLES `employees` WRITE;
/*!40000 ALTER TABLE `employees` DISABLE KEYS */;
INSERT INTO `employees` VALUES (1,'Brkic','Goran','goran#prodavnicaautomobila.com','Direktor'),(2,'Milosevic','Srdjan','srdjan#prodavnicaautomobila.com','Marketing'),(3,'Srdic','Boro','boro#prodavnicaautomobila.com','Marketing'),(4,'Marinkovic','Marin','marin#cprodavnicaautomobila.com','Menadzer prodaje'),(5,'Nemanjic','Tamara','tamara#prodavnicaautomobila.com','Prodavac'),(6,'Kuduz','Renato','renato#prodavnicaautomobila.com','Prodavac'),(7,'Salkovic','Vladimir','vladimir#prodavnicaautomobila.com','Prodavac'),(8,'Berin','Marko','marko#prodavnicaautomobila.com','Prodavac'),(9,'Konjevic','Srecko','srecko#prodavnicaautomobila.com','Prodavac'),(10,'Pajic','Sasa','sasa#prodavnicaautomobila.com','Prodavac'),(11,'Goranovic','Milan','milan#prodavnicaautomobila.com','Prodavac');
/*!40000 ALTER TABLE `employees` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `soldcars`
--
DROP TABLE IF EXISTS `soldcars`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `soldcars` (
`carID` int(11) NOT NULL,
`empoyeeID` varchar(50) NOT NULL,
PRIMARY KEY (`carID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `soldcars`
--
LOCK TABLES `soldcars` WRITE;
/*!40000 ALTER TABLE `soldcars` DISABLE KEYS */;
INSERT INTO `soldcars` VALUES (1,'kuduz'),(2,'brkic'),(4,'goranovic'),(5,'milosevic'),(12,'pajic');
/*!40000 ALTER TABLE `soldcars` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=#OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=#OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS */;
/*!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 */;
/*!40111 SET SQL_NOTES=#OLD_SQL_NOTES */;
-- Dump completed on 2014-03-04 18:47:40
Check your table sold car has empoyeeid instead of employeeid. That is why you are not able to connect
CREATE TABLE `employees` (
`employeeID` int(11) NOT NULL,
`lastName` varchar(50) NOT NULL,
`name` varchar(50) NOT NULL,
`email` varchar(100) NOT NULL,
`position` varchar(50) NOT NULL,
PRIMARY KEY (`employeeID`),
KEY `prodaja_idx` (`employeeID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `soldcars` (
`carID` int(11) NOT NULL,
`empoyeeID` varchar(50) NOT NULL,
PRIMARY KEY (`carID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Related
I recently exported a dump file from my working MySQL database. I want to run it on a docker MariaDB database. Problem is, that the import is not working. It's throwing the following error message:
Syntax error: Unterminated quoted string.
Do you have any idea what the issue could be? Thank you for your help in advance.
My dump file:
CREATE DATABASE IF NOT EXISTS `trackmap` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE
utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
USE `trackmap`;
-- MySQL dump 10.13 Distrib 8.0.27, for Win64 (x86_64)
--
-- Host: localhost Database: trackmap
-- ------------------------------------------------------
-- Server version 8.0.27
/*!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 */;
/*!50503 SET NAMES utf8 */;
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!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' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `gruppe`
--
DROP TABLE IF EXISTS `gruppe`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `gruppe` (
`GroupID` int DEFAULT NULL,
`Name` varchar(30) DEFAULT NULL,
`Beschreibung` varchar(140) DEFAULT NULL,
`GruppenFarbe` varchar(8) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `gruppe`
--
LOCK TABLES `gruppe` WRITE;
/*!40000 ALTER TABLE `gruppe` DISABLE KEYS */;
INSERT INTO `gruppe` VALUES (1,'tolleGruppe','Eine tolle Gruppe','weiß'),
(2,'superGruppe','Eine super Gruppe','rot');
/*!40000 ALTER TABLE `gruppe` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `user`
--
DROP TABLE IF EXISTS `user`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user` (
`username` varchar(10) DEFAULT NULL,
`password` varchar(50) DEFAULT NULL,
`geolat` double DEFAULT NULL,
`geolong` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `user`
--
LOCK TABLES `user` WRITE;
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
INSERT INTO `user` VALUES ('Jakob','Jakob',0,0),
('Hendrick','Hendrick',49.99135204584314,8.280738733723956),
('Zoe','Zoe',50.06812365779786,8.236003513207015),
('Lenny','Lenny',51.21475408000626,6.779539564097885),
('Maximilian','Maximilian',53.49847387955471,10.042672857321604);
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `usergruppe`
--
DROP TABLE IF EXISTS `usergruppe`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `usergruppe` (
`GroupID` int DEFAULT NULL,
`Username` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `usergruppe`
--
LOCK TABLES `usergruppe` WRITE;
/*!40000 ALTER TABLE `usergruppe` DISABLE KEYS */;
INSERT INTO `usergruppe` VALUES (1,'Jakob'),(1,'Zoe'),(1,'Maximilian'),(1,'Lenny'),
(1,'Hendrick');
/*!40000 ALTER TABLE `usergruppe` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=#OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=#OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS */;
/*!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 */;
/*!40111 SET SQL_NOTES=#OLD_SQL_NOTES */;
-- Dump completed on 2021-12-17 15:53:30
Ive been trying to import a .SQL file and I know the database works. Can someone please explain why I am getting the below error whilst importing from self-contained file?
ERROR 3734 (HY000) at line 55: Failed to add the foreign key constraint. Missing column 'userid' for constraint 'user_app_FK' in the referenced table 'user'
-- MySQL dump 10.13 Distrib 8.0.12, for Win64 (x86_64)
--
-- Host: 127.0.0.1 Database: avi_it
-- ------------------------------------------------------
-- Server version 8.0.12
/*!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 */;
SET NAMES utf8 ;
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!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' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
DROP TABLE IF EXISTS `application`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
SET character_set_client = utf8mb4 ;
CREATE TABLE `application` ( --line 55
`applicationID` int(11) NOT NULL AUTO_INCREMENT,
`userID` int(11) DEFAULT NULL,
`jobID` int(11) DEFAULT NULL,
`applicationDes` text,
PRIMARY KEY (`applicationID`),
KEY `user_app_FK_idx` (`userID`),
KEY `job_app_FK_idx` (`jobID`),
CONSTRAINT `job_app_FK` FOREIGN KEY (`jobID`) REFERENCES `job` (`jobid`),
CONSTRAINT `user_app_FK` FOREIGN KEY (`userID`) REFERENCES `user` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
DROP TABLE IF EXISTS `user`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
SET character_set_client = utf8mb4 ;
CREATE TABLE `user` (
`userID` int(11) NOT NULL AUTO_INCREMENT,
`personID` int(11) DEFAULT NULL,
PRIMARY KEY (`userID`),
KEY `person_user_FK_idx` (`personID`),
CONSTRAINT `person_user_FK` FOREIGN KEY (`personID`) REFERENCES `person_detail` (`personid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
should be just order issue. need to first create the user table
I am trying to implement a database made in MySQL Workbench into PHPMyadmin. However, I tried a lot and it is not working. It is telling me that a certain table can't be made, since the foreign key constraint is incorrectly formed. Hopefully any of you see what is wrong with my code.
Here is my code:
-- MySQL dump 10.13 Distrib 8.0.16, for Win64 (x86_64)
--
-- Host: localhost Database: db-website
-- ------------------------------------------------------
-- Server version 8.0.15
/*!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 */;
SET NAMES utf8 ;
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!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' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `tblcategory`
--
DROP TABLE IF EXISTS `tblcategory`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
SET character_set_client = utf8 ;
CREATE TABLE `tblcategory` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`strName` varchar(45) NOT NULL,
`strDescription` varchar(100) NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ID_UNIQUE` (`ID`),
UNIQUE KEY `strName_UNIQUE` (`strName`),
UNIQUE KEY `strDescription_UNIQUE` (`strDescription`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `tblcategory`
--
LOCK TABLES `tblcategory` WRITE;
/*!40000 ALTER TABLE `tblcategory` DISABLE KEYS */;
INSERT INTO `tblcategory` VALUES (1,'Beers','Beers - description...'),(2,'Wines','Wines - description...'),(3,'Liquors','Liquors - description...');
/*!40000 ALTER TABLE `tblcategory` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `tblproduct`
--
DROP TABLE IF EXISTS `tblproduct`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
SET character_set_client = utf8 ;
CREATE TABLE `tblproduct` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`strName` varchar(45) NOT NULL,
`decPrice` decimal(10,2) unsigned NOT NULL,
`intVolume` decimal(10,2) unsigned NOT NULL,
`strDescription` varchar(100) NOT NULL,
`idProductCategory` int(10) unsigned NOT NULL,
`idProductSubCategory` int(10) unsigned NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ID_UNIQUE` (`ID`),
UNIQUE KEY `strName_UNIQUE` (`strName`),
UNIQUE KEY `strDescription_UNIQUE` (`strDescription`),
KEY `ProductSubCategory_idx` (`idProductSubCategory`),
KEY `ProductCategory_idx` (`idProductCategory`),
CONSTRAINT `ProductCategory` FOREIGN KEY (`idProductCategory`) REFERENCES `tblcategory` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `ProductSubCategory` FOREIGN KEY (`idProductSubCategory`) REFERENCES `tblsubcategory` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `tblproduct`
--
LOCK TABLES `tblproduct` WRITE;
/*!40000 ALTER TABLE `tblproduct` DISABLE KEYS */;
INSERT INTO `tblproduct` VALUES (1,'Heineken H41',6.99,2.00,'Heineken H41 Lager',1,2),(2,'G7 sauvignon blanc',5.00,0.75,'G7 sauvignon blanc White Wine ',2,12),(3,'Jack Daniel\'s Tennessee',26.99,0.70,'Jack Daniel\'s Tennessee Whiskey',3,21);
/*!40000 ALTER TABLE `tblproduct` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `tblsubcategory`
--
DROP TABLE IF EXISTS `tblsubcategory`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
SET character_set_client = utf8 ;
CREATE TABLE `tblsubcategory` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`strName` varchar(45) NOT NULL,
`strDescription` varchar(45) NOT NULL,
`idCategory` int(10) unsigned NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ID_UNIQUE` (`ID`),
UNIQUE KEY `strName_UNIQUE` (`strName`),
KEY `SubCategory-Category_idx` (`idCategory`),
CONSTRAINT `SubCategory-Category` FOREIGN KEY (`idCategory`) REFERENCES `tblcategory` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `tblsubcategory`
--
LOCK TABLES `tblsubcategory` WRITE;
/*!40000 ALTER TABLE `tblsubcategory` DISABLE KEYS */;
INSERT INTO `tblsubcategory` VALUES (1,'Ale','Description...',1),(2,'Lager','Description...',1),(3,'Pilsner','Description...',1),(4,'Stout','Description...',1),(5,'Porter','Description...',1),(6,'Bock','Description...',1),(7,'Weissbier','Description...',1),(8,'Lambic','Description...',1),(9,'Kölsch','Description...',1),(10,'Malt Liquor','Description...',1),(11,'Red Wine','Description...',2),(12,'White Wine','Description...',2),(13,'Rosé Wine','Description...',2),(14,'Sparkling Wine','Description...',2),(15,'Fortified Wine','Description...',2),(16,'Gin','Description...',3),(17,'Rum','Description...',3),(18,'Brandy','Description...',3),(19,'Tequila','Description...',3),(20,'Vodka','Description...',3),(21,'Whiskey','Description...',3);
/*!40000 ALTER TABLE `tblsubcategory` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=#OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=#OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS */;
/*!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 */;
/*!40111 SET SQL_NOTES=#OLD_SQL_NOTES */;
-- Dump completed on 2019-05-12 13:15:55
I have an application where I use a QSqlQueryModel and a table view to view some data from a mysql database.
I created the database using phpMyadmin and wrote a Python script to read Arabic data from Excel sheets and insert it into the database.
Everything works well on Linux, but when I switched to Windows, the application can't seem to encode the Arabic words correctly.
This is how it looks like for the avilable data:
صودق بالعلاج ةالمتابعه بقسم(المخ والاعصاب)
...and when I insert new data using Qt, the data shows as question marks (?).
Here's the MySQL dump for the database:
-- MySQL dump 10.13 Distrib 5.6.21, for Win32 (x86)
--
-- Host: localhost Database: tasdeek
-- ------------------------------------------------------
-- Server version 5.6.21
/*!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 */;
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!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' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `tasdeek`
--
DROP TABLE IF EXISTS `tasdeek`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tasdeek` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`rank` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`working` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`notes` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`amount` varchar(25) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`relationship` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`startDate` date NOT NULL,
`endDate` date NOT NULL,
`agency` tinyint(4) NOT NULL,
`nationalId` varchar(14) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=899 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `tasdeek`
--
LOCK TABLES `tasdeek` WRITE;
/*!40000 ALTER TABLE `tasdeek` DISABLE KEYS */;
INSERT INTO `tasdeek` VALUES (2,'مساعد','زياد شسيشسي شيسي','شسيش ','شيشسيشيسشي ي شسيشس ي شسي د','5000','شخصه','2017-02-06','2018-02-06',1,NULL),(3,'اتتلاتل تلات لات لا','سيشس شيشسي شسي ','','شيسيشسي ششي شسف شسيشي شسيشي // تجديد','5000','الوالد','2017-05-11','2018-05-11',1,NULL)
/*!40000 ALTER TABLE `tasdeek` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `users`
--
DROP TABLE IF EXISTS `users`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`userGroup` int(2) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQUE` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `users`
--
LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` VALUES (1,'admin','5bdba65d1a953aa83ed8f35ef2877274b5d451d2',0);
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=#OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=#OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS */;
/*!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 */;
/*!40111 SET SQL_NOTES=#OLD_SQL_NOTES */;
-- Dump completed on 2017-09-13 21:40:59
Note that the old data inserted on Linux is shown properly on phpMyAdmin.
See this fragment from QTextCodec::codecForLocale documentation:
On Windows, the codec will be based on a system locale. On Unix systems, the codec will might fall back to using the iconv library if no builtin codec for the locale can be found.
This could explain why you saw the correct arabic characters on Linux, but not on Windows.
As an alternative in this case, you can "force" the codec using the following instruction in your main.cpp:
QTextCodec::setCodecForLocale( QTextCodec::codecForName("UTF-8") );
PS: Don't forget the #include <QTextCodec> directive.
i was working in mysql workbench to export my database dump file to upload it to my phpmyadmin database , but i get empaty database , second i'm showing this error :
1044 - Access denied for user 'hesham'#'mocha6004.mochahost.com' to database 'sams'
and my database account have all premisson
my database file code :
CREATE DATABASE IF NOT EXISTS `sams` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `sams`;
-- MySQL dump 10.13 Distrib 5.6.11, for Win32 (x86)
--
-- Host: 127.0.0.1 Database: sams
-- ------------------------------------------------------
-- Server version 5.6.13-log
/*!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 */;
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!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' */;
/*!40111 SET #OLD_SQL_NOTES=##SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `class`
--
DROP TABLE IF EXISTS `class`;
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `class` (
`CLASS_ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`CLASS_NAME` varchar(45) NOT NULL,
`GRAdE_ID` varchar(45) NOT NULL,
`STAGE_ID` varchar(45) NOT NULL,
`school_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`CLASS_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = #saved_cs_client */;
--
-- Dumping data for table `class`
--
LOCK TABLES `class` WRITE;
/*!40000 ALTER TABLE `class` DISABLE KEYS */;
INSERT INTO `class` (`CLASS_ID`, `CLASS_NAME`, `GRAdE_ID`, `STAGE_ID`, `school_id`) VALUES (1,'1-10','1','1',1),(3,'2-20','1','1',1);
/*!40000 ALTER TABLE `class` ENABLE KEYS */;
UNLOCK TABLES;