Home >Database >Mysql Tutorial >Why do you need to set the encoding of mysql to utf8 in ubuntu 16.04?

Why do you need to set the encoding of mysql to utf8 in ubuntu 16.04?

坏嘻嘻
坏嘻嘻Original
2018-09-15 09:21:233089browse

The content of this article is about why it is necessary to set the encoding of mysql to utf8 in ubuntu 16.04. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Introduction

ubuntu 16.04 mysql After installation, the default encoding of the database is not all utf8, some are latin1, which results in garbled characters when storing Chinese in the database, so it is still necessary to set the following database default encoding. Usually, one way to modify the encoding is to modify it directly in the interactive shell of mysql, but this modification is not permanent and will become invalid when exiting the interactive shell. The blogger below mainly introduces how to modify the persistence. The default encoding of mysql database

Steps

  • First you can log in to the interactive shell of mysql and enter the following command to view the current database Encoding method

    show variables like '%character%';

    Why do you need to set the encoding of mysql to utf8 in ubuntu 16.04?

    As can be seen from the above, after the mysql database is installed, it is not uniformly utf8

  • Exit just now Interactive shell, to modify the following configuration file

    • Enter the following command to open the first configuration file

      sudo vim /etc/mysql/conf.d/mysql.cnf

      in[mysql]Add the following configuration to the next line of the label

      default-character-set=utf8
    • Enter the following command to open the second configuration file

      sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

      Find[mysqld] tag, add the following configuration in the next line

      character-set-server=utf8
  • After the configuration file is successfully modified, enter the following command to restart the mysql service

    sudo service mysql restart

After restarting, check the default encoding method of the database

show variables like '%character%';

Why do you need to set the encoding of mysql to utf8 in ubuntu 16.04?

##OK, the configuration is complete

The above is the detailed content of Why do you need to set the encoding of mysql to utf8 in ubuntu 16.04?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn