久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

mysql數據庫應用管理+亂碼+字符集的示例分析

134次閱讀
沒有評論

共計 4463 個字符,預計需要花費 12 分鐘才能閱讀完成。

這篇文章主要為大家展示了“mysql 數據庫應用管理 + 亂碼 + 字符集的示例分析”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓丸趣 TV 小編帶領大家一起研究并學習一下“mysql 數據庫應用管理 + 亂碼 + 字符集的示例分析”這篇文章吧。

insert

測試表 mysql show create  table test\G

create  table test(

id int(4)  not  null   AUTO_INCREMENT,

name char(20) not null,

primary  key(id)

);

mysql insert    into  test(id,name)  value(1, hequan);

mysql select * from test;

mysql insert into test(name)  value(hequan  //ID 是自增的,可以插 name

mysql   insert into test  value(3, hequna),(4, hequan  // 不給列,直接按順序插入

 mysqldump -uroot -p123456 -B oldboy /tmp/oldboy_bak.sql  // 備份數據庫 備份用檢查一遍

grep -E -v #|\/|^$|–   /tmp/oldboy_bak.sql 

select           from            where 

mysql select id,name from test  where name= hequan  and/or  id=4;

mysql select id,name from test   limit 0,2; // 從第 0 行開始,查 2 行

mysql select id,name from test  where id 2 and id

mysql select id,name from test   order by id     asc/desc;

多表查詢

mysql select student.Sno,student.Sname,course.Cname,SC.Grade  from student,course,SC   where  student.Sno=SC.Sno and  course.Cno=SC.Cno  order by Sno ;

mysql explain  select * from test where name= hequan // 執行過程   判斷有么有走索引

possible_keys: NULL

rows: 2

mysql create index index_name on test(name);

possible_keys: index_name

rows: 1

update

mysql update   test set  name= xx   where   id=4   ;

 mysql -uroot -p123456 oldboy /tmp/oldboy_bak.sql // 恢復數據,增量恢復。

增量恢復  

#log-bin=mysql-bin   打開

/application/mysql/data/mysql-bin-hequan.000001

mysqlbinlog mysql-bin-hequan.000001

 mysqladmin -uroot -p123456  flush-log 切割日志

mysql-bin-hequan.000002

 mysqlbinlog -d oldboy mysql-bin-hequan.000001  bin.sql

把錯誤的語句刪除掉

mysql  -uroot -p123456 oldboy  bin.sql

binlog 只記錄主數據庫更改  

delete

mysql delete from  test  where id=3;  

mysql truncate table test;  // 清空表

更改表的字段

mysql alter table test add sex  char(4)  after name;  // 在 name 后面添加 sex  // first

mysql rename   table test to test1;

mysql alter table test1 rename to test;

mysql drop table test;

亂碼

統一字符集   /etc/my.cnf       改動 3 個           重啟服務

set  names  utf8;

cat  /etc/sysconfig/i18n              // 系統環境

LANG= zh_CN.UTF-8

vim  /etc/my.cnf                               // 服務器端 和客戶端

[client]

default-character-set=utf8

[mysqld]

character-set-server=utf8    //5.5

default-character-set=utf8   //5.1

[mysql]

default-character-set=utf8

show  variables like character_set%

SecureCRT 客戶端要更改為 utf8

  數據庫字符集         GBK   UTF-8   latin1

mysql show character set;

+———-+—————————–+———————+——–+

| Charset  | Description                           | Default collation   | Maxlen |

+———-+—————————–+———————+——–+

| utf8     | UTF-8 Unicode                      | utf8_general_ci     |      3 |

| gbk      | GBK Simplified Chinese       | gbk_chinese_ci      |      2 |

| latin1   | cp1252 West European        | latin1_swedish_ci   |      1 |

| utf8mb4  | UTF-8 Unicode               | utf8mb4_general_ci  |      4 |

mysql show  variables like character_set%

+————————–+————————————+

| Variable_name            | Value                              |

+————————–+————————————+

| character_set_client             | utf8                               |     客戶端

| character_set_connection    | utf8                               |   鏈接

| character_set_database       | latin1                             |   數據庫字符集

| character_set_filesystem      | binary                             |

| character_set_results            |   utf8                               |         返回結果

| character_set_server            | latin1                             |   服務器字符集

| character_set_system           | utf8                               |

| character_sets_dir                   | /application/mysql/share/charsets/ |

+————————–+————————————+

 mysql -uroot -p123456  –default-character-set=latin1

set  names  latin1

臨時生效

mysql 更改已有數據表的字符集,保留原有數據內容

環境:在應用開始階段沒有正確的設置字符集,在運行一段時間以后才發現存在不能滿足需求需要調整,又不想丟棄這段時間的數據,那么就需要進 行字符集的修改。字符集的修改不能直接通過 alter database character set *** 或者 alter table tablename character set *** 命令進行,這兩個命令都沒有更新已有記錄的字符集,而只是對新創建的表或者記錄生效。

那么已有記錄的字符集調整,需要怎么操作呢?

以下模擬的是將 latin1 字符集的數據庫修改成 GBK 字符集的數據庫的過程:

(1) 導出表結構

mysqldump -uroot -p –default-character-set=gbk    -d   name   createdb.sql

其中 –default-character-set=gbk 表示設置以什么字符集連接,- d 表示只導出表結構,不導出數據

(2) 手工修改 createdb.sql 中表結構定義中的字符集為新的字符集

sed -i  s#latin1#gbk#g   createdb.sql

(3) 確保記錄不再更新,導出所有記錄

mysqldump -uroot -p –quick –no-create-info –extended-insert –default-character-set=latin1 name data.sql

–quick: 該選項用于轉儲大的表。它強制 Mysqldump 從服務器一次一行的檢索表中的行,而不是檢索所有的行,兵輸出前將它緩存在內存中

–extended-insert: 使用包括幾個 values 列表的多行 Insert 語法,這樣使轉儲文件更小,重載文件更快

–no-create-info: 不屑重新創建每個轉儲表的 create table 語句

–default-character-set=latin1: 按照原有的字符集導出所有數據,這樣導出的文件中,所有中文都是可見的,不會保存成亂碼

(4) 打開 data.sql, 將 SET NAMES latin1 修改成 SET NAMES gbk

(5) 使用新的字符集創建新的數據庫

create database newdatabasename default charset gbk;

(6) 創建表,執行 createdb.sql

mysql -uroot -p newdatabasename createdb.sql

(7) 導入數據,執行 data.sql

mysql -uroot -p newdatabasename data.sql

(8) 查看之前,確認本地環境,是不是都改成了 gbk 模式。可以用   臨時更改   測試用

set names   gbk;

以上是“mysql 數據庫應用管理 + 亂碼 + 字符集的示例分析”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注丸趣 TV 行業資訊頻道!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-19發表,共計4463字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 乳源| 崇文区| 敖汉旗| 孟州市| 瓦房店市| 德钦县| 鄂伦春自治旗| 平塘县| 绿春县| 临洮县| 哈密市| 内黄县| 炎陵县| 满洲里市| 大庆市| 乡城县| 肃南| 隆德县| 定结县| 鄂托克前旗| 新宁县| 奉新县| 科技| 太康县| 延边| 南充市| 修文县| 海宁市| 丹阳市| 文水县| 哈尔滨市| 偃师市| 浠水县| 闵行区| 富民县| 涞源县| 盘锦市| 田阳县| 汨罗市| 温泉县| 屏南县|