Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Some solutions to mysql garbled code sharing

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "sharing some solutions to mysql garbled". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

A new library has been created, which is encoded by default. Then import the utf8-encoded tables and data. It turned out to be all garbled. It still doesn't work to change the encoding of the sql file. Finally, it was found that the utf8 code was not set when building the library. As a result, with the following record, the problem can be solved.

Build the database:

CREATE DATABASE `mydb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

Also record the relevant actions:

Import sql Fil

-h localhost-u root-p mydbname

< data.sql; 导出sql mysqldump -h localhost -u root -p --default-character-set=utf8 mydbname >

Data.sql

Build a table:

DROP TABLE IF EXISTS `mytablename`

SET @ saved_cs_client = @ @ character_set_client

SET character_set_client = utf8

CREATE TABLE `mytablename` (

`id`int (10) unsigned NOT NULL auto_increment

`int10` int (10) unsigned NOT NULL

`char2`char (2)

`varchar100` varchar (100) NOT NULL

PRIMARY KEY (`id`)

) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

SET character_set_client = @ saved_cs_client

Insert data:

LOCK TABLES `mytablename` WRITE

INSERT INTO `mytablename` (`id`, `int10`, `char2`, `varchar100`) VALUES (1Min 123456, "ab", "adsfsadf")

UNLOCK TABLES

Create a user (set permissions, password)

GRANT ALL PRIVILEGES ON *. * TO 'user'@'localhost' IDENTIFIED BY' 123456'

GRANT ALL PRIVILEGES ON *. * TO 'user'@'127.0.0.1' IDENTIFIED BY' 123456'

ALL PRIVILEGES is all permissions. Optional: select,insert,update,delete,create,drop, etc.

*. * means: some library. Some table

Localhost can only log in locally, if set to:% for any location

Change the password:

Mysqladmin-u root-p password 456789

View all users:

Select host,user from mysql.user

Finally, in order to avoid the occurrence of garbled codes, we should do the following: file coding + page coding + database coding + application server coding + unified operating system coding.

This is the end of the content of "sharing some solutions to mysql garbled". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report