Home > Database > Mysql Tutorial > body text

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

坏嘻嘻
Release: 2018-09-15 09:21:23
Original
3018 people have browsed it

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%';
    Copy after login
    Copy after login

    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
      Copy after login

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

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

      sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
      Copy after login

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

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

    sudo service mysql restart
    Copy after login

After restarting, check the default encoding method of the database

show variables like '%character%';
Copy after login
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!