MySql Database showing ???? for Hindi Fonts - mysql

I am trying to save Hindi content in db so for that i made changes in table as well with this query
ALTER TABLE group_distribution CHARACTER SET UTF8;
and when i run this query
SHOW VARIABLES LIKE 'character_set%';
I got below result
character_set_client utf8
character_set_connection utf8
character_set_database latin1
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
character_sets_dir /usr/share/mysql/charsets/
What changes i have to made so my DB support other languages too ?

I got the issue ..Issue is related to table definition see below
CREATE TABLE `group_distribution` (
`gd_id` int(11) NOT NULL,
`gd_tweet` varchar(500) CHARACTER SET latin1 NOT NULL,
`gd_ht` varchar(45) CHARACTER SET latin1 DEFAULT NULL,
`gt_created_by` int(11) DEFAULT NULL,
`gt_team_lead` int(11) DEFAULT NULL,
`gt_send_to` int(11) DEFAULT NULL,
`gt_added_dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`gt_update_dt` timestamp NULL DEFAULT NULL,
`gt_active_flag` tinyint(1) NOT NULL,
PRIMARY KEY (`gd_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Here you can check it clearly show gd_tweet` varchar(500) CHARACTER SET latin1 NOT NULL, have diffrent characterset thats why created issue now i changed it to
CREATE TABLE `group_distribution` (
`gd_id` int(11) NOT NULL,
`gd_tweet` varchar(500) CHARACTER SET utf8 NOT NULL,
`gd_ht` varchar(45) CHARACTER SET utf8 DEFAULT NULL,
`gt_created_by` int(11) DEFAULT NULL,
`gt_team_lead` int(11) DEFAULT NULL,
`gt_send_to` int(11) DEFAULT NULL,
`gt_added_dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`gt_update_dt` timestamp NULL DEFAULT NULL,
`gt_active_flag` tinyint(1) NOT NULL,
PRIMARY KEY (`gd_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8;

Related

Sql constraint error references other column

I don't know a lot of mysql and have an error in my sql script. Currently running mysql 8.0.24. Does anyone know what might be the problem?
Error:
https://prnt.sc/226xk5x
Sql:
-- Dumping structure for table gtav_rp2._vehicle
CREATE TABLE IF NOT EXISTS `_vehicle` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`cid` int(11) unsigned NOT NULL,
`vin` varchar(50) NOT NULL DEFAULT '',
`type` varchar(50) NOT NULL DEFAULT '',
`size` int(11) NOT NULL,
`plate` varchar(50) NOT NULL DEFAULT '',
`model` varchar(50) NOT NULL DEFAULT '',
`name` varchar(50) DEFAULT NULL,
`garage` varchar(59) DEFAULT NULL,
`state` varchar(50) DEFAULT NULL,
`appearance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid('appearance')),
`mods` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid('mods')),
`data` longtext DEFAULT NULL,
`damage` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid('damage')),
`degredation` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid('degredation')),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Dumping data for table gtav_rp2._vehicle: ~0 rows (approximately)
/*!40000 ALTER TABLE `_vehicle` DISABLE KEYS */;
/*!40000 ALTER TABLE `_vehicle` ENABLE KEYS */;
/*!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 */;
Your CHECK constraint does not reference the column. Or any column, actually. By using single-quotes, you're using a string literal, not a column name.
`appearance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
CHECK (json_valid('appearance')),
I assume this is meant to be:
`appearance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
CHECK (json_valid(`appearance`)),
Use the right type of quotes for SQL identifiers, not string literals.
In addition, this CHECK constraint would be unnecessary if you used the JSON data type instead of LONGTEXT. The JSON data type already enforces that the content of the column must be valid JSON format.
MySQL's JSON data type already uses utf8mb4 character set and utf8mb4_bin collation.
So your column definition could be simply as follows:
`appearance` JSON

MySQL Merge Two Tables with Similar Data Union/Join?

