How do I import dump file containing "£" data into MySQL? - mysql

I'm trying to create a dump file from an MSAccess database to import in to a MySQL database. I can create the dump file, but when I try to import it I get this error Incorrect string value: '\xA325- R...' for column...
I'm not really sure what it means or how to fix it. I know the dump partially works as other tables and data get imported. The import gets to this error and then stops
I've tried setting this DEFAULT CHARACTER SET = utf8; on the table
I've also tried this on the column CHARACTER SET utf8 COLLATE utf8_unicode_ci
Here's an example from my dump file
CREATE TABLE Agent_Table(
AgentID INT NOT NULL AUTO_INCREMENT ,
Agent VARCHAR(255) ,
Archive VARCHAR(255) ,
AgentEmail VARCHAR(255) ,
AgentMobile VARCHAR(255) ,
PRIMARY KEY (`AgentID`)
)
I also tried
CREATE TABLE Agent_Table(
AgentID INT NOT NULL AUTO_INCREMENT ,
Agent VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
Archive VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci ,
AgentEmail VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
AgentMobile VARCHAR(255)CHARACTER SET utf8 COLLATE utf8_unicode_ci ,
PRIMARY KEY (`AgentID`)
)
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
I've tried a number of the utf8 options as well and still no joy
Nothing seems to work.
I'm writing a dump file because I've exhausted all other methods to try and to import/export the data
All the methods/tools I have tried all fail with some form of ODBC error I'd list them here but there are so many as I have been at this all day.
If anyone knows how to fix this problem or how else I can import this data I would appreciate it
UPDATE
The problems are £ and ` and ’ that I have seen so far. If I do a find and replace of those chars they no longer throw up errors. But it seems no matter what encoding I set the database to it just does not like these characters during the import.

Related

arabic word inserted in sql but with a warning sign

i tried to insert arabic word in MySql and it got inserted and when i displayed it it was there
but there was a warning 3720
for context here is the table:
create table SIGHTS ( S_no int not null PRIMARY KEY, S_name Nvarchar(30) not null);
and here is the inserted value:
insert into SIGHTS values (1,(N'كهف الهكبة'));
so? is it safe to ignore the warning or what should i do with it ?
it seems like you have used the default CHARACTER SET "utf8mb4" and the COLLATE utf8mb4_0900_ai_ci when you create the database. for more information, check this link out
when you create the database using the default "create" statement, which is
CREATE DATABASE _dbase;
it will execute the following statement adding the default CHARACTER SET
CREATE DATABASE _dbase CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
change the CHARACTER SET to "utf8" and the COLLATE to "utf8_general_ci" or "utf8_unicode_ci", you need to use the following statements :
CREATE DATABASE _dbase CHARACTER SET utf8 COLLATE utf8_general_ci;
or
CREATE DATABASE _dbase CHARACTER SET utf8 COLLATE utf8_unicode_ci;

MYSQL - Storing unicode characters (emoji) in TEXT column

When trying to insert a unicode emoji character (😎) to a MYSQL table, the insert fails due to the error;
Incorrect string value: '\\xF0\\x9F\\x98\\x8E\\xF0\\x9F...' for column 'Title' at row 1
From what I've red about this issue, it's apparently caused by the tables default character set, and possible the columns default character set, being set incorrectly. This post suggests to use utf8mb4, which I've tried, but the insert is still failing.
Here's my table configuration;
CREATE TABLE `TestTable` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`InsertDate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Title` text,
`Description` text,
`Info` varchar(250) CHARACTER SET utf8 DEFAULT NULL,
PRIMARY KEY (`Id`),
KEY `xId_TestTablePK` (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=2191 DEFAULT CHARSET=utf8mb4;
Note that the Title and Text columns dont have an explicitly stated character set. Initially I had no default table character set, and had these two columns were setup with DEFAULT CHARSET=utf8mb4. However, when I altered the table's default charset to the same, they were removed (presumably because the columns inherit the type from the table?)
Can anyone please help me understand how I can store these unicode values in my table?
Its worth noting that I'm on Windows, trying to perform this insert on the MYSQL Workbench. I have also tried using C# to insert into the database, specifying the character set with CHARSET=utf8mb4, however this returned the same error.
EDIT
To try and insert this data, I am executing the following;
INSERT INTO TestTable (Title) SELECT '😎😎';
Edit
Not sure if this is relevant or not, but my database is also set up with the same default character set;
CREATE DATABASE `TestDB` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
The connection needs to establish that the client is talking utf8mb4, not just utf8. This involves changing the parameters used at connection time. Or executing SET NAMES utf8mb4 just after connecting.

Converting MySQL database to UTF16

I am trying to create this table in a MySQL database
CREATE TABLE IF NOT EXISTS `Scania` (
`GensetType` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`EngineType` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`Engine60Hz` int(11) NOT NULL,
`Alternator` text CHARACTER SET utf16 COLLATE utf16_unicode_ci NOT NULL,
`PriceEur` float NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
However I receive a error message as
Error 1115 <42000> : Unknown character set: 'UTF 16'
I even tried to Alter the database but I received the same error
ALTER DATABASE nordhavn charset='utf16'
I tried searching online about other methods to convert the database but failed to find any possible solutions
The utf16 character set is available since MySQL 5.5 and up.
I guess you're using some earlier version.

Saving and retrieving URL from MYSQL

I am trying to save an URL in mysql db and get it back in my application. It gets saved properly.
http://i.>/00/s/NTAwWDUwMA==/$(KGrHqZHJC4E8fW,EPnUBPN1zoBtIQ~~60_1.JPG?set_id=8800005007
but while retrieving, all the '.' operators in the URL gets replaced by
http://i�domain�com/00/s/NTAwWDUwMA==/$�KGrHqZHJC4E8fW�EPnUBPN1zoBtIQ~~60_1�JPG?set_id=8800005007
Is there a way to remove those special characters. Attaching the create script for the table..
Im getting the url from the result set.
rs.getString(image)
delimiter $$
CREATE TABLE `livedeals` (
`ItemID` bigint(20) NOT NULL,
`category` varchar(200) CHARACTER SET latin1 NOT NULL,
`deal_like` int(4) NOT NULL,
`deal_dislike` int(4) NOT NULL,
`image` varchar(200) CHARACTER SET armscii8 COLLATE armscii8_bin NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8$$
any help would be helpful.
thanks.
If for some reason you can't change the character set of the table, then you could get that field the following way:
SELECT CAST(image AS CHAR CHARACTER SET utf8) AS image2 FROM livedeals

SQL Load Data Special Characters

I'm trying to import data into SQL from a CSV in PHP My Admin so it may be a PHP My Admin problem. The problem i'm having is that some of the columns use special characters for instance:
"Adán, Antonio"
Ends up as just "Ad".
The column structure is as follows:
CREATE TABLE IF NOT EXISTS `players` (
`player_name` varchar(255) COLLATE utf8 NOT NULL,
`player_nation` varchar(255) CHARACTER SET utf8 NOT NULL,
`player_club` varchar(255) CHARACTER SET utf8 NOT NULL,
`player_position` varchar(255) CHARACTER SET utf8 NOT NULL,
`player_age` tinyint(2) NOT NULL,
`player_dob` varchar(32) CHARACTER SET utf8 NOT NULL,
`player_based` varchar(255) CHARACTER SET utf8 NOT NULL,
`player_id` int(10) unsigned NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8;
I'm guessing it's something to do with the character set but mysql.com just suggests to alter the table to characters set utf8 which it already is.
Any ideas how else I can prevent this?
UPDATE
Inserting into the database is fine, so i'm guessing it's not to do with my table structure. It seems to be specifically to do with importing from a CSV.
This is the query for load data, as generated by PHP My Admin
LOAD DATA LOCAL INFILE 'C:\\Windows\\Temp\\php21E4.tmp' INTO TABLE `players` FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n'.
SOLUTION
I discovered the problem. My CSV was encoded with a Western Europe charset. After faffing around for a bit to convert it to UTF8 it imported just fine. Not an SQL problem at all.
Can you track where the truncation is happening, its quite possible that the issue isn't with your DB at all.
Try a simple insert into your DB table from the command line with the special chars and see if it succeeds.
Then try logging the various steps in the import to track where the issue occurs...