SQL Query Returning Distorted Integer - mysql

This is the SQL table:
CREATE TABLE `player_data` (
`id` BIGINT(225) DEFAULT NULL,
`name` VARCHAR(225) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '',
`gender` VARCHAR(225) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '',
`model` VARCHAR(225) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '',
`money` BIGINT(225) DEFAULT NULL,
`playtime` BIGINT(225) DEFAULT NULL
);
I have a very simple query that is trying to fetch the id. Query:
SELECT id FROM player_data WHERE id = '"..id.."'
The ID in the table is 76561198342211128, however, when that query is run it returns 7.6561198342211e+16 is there any reason it's doing this based off what I've shown?

Related

MYSQL Stored Procedure - Concat Row Value (continued)

Update / Answer
To fix this issue, I added the keyword BINARY to each side of the comparison operator. This generated the expected results. Also note that I set the variable to empty string. Setting this to NULL did not resolve the issue.
SET #previousstate = '';
SELECT
if(**BINARY** #previousstate != **BINARY** frm.fi_details_temp.PortfolioCode,
End Update / Answer
This is somewhat related to MYSQL Stored Procedure - Concat Row Value. That thread was based on Mysql 5.7.
The following statement worked under MySQL 5.7. I am in the process of trying to get it to work in MySql 8. I had to update the SET statement to 'SET #previousstate = NULL;' otherwise I get "Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operation '<>'". This error was way above my understanding. I am just a marketing guy working in a small firm. So that is why I set it to NULL.
With that said, after updating the SET statement the result set returns but the if() statement is not working like it did under 5.7. The very first row returned should have the first column of data marked with '*' at the beginning and end, and as the data in the column changes it should mark it too.
So it should look like this:
*brownfdn*
brownfdn
*brownfmi*
brownfmi
But I am getting this:
brownfdn
brownfdn
brownfmi
brownfmi
Do you have any thoughts about what I am doing wrong? I appreciate your help!! Getting to MySql 8 has been a struggle.
5.7
CREATE table fi_details_temp AS (
SELECT
frm.fi_details.PortfolioCode,
frm.fi_details.MaturityDate_Final
From
frm.fi_details
Where
frm.fi_details.manager = 'Bartz' And
frm.fi_details.PortfolioCode Like ('Crown%')
Group By
frm.fi_details.PortfolioCode,
frm.fi_details.MaturityDate_Final
Order By
frm.fi_details.PortfolioCode;
SET #previousstate = '';
SELECT
if(#previousstate != frm.fi_details_temp.PortfolioCode, concat('*',#previousstate:= frm.fi_details_temp.PortfolioCode,'*'), frm.fi_details_temp.PortfolioCode) as 'Portfolio Code',
frm.fi_details_temp.MaturityDate_Final as 'Maturity Date'
From frm.fi_details_temp;
DROP TABLE IF EXISTS fi_details_temp;
END
*** Create Statements - the above was a trimmed down version ***
CREATE TABLE `fi_details` (
`id` int NOT NULL AUTO_INCREMENT,
`RecordDate` datetime DEFAULT CURRENT_TIMESTAMP,
`PortfolioCode` varchar(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`manager` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`RunDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`RunDate_Final` date DEFAULT NULL,
`AsOfDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AsOfDate_Final` date DEFAULT NULL,
`Symbol` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`Coupon` double DEFAULT NULL,
`MaturityDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`MaturityDate_Final` date DEFAULT NULL,
`ParValue` double DEFAULT NULL,
`MarketValue` double DEFAULT NULL,
`AdjustedUnitCost` double DEFAULT NULL,
`TotalAdjustedCost` double DEFAULT NULL,
`SPRating` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`MoodyRating` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`YieldCost` double DEFAULT NULL,
`YieldMarket` double DEFAULT NULL,
`YieldCall` double DEFAULT NULL,
`YieldPut` double DEFAULT NULL,
`YieldWorst` double DEFAULT NULL,
`WorstDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`WorstDate_Final` date DEFAULT NULL,
`CallDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`CallDate_Final` date DEFAULT NULL,
`CallPrice` double DEFAULT NULL,
`PutDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`PutDate_Final` date DEFAULT NULL,
`PutPrice` double DEFAULT NULL,
`FirstCouponDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`FirstCouponDate_Final` date DEFAULT NULL,
`LastCouponDate` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`LastCouponDate_Final` date DEFAULT NULL,
`Freq` int DEFAULT NULL,
`BondCalendarCode` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`SecTypeCode` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`Security` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_fi_details_MaturityDate_Final` (`MaturityDate_Final`),
KEY `idx_fi_details_PortfolioCode` (`PortfolioCode`),
KEY `idx_fi_details_PortfolioCode_MaturityDate_Final` (`PortfolioCode`,`MaturityDate_Final`),
KEY `idx_fi_details_manager_MaturityDate_Final` (`manager`,`MaturityDate_Final`),
KEY `idx_fi_details_MaturityDate_Final_manager` (`MaturityDate_Final`,`manager`)
) ENGINE=InnoDB AUTO_INCREMENT=234850 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE DEFINER=`root`#`localhost` PROCEDURE `fi_details_Worst_Date_Hartz_Brown`()
BEGIN
DROP TABLE IF EXISTS fi_details_temp;
CREATE table fi_details_temp AS (
SELECT
frm.fi_details.PortfolioCode,
frm.fi_details.MaturityDate_Final,
frm.fi_details.YieldWorst,
frm.fi_details.WorstDate_Final,
frm.fi_details.YieldMarket,
frm.fi_details.Symbol,
frm.fi_details.Security,
frm.fi_details.Coupon,
frm.fi_details.ParValue,
frm.fi_details.MarketValue,
frm.fi_details.TotalAdjustedCost,
frm.fi_details.AdjustedUnitCost,
frm.fi_details.YieldCost,
frm.fi_details.YieldCall,
frm.fi_details.YieldPut,
frm.fi_details.CallDate_Final
From
frm.fi_details
Where
frm.fi_details.manager = 'Hartz' And
frm.fi_details.PortfolioCode Like ('Brown%')
Group By
frm.fi_details.PortfolioCode,
frm.fi_details.MaturityDate_Final,
frm.fi_details.YieldWorst,
frm.fi_details.WorstDate_Final,
frm.fi_details.YieldMarket,
frm.fi_details.Symbol,
frm.fi_details.Security,
frm.fi_details.Coupon,
frm.fi_details.ParValue,
frm.fi_details.MarketValue,
frm.fi_details.TotalAdjustedCost,
frm.fi_details.AdjustedUnitCost,
frm.fi_details.YieldCost,
frm.fi_details.YieldCall,
frm.fi_details.YieldPut,
frm.fi_details.CallDate_Final
Order By
frm.fi_details.PortfolioCode,
frm.fi_details.WorstDate_Final );
SET #previousstate = NULL;
SELECT
if(#previousstate != frm.fi_details_temp.PortfolioCode, concat('*',#previousstate:= frm.fi_details_temp.PortfolioCode,'*'), frm.fi_details_temp.PortfolioCode) as 'Portfolio Code',
frm.fi_details_temp.MaturityDate_Final as 'Maturity Date',
frm.fi_details_temp.YieldWorst as 'Worst Yield',
frm.fi_details_temp.WorstDate_Final as 'Worst Date',
frm.fi_details_temp.YieldMarket as 'Yield to Market',
frm.fi_details_temp.Symbol,
frm.fi_details_temp.Security as 'Description',
frm.fi_details_temp.Coupon,
frm.fi_details_temp.ParValue as 'Par Value',
frm.fi_details_temp.MarketValue as 'Market Value xAI',
frm.fi_details_temp.TotalAdjustedCost as 'Adjusted Cost',
frm.fi_details_temp.AdjustedUnitCost as 'Unit Adjusted Cost',
frm.fi_details_temp.YieldCost as 'Yield to Cost',
frm.fi_details_temp.YieldCall as 'Yield to Call',
frm.fi_details_temp.YieldPut as 'Yield to Put',
frm.fi_details_temp.CallDate_Final as 'Next Call Date'
From frm.fi_details_temp;
DROP TABLE IF EXISTS fi_details_temp;
END

mysql: (pdo) continue at last position without using OFFSET

I wish to retrieve around 200 million profiles using PDO.
It is a partitioned table, so it does not have a primary key, it's sorted with INNODBs internal primary key.
I need to retrieve the data in internal sort order for performance, so using SORT BY some_id and to continue from there would not work for performance reasons.
Using LIMIT OFFSET would not work at all, OFFSET 100 million or more would take ages, the RAM is by far not enough to take all the terrabyte of table data into cache.
I would need something that fetches a chunk of rows, remembers the internal position and continues with next call.
Update
I was digging a bit and the problem seems familiar, it was solved in Oracle by having ROWID and ROWNUM which refer to the internal id.
It seems we have such an id in innodb as well but it's not queryable ?!
That sounds like a significant disadvantage of mysql for performant query.
Table def:
CREATE TABLE `members` (
`id` int(11) NOT NULL DEFAULT 0,
`intern_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`first_name` varchar(48) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`last_name` varchar(48) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`middle_name` varchar(48) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`l` varchar(196) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`i` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`ex` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`country_code` varchar(4) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`country_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`state_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`city_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`edu` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`nc` smallint(6) DEFAULT NULL,
`nj` smallint(6) DEFAULT NULL,
`jt` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`cn` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`email_address` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`fpe` tinyint(4) DEFAULT NULL COMMENT '1/0',
`pbu` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`cii` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`unmatched_facts` varchar(2048) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`dt_snapshot` datetime DEFAULT NULL,
`change_small` tinyint(4) DEFAULT NULL,
`change_significant` tinyint(4) DEFAULT NULL,
`jta` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`cna` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`cnia` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`ut_created` int(11) DEFAULT NULL ,
`reserve_int_2` int(11) DEFAULT NULL,
`reserve_vc1` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`reserve_vc2` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`reserve_vc_3` varchar(256) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
KEY `id` (`id`),
KEY `intern_id` (`intern_id`),
KEY `state_name` (`state_name`),
KEY `city_name` (`city_name`),
KEY `i` (`i`),
KEY `country_name` (`country_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
PARTITION BY KEY (`country_name`)
PARTITIONS 30

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

mySQL: Illegal mix of collations (utf8mb4_bin,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='

I'm trying to figure out why my CMS is giving me an error, but SQLFiddle and phpMyAdmin both run the query fine. Here is the fiddle:
http://sqlfiddle.com/#!9/cadc53/2
So the sample data:
CREATE TABLE IF NOT EXISTS `glinks_Sales` (
`TransactionID` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
`Billing_Name` char(255) COLLATE utf8mb4_bin DEFAULT NULL,
`Billing_Street` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Billing_City` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Billing_State` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Billing_PostCode` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Billing_Country` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Shipping_Name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Shipping_Street` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Shipping_City` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Shipping_State` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Shipping_PostCode` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Shipping_Country` varchar(255) COLLATE utf8mb4_bin NOT NULL,
`Been_Dispatched` int(11) NOT NULL,
`Postcode_Check_Status` varchar(10) COLLATE utf8mb4_bin DEFAULT NULL,
`Billing_Street_2` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
`Shipping_Street_2` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
`Items_In_Order` longtext COLLATE utf8mb4_bin,
`Email` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
`unique_id` int(11) NOT NULL,
`Order_Date` bigint(20) DEFAULT NULL,
`Method` char(10) COLLATE utf8mb4_bin DEFAULT NULL,
`Currency` char(3) COLLATE utf8mb4_bin DEFAULT NULL,
`Shipping_Amount` float DEFAULT NULL,
`Language` varchar(5) COLLATE utf8mb4_bin DEFAULT NULL,
`Cancelled` int(11) DEFAULT NULL,
`TrackingNumber` varchar(200) COLLATE utf8mb4_bin DEFAULT NULL,
`PostageCompany` varchar(200) COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
ALTER TABLE `glinks_Sales`
ADD PRIMARY KEY (`unique_id`);
INSERT INTO `glinks_Sales` (`TransactionID`, `Billing_Name`, `Billing_Street`, `Billing_City`, `Billing_State`, `Billing_PostCode`, `Billing_Country`, `Shipping_Name`, `Shipping_Street`, `Shipping_City`, `Shipping_State`, `Shipping_PostCode`, `Shipping_Country`, `Been_Dispatched`, `Postcode_Check_Status`, `Billing_Street_2`, `Shipping_Street_2`, `Items_In_Order`, `Email`, `unique_id`, `Order_Date`, `Method`, `Currency`, `Shipping_Amount`, `Language`, `Cancelled`, `TrackingNumber`, `PostageCompany`) VALUES ('8LL79654AS664260H', 'Andyííííééé Íóé', 'xxxx', 'Rudgwick', 'West Sussex', 'xxx', 'GB', 'Andyííííééé Íóé ', 'foo', 'x', 'West Sussex', 'x', 'GB', 1488558170, '1', '', '', 'test', 'ss#gmail.com', 15, 1488472336, 'PayPal', '', 10, 'en', NULL, 'foo', 'royal mail');
Then a sample query to grab
SELECT * FROM glinks_Sales WHERE (Shipping_Name = "Andyííííééé Íóé" OR Email = "Íóé" OR unique_id = "Íóé" OR TrackingNumber = "Íóé" OR PostageCompany = "Íóé")
That runs just fine. However, my Perl script that accesses the database does:
SELECT * FROM glinks_Sales WHERE (TransactionID = ?) ORDER BY Order_Date ASC'
...and it spits out the error:
Illegal mix of collations (utf8mb4_bin,IMPLICIT) and
(utf8_general_ci,COERCIBLE) for operation '='
I'm confused as to where it would be getting utf8_general_ci from? I must be missing something stupid, but I can't see it. Hopefully a fresh pair of eyes will help!
Thanks for any suggestions!
Collation mixes can be a pain. Try to SET collation_connection = 'utf8mb4_bin' before the query:
SET collation_connection = 'utf8mb4_bin';
SELECT * FROM glinks_Sales WHERE (TransactionID = ?) ORDER BY Order_Date ASC';
This sets the collation for the connection, before you run your query.
If that do not work, check other possible collation settings for database, server or connection. You find some hints here: https://stackoverflow.com/a/37298732/1363190