SQL latin1 to utf-8 converting - mysql

I have a very big database with data stored on latin1 charsets.
On database with phpmyadmin if i use lines like this:
alter table TABLE_NAME modify FIELD_NAME blob;
alter database DATABASE_NAME charset=utf8;
alter table TABLE_NAME modify FIELD_NAME varchar(255) character set utf8;
All goes on. Text was converting.
But i have a lot of fields, tables. How to make it on all tables, fields? Is there a good convertation php script?
Also i uses on iconv, but no changes from latin1 to utf-8

create new database in utf8
restore your database structure
run "ALTER TABLE the_latin_one CONVERT TO CHARACTER SET utf8;" for all of your tables
create php script that create sql.txt like this
file_put_contents(PATH2."sql.txt","insert into ". $TABLE[0]. " values(". (rtrim($q_col,",") ).");\n",FILE_APPEND);
really you must create all tables insert query. using "show FULL tables where Table_type<>'VIEW'" and "set character set 'latin1'" query may help you for do this. if you have any problem write a comment for me ;)
in command line mysql -u xxx -p yourDB< sql.txt
i do this and solve my problem after 3 years :))

Related

Changing character set of MySQL tables

I have a MySQL table CHINESE with DEFAULT CHARSET=latin1 and it has a column NAME with CHARACTER SET latin1. I have huge amount to data stored in this table. Around a million rows. And, I want to execute the following commands on my database:
ALTER DATABASE <DATABASE_NAME> DEFAULT CHARACTER SET utf8
ALTER TABLE CHINESE DEFAULT CHARACTER SET utf8
ALTER TABLE CHINESE MODIFY NAME VARCHAR(30) CHARACTER SET utf8
Considering the fact that I have huge amount of data stored in this database. Should I run these commands on my database? Will these commands lock the database in any way?
I am using Java to query and insert values in database. Will appending ?useUnicode=yes&characterEncoding=UTF-8 in URI string help me?
It will take a long time,
I think is it is the best that you export a .sql out and don't the trans-code there replace latin1 to utf8 , then import back in a temp table. Finally swap the name of they.

MySQL thinks "e" is the same as "é"?

I have a table with the following columns:
ID
name
Both are indexed, both must be unique.
One post has name "ussé".
I try to insert a new post with the name "usse" and get the following error:
[MySQL][ODBC 5.3(w) Driver][mysqld-5.6.16-log]Duplicate entry 'usse' for key 'name'.
What the...? MySQL can't tell those two strings apart?
Is there some way to fix this?
All my text fields have "utf8 - default collation" selected. Does this make a difference? If I need to change it to something else, is there a way to do it quickly for all tex fields in all databases? There are so many that I would like to avoid going through them manually if I can.
My connection string:
DRIVER={MySQL ODBC 5.3 Unicode Driver}; SERVER=localhost;DATABASE=example; UID=example; PASSWORD=example; OPTION=3;
As you can see here :
How to convert an entire MySQL database characterset and collation to UTF-8?
here's a list of commands :
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

phpmyadmin MySQL data stored as ascii values in certain table

my host has just updated phpmyadmin to version 4.0.3. I don't know if it is related to the following problem.
I have a table 'users' which stores user data for the site and all data is now being stored as numbers. Where I had a username of 'rich' it is now '72696368' which is it's ascii code.
Any ideas why this might have happened? I have a lot of tables and have checked them all, it is only the users table that has been modified. It is not critical as I can still log in and accept new users etc but I would like to know why this is happening.
Thanks a lot
EDIT The collation is utf8_general_c
try adding this snippet to the script you are running in the line in which you create the schema
DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
for example :
CREATE SCHEMA IF NOT EXISTS `my_schema` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

PHPMyAdmin and mySQL: Insert into existing database, not create new one. Error "Can't create database; database exists"

I recently went to backup a database and got the following error "#1007 - Can't create database 'wordpress_8'; database exists".
I have the following line in the beginning of my sql file:
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: 'wordpress_8'
--
CREATE DATABASE wordpress_8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE wordpress_8;
What do I need to change this to in order to insert the subsequent data into the existing "wordpress_8" database rather than create a new one?
Thanks!
To change which database you're using, you use the USE statement. In this case, USE wordpress_8;. Then the actual data needs to be inserted into the tables using INSERT statements.
To ensure a clean restore, I would add:
DROP DATABASE wordpress_8;
Else you're potentially merging two databases, which can get ugly.
Delete
CREATE DATABASE wordpress_8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
and Imropt again ))

Mysql change column collation and character set of information schema

I want to change column collation and character set of system database information_schema...
Can anyone give any input on how to do this? Is there any special priviledges i need for this
To change the character set and collation for all columns in an existing table, use:
ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name [COLLATE collation_name];
As far as I know, you cannot run ALTER TABLE commands on the tables in information_schema. Instead you will probably want to take a look at the character_set_* variabes. You can see which variables are set to which values in your MySQL server with a show variables command:
show variables like "character_set_%";
The variable that has to do with meta data in MySQL, such as the information_schema tables, is the character_set_system variable. I think the my.cnf is the right place to set it.
There's more information on this page: UTF-8 for Metadata.
For ordinary tables, you change the character set of a table with an ALTER TABLE command:
alter table some_table convert to character set utf8;
To do this, you will need the "alter" privilege.
You can see which privileges your MySQL server supports with a show privileges command, and you can see which privileges are granted to your current user with a show grants command.
alter table some_table convert to character set utf8;
awesome that worked great as far as i can tell for me, now i can use chinese in that tables!! and i can remove all the utf8_encode() utf8_decode() throughout my site!