So, I have two tables filled with for the most part very similar data, for example, a row in each table may have the same first name, last name, and address, but have a different phone number or email address based on the most recently available data which was updated in a separate excel worksheet (out of my hands, my job is just to merge this data into our latest database which they plan to use from here on out, not the excel sheet). I just need a good way to merge these tables with the same column names without doing it manually (about 24,000+) records.
Here is the Create Table Syntax for both tables:
CREATE TABLE `UsersUpdated` (
`FULLNME` longtext,
`LSTNME` varchar(23) CHARACTER SET utf8 DEFAULT NULL,
`FSTNME` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
`MID` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
`SUFF` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
`STAT` varchar(2) CHARACTER SET utf8 DEFAULT NULL,
`PTY` varchar(3) CHARACTER SET utf8 DEFAULT NULL,
`PH` bigint(20) DEFAULT NULL,
`ALTPH` bigint(20) DEFAULT NULL,
`DOB` datetime DEFAULT NULL,
`REGDTE` datetime DEFAULT NULL,
`ADDR` text,
`ST` int(11) DEFAULT NULL,
`STNME` varchar(19) CHARACTER SET utf8 DEFAULT NULL,
`APT` varchar(7) CHARACTER SET utf8 DEFAULT NULL,
`TWN` varchar(6) CHARACTER SET utf8 DEFAULT NULL,
`ZIP` int(11) DEFAULT NULL,
`W` int(11) DEFAULT NULL,
`d` int(11) DEFAULT NULL,
`G17` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`P17` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`G16` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`P16` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`G15` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`P15` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`G14` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`P14` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`SIGN` tinyint(1) NOT NULL DEFAULT '0',
`SUPP` tinyint(1) NOT NULL DEFAULT '0',
`NOTES` longtext,
`LTR` tinyint(1) DEFAULT NULL,
`REGISTERED` tinyint(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `Users` (
`FULLNME` longtext,
`LSTNME` varchar(23) CHARACTER SET utf8 DEFAULT NULL,
`FSTNME` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
`MID` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
`SUFF` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
`STAT` varchar(2) CHARACTER SET utf8 DEFAULT NULL,
`PTY` varchar(3) CHARACTER SET utf8 DEFAULT NULL,
`PH` bigint(20) DEFAULT NULL,
`ALTPH` bigint(20) DEFAULT NULL,
`DOB` datetime DEFAULT NULL,
`REGDTE` datetime DEFAULT NULL,
`ADDR` text,
`ST` int(11) DEFAULT NULL,
`STNME` varchar(19) CHARACTER SET utf8 DEFAULT NULL,
`APT` varchar(7) CHARACTER SET utf8 DEFAULT NULL,
`TWN` varchar(6) CHARACTER SET utf8 DEFAULT NULL,
`ZIP` int(11) DEFAULT NULL,
`W` int(11) DEFAULT NULL,
`d` int(11) DEFAULT NULL,
`G17` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`P17` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`G16` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`P16` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`G15` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`P15` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`G14` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`P14` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`SIGN` tinyint(1) NOT NULL DEFAULT '0',
`SUPP` tinyint(1) NOT NULL DEFAULT '0',
`NOTES` longtext,
`LTR` tinyint(1) DEFAULT NULL,
`REGISTERED` tinyint(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
As you can see, they are basically the same exact tables, I just need to merge them correctly.
Perhaps this is helpful.
update Users
set ADDR = (
select ADDR from UsersUpdated uu
where uu.FULLNME = Users.FULLNME and uu.DOB = Users.DOB
), STNME = (
select STNME from UsersUpdated uu
where uu.FULLNME = Users.FULLNME and uu.DOB = Users.DOB
) ...
;
You can add all the columns to a single update. Depending on the size of the database it might just be as easy to do them individually.
Many platforms allow for a from clause with update that permits a join and a shorter query but it can be problematic. This way you will get errors if any of the subqueries don't return just a single value.
I would modify the Users table to add a UNIQUE key on the fields that should be the same (presumably FSTNME, LSTNME and ADDR from your description but perhaps you might use some other columns e.g. DOB as suggested by #shawnt00), then INSERT the data from UsersUpdated into Users using an ON DUPLICATE KEY UPDATE clause to copy updated data into Users where the user already exists in that table. This query will also work when there are users in UsersUpdated who are not already in Users. So,
ALTER TABLE Users ADD UNIQUE KEY NameAddr (FSTNME, LSTNME, ADDR);
INSERT INTO Users
SELECT * FROM UsersUpdated
ON DUPLICATE KEY UPDATE
FULLNME=VALUES(FULLNME),
LSTNME=VALUES(LSTNME),
FSTNME=VALUKES(FSTNME),
...
LTR=VALUES(LTR),
REGISTERED=VALUES(REGISTERED);

sql import error, invalid default value

I have google the problem I guess I am not the expert in sql thats why I cant seem to solve it.
I am exporting database from dedicated server and trying to import into google cloud instance apache / sql
I get error like below even I tried all answers in stackoverflow
Error
SQL query:
CREATE TABLE `islemler` (
`islemID` int(11) NOT NULL,
`islemKullaniciID` int(11) NOT NULL,
`islemTarih` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`islemBitisTarihi` datetime DEFAULT NULL,
`islemDurum` varchar(500) COLLATE utf8_turkish_ci NOT NULL,
`islemNot` varchar(500) COLLATE utf8_turkish_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci
MySQL said: Documentation
1067 - Invalid default value for 'islemTarih'
please see the screen shot from link
Old database
New Database error
I appreciate some help...
As additional
I manage to create all tables manual, as much as from my sql knowledge.
I run below commands
CREATE TABLE oradamis_vt.islemler ( islemID INT(11) NOT NULL , islemKullaniciID INT(11) NOT NULL , islemTarih DATETIME NOT NULL , islemBitisTarihi DATETIME NOT NULL , islemDurum VARCHAR(500) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , islemNot VARCHAR(500) CHARACTER SET utf32 COLLATE utf32_turkish_ci NOT NULL ) ENGINE = InnoDB;
CREATE TABLE oradamis_vt.kullanicilar ( kullaniciID INT(11) NOT NULL , username VARCHAR(250) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , password VARCHAR(250) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , kullaniciAdi VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , kullaniciPozisyon VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , kullaniciSkype VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , kullaniciMail VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , kullaniciTelefon VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , kullaniciYetki VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL ) ENGINE = InnoDB;
CREATE TABLE oradamis_vt.version ( versionNumber INT(11) NOT NULL , sonIslemKullanici VARCHAR(250) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL , sonIslem VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL ) ENGINE = InnoDB;
But at the end when I try to import from old SQL gives same error of startup.
quite frustrated :(
Try replacing with:
CREATE TABLE islemler ( islemID int(11) NOT NULL, islemKullaniciID int(11) NOT NULL, islemTarih timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, islemBitisTarihi datetime DEFAULT NULL, islemDurum varchar(500) COLLATE utf8_turkish_ci NOT NULL, islemNot varchar(500) COLLATE utf8_turkish_ci NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci MySQL said: Documentation

XAMPP's PHPMyAdmin Ignores AUTO_INCREMENT Attribute When Exporting the Table

The problem that I am going to tell is for all the tables in the DB, When I dump my DB it ignores AUTO_INCREMENT attribute. My actual table is as the following:
CREATE TABLE IF NOT EXISTS `departments` (
`departmentid` int(11) NOT NULL AUTO_INCREMENT,
`chairid` int(11) NOT NULL,
`department_name` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`image` varchar(128) NOT NULL DEFAULT 'default_department.png',
`url` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`active` tinyint(4) NOT NULL DEFAULT '1'
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
But if I dump the table using PHPMyAdmin it does not add auto_increment which I mentioned before.
The output of the exported .sql file's content is here:
CREATE TABLE IF NOT EXISTS `departments` (
`departmentid` int(11) NOT NULL, -- AUTO_INCREMENT is missing
`chairid` int(11) NOT NULL,
`department_name` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`image` varchar(128) NOT NULL DEFAULT 'default_department.png',
`url` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`active` tinyint(4) NOT NULL DEFAULT '1'
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
I especially checked that if auto_increment is disabled in CREATE TABLE options but no, it is not.
This was fixed in phpMyAdmin version 4.5.0.1 (Sep 2015):
https://github.com/phpmyadmin/phpmyadmin/issues/11492
I supposed it ignores auto increment but I explore file and at the bottom of sql I found that it altered to auto increment somewhere else

Why am I seeing "COLLATION 'xxx' is not valid for CHARACTER SET 'yyy'"

I am on MySQL 5.6.22 (InnoDB) on Amazon RDS. I have attempted to set all of my tables, columns, connection and database charset and collation settings to utf8mb4 / utf8mb4_unicode_ci. I can find no evidence anywhere that anything has charset latin1, yet when I execute the following code (either via node-mysql, or directly in "Sequel Pro" app on my Mac):
update MyTable m
set m.Column8 = 1
where m.Column3 = 26 and m.Column4 = 76
collate utf8mb4_unicode_ci
I get this error message:
COLLATION 'utf8mb4_unicode_ci' is not valid for CHARACTER SET 'latin1'
I cannot find anything set to latin1 in my configuration.
Output of show variables like "char%":
character_set_client utf8mb4
character_set_connection utf8mb4
character_set_database utf8mb4
character_set_filesystem utf8mb4
character_set_results utf8mb4
character_set_server utf8mb4
character_set_system utf8
character_sets_dir /rdsdbbin/mysql-5.6.22.R1/share/charsets/
Output of show variables like "collation%":
collation_connection utf8mb4_unicode_ci
collation_database utf8mb4_unicode_ci
collation_server utf8mb4_unicode_ci
MyTable's CREATE TABLE info is:
CREATE TABLE `MyTable` (
`Column1` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`Column2` varchar(12) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`Column3` bigint(20) unsigned NOT NULL,
`Column4` bigint(20) unsigned NOT NULL,
`Column5` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
`Column6` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
`Column7` varchar(112) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`Column8` tinyint(1) unsigned NOT NULL,
`Column9` decimal(16,14) DEFAULT NULL,
`Column10` decimal(17,14) DEFAULT NULL,
`Column11` bigint(20) unsigned DEFAULT NULL,
`Column12` bigint(20) unsigned DEFAULT NULL,
`Column13` timestamp(6) NULL DEFAULT NULL,
`Column14` timestamp(6) NULL DEFAULT NULL,
`Column15` tinyint(4) NOT NULL DEFAULT '1',
`Column16` tinyint(4) NOT NULL DEFAULT '1',
`Column17` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`Column18` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`Column19` bigint(20) unsigned DEFAULT NULL,
PRIMARY KEY (`Column1`),
KEY `IX_Reevues_Column3` (`Column3`),
KEY `IX_Reevues_Column4` (`Column4`),
KEY `IX_Reevues_Column6` (`Column6`),
KEY `IX_Reevues_Column8` (`Column8`),
KEY `IX_Reevues_Column2` (`Column2`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Why have a COLLATE clause when comparing a BIGINTs compared to literal numbers? Remove the COLLATE clause in the UPDATE statement. -- This is the main solution, as per OP's comments.
Is the code inside a Stored Routine that was build with latin1? Do SHOW CREATE PROCEDURE (or FUNCTION) to see if that were the case. If so, then DROP and reCREATE it with utf8mb4 in force.
It is risky to change character_set_filesystem and character_set_server. Change them back.