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.
Related
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;
Hi I recently changed the hosting provider for my website. When doing this I exported the mysql database I had in my previous cpanel phpmyadmin. It had CHARACTER SET latin1 and COLLATE latin1_swedish_ci. After I importing it to my new phpmyadmin I saw there was an issue with displaying the characters written in Czech ě ř č ů which appeared as question mark or weird symbols etc. I also wasn't able to insert these letters at first but after changing the table CHARSET to utf8 I'm able to insert them. But how do I export the data from my old database and import it in the new one without messing up the data? Here's what the database looks like:
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
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: `sambajiu_samba`
--
-- --------------------------------------------------------
CREATE TABLE `bookings` (
`id` int(11) NOT NULL,
`fname` varchar(100) NOT NULL,
`surname` varchar(100) DEFAULT NULL,
`email` varchar(255) NOT NULL,
`telephone` varchar(100) NOT NULL,
`age_group` varchar(100) DEFAULT NULL,
`hear` varchar(100) DEFAULT NULL,
`experience` text,
`subscriber` tinyint(1) DEFAULT NULL,
`booking_date` varchar(255) DEFAULT NULL,
`lesson_time` varchar(255) NOT NULL,
`booked_on` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
ALTER TABLE `bookings` ADD PRIMARY KEY (`id`);
ALTER TABLE `bookings` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=345;
Czech is not handled by latin1. It would be better to use utf8mb4 (which can handle virtually everything in the world). Outside of MySQL, it is called "UTF-8".
How did you do the "export" and "import"? What is in the file? Can you get the hex of a small portion of the exported file -- we need to check what encoding was used for the Czech characters.
As for "as question mark or weird symbols", see question marks and Mojibake in Trouble with UTF-8 characters; what I see is not what I stored .
Your hex probably intended to say
Rezervovat trénink zda
In the middle of the hex is
C383 C2A9
Which is UTF-8 for é. When you display the data, you might see that, or you might see the desired é. In the latter case, the browser is probably "helping" you by decoding the data twice. For further discussion on this, see "double encoding" in the link above.
"Fixing the data" is quite messy:
CONVERT(BINARY(CONVERT(CONVERT(
UNHEX('52657A6572766F766174207472C383C2A96E696E6B207A6461')
USING utf8mb4) USING latin1)) USING utf8mb4)
==> 'Rezervovat trénink zda'
But, I don't think we are finished. that acute-e is a valid character in latin1. You mentioned 4 Czech accented letters that, I think, are not in Latin1. Latin5 and dec8 may be relevant.
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.
I'm trying to save a string of all 4-byte characters to a MySQL utf8mb4 column.
UPDATE `uga_libsteam`.`group_history` SET `source_name`='𝓔𝓶𝓹𝓻𝓮𝓼𝓼' WHERE `group_id`='103582791430024497' and`history_id`='1655';
The characters are as follows.
http://www.fileformat.info/info/unicode/char/1d4d4/index.htm
http://www.fileformat.info/info/unicode/char/1D4F6/index.htm
http://www.fileformat.info/info/unicode/char/1D4F9/index.htm
http://www.fileformat.info/info/unicode/char/1D4FB/index.htm
http://www.fileformat.info/info/unicode/char/1D4EE/index.htm
http://www.fileformat.info/info/unicode/char/1D4FC/index.htm
However, when I run this query, I receive this error.
Executing:
UPDATE `uga_libsteam`.`group_history` SET `source_name`='𝓔𝓶𝓹𝓻𝓮𝓼𝓼' WHERE `group_id`='103582791430024497' and`history_id`='1655';
Operation failed: There was an error while applying the SQL script to the database.
ERROR 1366: 1366: Incorrect string value: '\xF0\x9D\x93\x94\xF0\x9D...' for column 'source_name' at row 1
SQL Statement:
UPDATE `uga_libsteam`.`group_history` SET `source_name`='𝓔𝓶𝓹𝓻𝓮𝓼𝓼' WHERE `group_id`='103582791430024497' and`history_id`='1655'
Here is my schema. Title is deprecated and eventually I'll be removing it. Previously, source_name and target_name were both utf8/utf8_unicode_ci, but I was able to fix that last night.
CREATE TABLE `group_history` (
`group_id` bigint(20) unsigned NOT NULL,
`history_id` bigint(20) unsigned NOT NULL,
`type_id` tinyint(2) DEFAULT NULL,
`title` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`display_date` datetime DEFAULT NULL,
`year_offset` tinyint(2) unsigned DEFAULT NULL,
`month` tinyint(2) unsigned DEFAULT NULL,
`day` tinyint(2) unsigned DEFAULT NULL,
`time` time DEFAULT NULL,
`source_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`source_steam_id` bigint(20) DEFAULT NULL,
`target_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`target_steam_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`group_id`,`history_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Why is the database rejecting characters that should be legal to input? Do I have to switch to UTF-32 for this to work?
Previously, source_name and target_name were both utf8/utf8_unicode_ci, but I was able to fix that last night.
I guess you tried to fix the charset by changing the table's default charset.
ALTER TABLE group_history DEFAULT CHARSET utf8mb4;
This does NOT change the charset of existing columns of the table, it only changes the table's default charset, which will be used only if you subsequently add new columns. Existing columns are still encoded with the old charset, utf8.
To convert the existing columns, you must use:
ALTER TABLE group_history CONVERT TO CHARACTER SET utf8mb4;
This will rewrite all the existing string columns using the new character set, and subsequently allow you to insert 4-byte character values.
Thanks to this answer, I had to run this before inserts into my database would work...
SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;
So good news is I now have inserts into my database working, bad news is I'm writing this for a PHP application and PDO isn't working and is saving ??????? to the database.
Edit: Thanks to this question, I figured out the solution to my PHP question as well. This is what my code looked like before:
$dsn = "mysql:host=$this->hostname;port=$this->port;dbname=$this->database;charset=utf8mb4";
try {
$this->pdo = new \PDO($dsn, $this->username, $this->password, array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION));
$this->pdo->exec('SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;');
} catch (\PDOException $e) {
die($e->getMessage());
}
This is what I had to change it to:
$dsn = "mysql:host=$this->hostname;port=$this->port;dbname=$this->database;charset=utf8mb4";
try {
$this->pdo = new \PDO($dsn, $this->username, $this->password, array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci'));
} catch (\PDOException $e) {
die($e->getMessage());
}
Trying alter table through this query
ALTER TABLE `outlooks` CHANGE `description` `description` TEXT CHARSET=utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL;
but getting error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL' at line 1
That's not the right syntax. The error is pretty clear about where the problem is, too.
According to the manual it should look like:
ALTER TABLE `outlooks`
CHANGE `description`
`description` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL;
However this won't convert the content of the data table from ISO-8859-1 to UTF8. You're probably looking for:
ALTER TABLE `outlooks` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;