Scala Slick MySQL utf8mb4 support

Source: Internet
Author: User

Language Scala

SQL Package Slick 3.2.0

MySQL Database

Database Synchronization Program Error

string ' \xf0\x9f\x87\xb5\xf0\x9f ... '  for ' content ' 1

This error is too much to see, emoji characters and utf-8 incompatible, utf8mp4 character set support emoji

Source Library (provided by another company) changed the character set of the table, did not notify us, from the library and the source library character set, synchronization with partial character error

Change MySQL, change the synchronization program character set can

Simple to change MySQL

ALTER Table Table  CONVERT to CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Synchronization services are implemented in Scala and referenced by slick

Slick compared to utf8mb4 the whole network is not much information, but the idea and the traditional Java project consistent

If the official configuration has no relevant parameters, there are INI solutions, so there are two ways


The original connection mode is

Val dest_db = Database.forurl ("jdbc:mysql://127.0.0.1:3306/table?characterencoding=utf-8&charset =UTF8MB4""root"" 123456 "" Com.mysql.jdbc.Driver")


Two ways to solve the problem


1 manual run Execution INI statement

Val dest_db = Database.forurl ("jdbc:mysql://127.0.0.1:3306/table?characterencoding=utf-8&charset =UTF8MB4""root"" 123456 "" Com.mysql.jdbc.Driver") origin_db.run (SQL"""SET NAMES utf8mb4 COLLATE Utf8mb4_unicode_ci"" ". As[int])

2 starting with the JDBC INI

Val origin_db = Database.forurl ("jdbc:mysql://127.0.0.1:3306/table?charset=utf8mb4;init=\ "SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci\"", user ="Root", password ="123456", Driver ="Com.mysql.jdbc.Driver", executor = Asyncexecutor ("orgindb", minthreads=1, queuesize=Ten, maxthreads=Ten, maxconnections=Ten), keepaliveconnection=true)

Scala Slick MySQL utf8mb4 support

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.