next up previous contents
Next: 實機操作練習題 Up: MySQL 管理 Previous: 建立使用者   Contents

mysqld 設定檔

  1. mysql 的設定檔在 /etc/my.cfg,如果沒有特別要求,可以使用預設設定。
    [root@kvm8 ~]# cat /etc/my.cnf 
    [mysqld]
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    # Settings user and group are ignored when systemd is used (fedora >= 15).
    # If you need to run mysqld under a different user or group,
    # customize your systemd unit file for mysqld according to the
    # instructions in http://fedoraproject.org/wiki/Systemd
    user=mysql
    
    # Semisynchronous Replication
    # http://dev.mysql.com/doc/refman/5.5/en/replication-semisync.html
    # uncomment next line on MASTER
    ;plugin-load=rpl_semi_sync_master=semisync_master.so
    # uncomment next line on SLAVE
    ;plugin-load=rpl_semi_sync_slave=semisync_slave.so
    
    # Others options for Semisynchronous Replication
    ;rpl_semi_sync_master_enabled=1
    ;rpl_semi_sync_master_timeout=10
    ;rpl_semi_sync_slave_enabled=1
    
    # http://dev.mysql.com/doc/refman/5.5/en/performance-schema.html
    ;performance_schema
    
    [mysqld_safe]
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    
  2. 設定 mysql 伺服器 section 使用 utf-8 編碼。
    [root@kvm8 ~]# vim /etc/my.cnf
    [mysqld]
    collation-server=utf8_general_ci
    character-set-server=utf8
    
  3. 設定所有連線的用戶端預設使用 utf-8 編碼。
    [root@kvm8 ~]# vim /etc/my.cnf
    [client]
    default-character-set=utf8
    
  4. 設定 mysql 命令列用戶端預設使用 utf-8 編碼。
    [root@kvm8 ~]# vim /etc/my.cnf
    [mysql]
    default-character-set=utf8
    
  5. 重新啟動 mysqld。
    [root@kvm8 ~]# /etc/init.d/mysqld restart
    Stopping mysqld:                                  [  OK  ]
    Starting mysqld:                                  [  OK  ]
    
  6. 查詢變數是否生效?
    [root@kvm6 ~]# mysql -uroot -p123qwe
    mysql> show variables like '%character%';
    +--------------------------+----------------------------+
    | Variable_name            | Value                      |
    +--------------------------+----------------------------+
    | character_set_client     | utf8                       |
    | character_set_connection | utf8                       |
    | character_set_database   | utf8                       |
    | character_set_filesystem | binary                     |
    | character_set_results    | utf8                       |
    | character_set_server     | utf8                       |
    | character_set_system     | utf8                       |
    | character_sets_dir       | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    8 rows in set (0.00 sec)
    
    mysql>
    



2017-06-01