There is a view table created with a mis-encoded query.
Interestingly, the results of "show create table" and "mysqldump" were different.
The result of "show create table" showed the incorrectly encoded part with a question marks.
However, the result of "mysqldump" shows the incorrectly encoded part as the value of bytes.
I want to show like mysqldump result.
mysql> show create table test_view;
CREATE ALGORITHM=UNDEFINED DEFINER=`tester`#`%` SQL SECURITY DEFINER VIEW
`test_view` AS select `test_table`.`idx` AS `Index`,
`test_table`.`tel` AS `???IP` from `test_table` order by `test_table`.`idx`
Use mysqldump...
/*!50001 VIEW `test_view` AS
select `test_table`.`idx` AS `Index`,`test_table`.`tel` AS `�ъ⑹踰IP`
from `test_table`
order by `test_table`.`idx` */;
In MySQL character_set_results configuration variable decides the encoding of the results sent back to the client. Use the same character set from the CLI interface as you use from mysqldump to get the same results. set names also sets this variable.
Related
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 :))
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 ))
I want to dump only view object from mysql databases in the following format :
CREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=`root`#`localhost` SQL SECURITY DEFINER VIEW
`v_sample` AS
SELECT
`a`.`id` AS `id`,
`a`.`code` AS `active`,
`a`.`title` AS `title`
FROM t_test a;
the script above is the best practive i have ever had... no problem with privilege issue like can not drop the temporary view table, etc
Notes :
I found inside the dump script database, that mysql treat the view object as table first then will be replaced by the real view.
You need to use SHOW CREATE VIEW statement.
SHOW CREATE VIEW v_sample
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!
how do i determine what a mysql db's charset is set to? in the cli?
SHOW CREATE DATABASE db-name
Will show you the default character set for the database,
SHOW CREATE TABLE db-name.table-name
Will show you the character set for a specific table (along with a lot of other information).
You can use the command "show table status",
it will show you a lot of information (including character set) about your tables
mysql> show table status;