0

SO has the same question 'mysql change default table charset to database charset' asked before .I used the second answer to change my database default character set to utf-8 .

alter database mydatabase default character set utf8 collate utf8_general_ci;

But when I exported the database using phpMyAdmin ,though at the top I have

/*!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 utf8 */;

but for queries I have something like

--
-- Table structure for table `paras`
--

CREATE TABLE IF NOT EXISTS `paras` (
  `p_id` int(11) NOT NULL AUTO_INCREMENT,
  `para` text,
  PRIMARY KEY (`p_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

where charset=latin1 .IMO it shouid be set to UTF-8.Am I confusing something or what is the correct way?

Community
  • 1
  • 1
Naveen
  • 7,944
  • 12
  • 78
  • 165
  • You've changed the *default* charset of the *database*, but tables and finally individual columns all have a charset setting too. – deceze Jan 26 '14 at 10:59
  • @deceze: SO do I need do execute the queries for individual tables.Isn't there a single query? – Naveen Jan 26 '14 at 11:06

1 Answers1

3

In MySQL individual columns have a actual charset setting. Anything else just has a default charset setting. This means if a charset is not explicitly specified for a column, the default charset of its table is used. If there is none, the default of the database it's in is used. If there is none, the server default is used. Each one of server, database and table has an individual default setting which overrides the next higher default.

What you did was simply set the default for the database, but your tables still have individual defaults set. You'll have to change it for each individual table.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • :I got it.MySQL has set them to the default to `latin` so can I leave it as it is though I may be entering data in UTF-8 format in future?Currently my tables are empty. – Naveen Jan 26 '14 at 11:16
  • If you want to store UTF-8 encoded text, the column or one of its next higher defaults will have to be set to utf8. – deceze Jan 26 '14 at 11:18