centos7下pymysql安裝


1.

安裝

添加mysql yum respository

添加 MySQL Yum Repository 到你的系統 repository 列表中,執行
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
yum localinstall mysql-community-release-el7-5.noarch.rpm

通過Yum安裝mysql

執行命令
yum install mysql-community-server

systemctl start mysqld

 

設置字符集

一般的,為了支持中文,我們應該講字符集設為 UTF-8, 執行
SHOW VARIABLES LIKE 'character%';
查看當前 MySQL 字符集

mysql> SHOW VARIABLES LIKE 'character%'; +--------------------------+----------------------------+ | 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 | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec

可以看到默認服務器的字符器是 latin1 ,對中文不友好。
修改 /etc/my.cnf 文件,添加字符集的設置

[mysqld] character_set_server = utf8 [mysql] default-character-set = utf8

重啟 MySQL ,可以看到字符集已經修改了

systemctl restart mysqld

參考來自:http://blog.csdn.net/whatlookingfor/article/details/52382472#%E8%AE%BE%E7%BD%AE%E5%AD%97%E7%AC%A6%E9%9B%86

 

新建數據庫 create database dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

新建表 CREATE TABLE test (usr_id INT(10),
    test_name CHAR(20),
    test_num INT(20))
    prim
    ENGINE=INNODB DEFAULT CHARSET=utf8;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM