1. 程式人生 > >Ubuntu16.04 MySQL的安裝及設定資料庫編碼為UTF-8

Ubuntu16.04 MySQL的安裝及設定資料庫編碼為UTF-8

檢視MySQL是否安裝

      netstat –tap | grep mysql

安裝MySQL

      sudo apt-get install mysql-server mysql-client

      輸入root使用者密碼

測試是否安裝成功

      netstat –tap | grep mysql 


基本操作

登入MySQL   mysql –u root –p

退出MySQL    quit;

檢視當前資料庫   show databases;  

建立資料庫test    create database test; 

選擇test資料庫    use test;  

顯示當前資料庫中的表  show tables;

建表create table student(

      -> id int not nullprimary key,

      -> name char(8),

      -> age char(8),

      -> birthday date );

顯示資料庫表的結構    describe 表名;

刪庫   drop test;

刪表   drop table 表名;


設定MySQL資料庫編碼為UTF-8

 登陸後檢視資料庫當前編碼:SHOW VARIABLES LIKE 'character%';
 修改/etc/mysql/my.cnf (預設安裝路徑下) (標籤下沒有的新增,有的修改)

  [mysqld]

     character_set_server=utf8

     [mysql]

     default-character-set= utf8

     [client]

     default-character-set = utf8

重啟MySQL服務 service mysql restart
檢視資料庫編碼:SHOW VARIABLES LIKE 'character%';