乱码原因:是因为数据库的编码格式不是utf8格式的
解决方法
方法一:在创建数据库的时候将编码格式选择为utf8,如图
注意:如果如果当前数据库的编码不是utf8需要新建数据库才可以
方法二:修改mysql安装目录下的my.ini文件
将文件中的红色部分改为utf8 (注意是utf8,不是utf-8)
[client]
port=3306
[mysql]
default-character-set=utf8
# SERVER SECTION
# ———————————————————————-
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306
#Path to installation directory. All paths are usually resolved relative to this.
basedir=”C:/Program Files/MySQL/MySQL Server 5.5/”
#Path to the database root
datadir=”C:/ProgramData/MySQL/MySQL Server 5.5/Data/”
# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB
修改完这个文件后,以后再创建数据库就不用再手动选择utf8编码了