mysql配置命令 CHARACTER_SET_%字元集設定

來源:互聯網
上載者:User

標籤:

參照:http://blog.csdn.net/mzlqh/article/details/7621307點擊開啟連結其實現在的ubuntu12.04 直接sudo apt-get install MySQL 就可以了,mysql-client會自動地為你裝上#查看mysql是否正在運行sudo netstat -tap | grep mysql如果是正在運行,則tcp 0 0 localhost.localdomain:mysql *:* LISTEN -重啟mysqlsudo /etc/init.d/mysql restart配置 MySQL 的管理員密碼:1 sudo mysqladmin -u root password newpassword 三、 MySQL服務 加入開機自啟動加入開機自啟動:        sudo update-rc.d mysql defaults從開機自啟動中移出:    sudo update-rc.d -f mysql remove四、遠端連線ubuntu下MySQLvim /etc/mysql/my.cnf找到bind-address = 127.0.0.1這行,注釋掉(如下)#bind-address = 127.0.0.1或者改為bind-address = 0.0.0.0允許任意IP訪問,或者自己指定一個IP地址。然後重啟 MySQLsudo /etc/init.d/mysql restart授權使用者能進行遠端連線grant all privileges on *.* to root@"%" identified by "password" with grant option;flush privileges;第一行命令解釋如下,*.*:第一個*代表資料庫名;第二個*代表表名。這裡的意思是所有資料庫裡的所有表都授權給使用者。root:授予root帳號。“%”:表示授權的使用者IP可以指定,這裡代表任意的IP地址都能訪問MySQL資料庫。“password”:分配帳號對應的密碼,這裡密碼自己替換成你的mysql root帳號密碼。第二行命令是重新整理許可權資訊,也即是讓我們所作的設定馬上生效。此時再遠端連線ubuntu下的MySQL應該能夠串連上了。解決mysql插入中文字元時出現亂碼[sql] view plain copy print?01.比如你可以在建庫時設定預設編碼為utf8:  02.create database mydb default character set utf8 collate utf8_general_ci;  [sql] view plain copy print?01.問題解決了,原因是在my.cnf中缺少了如下代碼:  02.[client]  03.default-character-set=utf8  04.[mysqld]  05.default-character-set=utf8  06.  07.  08.如果不加以上代碼,那麼即便MYSQL編譯安裝時指定的編碼是UTF8,那麼在建庫時其預設編碼仍是LATIN1,而由於字元集的繼承性,庫中的表也是LATIN1的了。  09.  10.  11.這裡列幾條命令,大家可以自己試下:  12.1.列出MYSQL支援的所有字元集:  13.SHOW CHARACTER SET;  14.  15.2.當前MYSQL伺服器字元集設定  16.SHOW VARIABLES LIKE ‘character_set_%‘;  17.  18.3.當前MYSQL伺服器字元集校正設定  19.SHOW VARIABLES LIKE ‘collation_%‘;  20.  21.4.顯示某資料庫字元集設定  22.show create database 資料庫名;  23.  24.5.顯示某資料表字元集設定  25.show create table 表名;  26.  27.6.修改資料庫字元集  28.alter database 資料庫名 default character set ‘utf8‘;  29.  30.7.修改資料表字元集  31.alter table 表名 default character set ‘utf8‘;  32.  33.8.建庫時指定字元集  34.create database 資料庫名 character set gbk collate gbk_chinese_ci;  35.  36.9.建表時指定字元集  37.CREATE TABLE `mysqlcode` (  38.`id` TINYINT( 255 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,  39.`content` VARCHAR( 255 ) NOT NULL  40.) TYPE = MYISAM CHARACTER SET gbk COLLATE gbk_chinese_ci;   ubuntu12.04 mysql設定檔路徑是/etc/mysql/my.cof [sql] view plain copy print?01.(2)用命令show variables like ‘character\_set\_%‘;查看當前字元集設定:  [sql] view plain copy print?01.修改mysql字元編碼出現Job failed to start解決辦法  02.   03.在python mange.py shell下填充MySQL資料庫的時候,發現漢字不能輸入。  04.於是要修改一下MySQL資料庫編碼。  05.   06.從網上找到如下資料:  07.$sudo gedit /etc/mysql/my.cnf  08.[client]下添加:  09.   10.default-character-set=utf8  11.   12.[mysqld]下添加:  13.   14.default-character-set=utf8  15.   16.        然後儲存退出  17.   18.$sudo service mysql restart  19.   20.        結果出現了Job failed to start  21.  www.2cto.com    22.----------------------------------------------------------------------------------------------------------------------------  23.可能是版本的問題,查5.5以後的版本對字元編碼方式修改的辦法,發現[mysqld]修改方法變了:  24.   25.[mysqld]下添加的應該為:  26.   27.character-set-server=utf8  28.   29.collation-server=utf8_general_ci  30.   31.儲存退出  32.   33.$sudo service mysql restart  34.   35.成功  36.   37.進入MySQL控制台:  38.   39.    show variables like ‘character%‘;  40.  www.2cto.com    41.+-----------------------------------+-----------------------------------+  42.| Variable_name                    | Value                                    |  43.   44.+-----------------------------------+-----------------------------------+  45.   46.| character_set_client           | utf8                                         |  47.   48.| character_set_connection | utf8                                         |  49.   50.| character_set_database    | utf8                                         |  51.   52.| character_set_filesystem   | binary                                    |  53.   54.| character_set_results         | utf8                                         |  55.  www.2cto.com    56.| character_set_server          | utf8                                         |  57.   58.| character_set_system         | utf8                                         |  59.   60.| character_sets_dir               | /usr/share/mysql/charsets/ |  61.   62.+------------------------------------+-----------------------------------+  63.   64.8 rows in set (0.00 sec)  65.   66.已經修改成功,做下記錄。  67.   68.    最後是這樣做的: [sql] view plain copy print?01. $sudo gedit /etc/ mysql/my.cnf  02.[client]下添加:  03.   04.default-character-set=utf8  05.[mysqld]下添加的應該為:  06.   07.character-set-server=utf8  08.   09.collation-server=utf8_general_ci  10.   11.儲存退出  12.   13.$sudo service mysql restart  14.   15.成功  但是中文亂碼的解決道路還沒有結束 [sql] view plain copy print?01.character_set_server 伺服器的預設字元集。  02.character_set_database 預設資料庫使用的字元集。當預設資料庫更改時,伺服器則設定該變數。如果沒有預設資料庫,變數的值同character_set_server。  03.show variables like ‘character%‘;  04.你用set @@character_set_database=utf8  05.show variables like ‘character%‘;  06.在看下character_set_server的值  成功了!

 

mysql配置命令 CHARACTER_SET_%字元集設定

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.