美文网首页
[MySQL]报错:java.sql.SQLException:

[MySQL]报错:java.sql.SQLException:

作者: techhow | 来源:发表于2017-10-23 11:38 被阅读0次
    问题原因

    MySQL's utf8
    only supports basic multilingual plane, and you need to use utf8mb4
    instead
    :

    解决方法
    1. 建表的时候添加如下限制:ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
    2. 在my.cnf上修改如下:
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
    [client]
    default-character-set=utf8mb4
    [mysql]
    default-character-set = utf8mb4
    [mysqld]
    character-set-client-handshake = FALSE
    character-set-server = utf8mb4
    collation-server = utf8mb4_unicode_ci
    init_connect='SET NAMES utf8mb4'
    
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
     
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    # These are commonly set, remove the # and set as required.
    # basedir = .....
    # datadir = .....
    # port = .....
    # server_id = .....
    # socket = .....
     
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
     
    #log-slow-queries= /usr/local/mysql/log/slowquery.log
    
    1. 重启mysql服务。备注:官方说不需要重启mysql,但只有重启才可以。
    参考资料
    1. https://stackoverflow.com/questions/13653712/java-sql-sqlexception-incorrect-string-value-xf0-x9f-x91-xbd-xf0-x9f
    2. http://www.cnblogs.com/lowwen/p/5645242.html
    

    相关文章

      网友评论

          本文标题:[MySQL]报错:java.sql.SQLException:

          本文链接:https://www.haomeiwen.com/subject/ysnouxtx.html