Java program into the MySQL database when the characters into garbled

Source: Internet
Author: User
Tags character set command line commit flush ini mysql client thread mysql database

Today depressed day, Java program to insert data to MySQL is not garbled, database installation also selected encoding for UTF8 (and my program coding format consistent). But the insertion of data into garbled, rather depressing.

Reason: The code in the MySQL configuration file is not changed to UTF8;

Solution: In the MySQL installation directory to find My.ini file, the inside two involved in the coding of the place to UTF8, as follows:

# MySQL Server Instance Configuration File #----------------------------------------------------------------------# Generated by the MySQL Server Instance Configuration Wizard # # Installation Instructions #------------------- ---------------------------------------------------# on Linux and can copy this file to/etc/my.cnf to set global O ptions, # MYSQL-DATA-DIR/MY.CNF to set server-specific options # (for this installation) or to # ~/.MY.CNF to set U  
Ser-specific options. # on Windows and should keep this file in the installation directory # of your server (e.g. C:\Program files\mysql\ MySQL Server x.y).   
To # Make sure the ' server reads ' config file use the ' startup option # '--defaults-file '.  
# to run Run the ' Server from the ' command line, execute the ' in ' a # command line shell, e.g. # mysqld--defaults-file= "C:\Program files\mysql\mysql server X.y\my.ini" # to install the server as a Windows servi Ce manually, execute this in a # command line shell, e.g. # mysqld--install mysqlxy--defaults-file= "C:\Program files\mysql\mysql Server X.y\my.ini" # # and then execute this  
In a command line shell to start the server, e.g. # net start Mysqlxy # # Guildlines for editing this file #-----------------------------------------------------  
-----------------# In this file, you can use all long options supports.  
# If you are want to know the options a program supports, the start of the program # with the '--help ' option.  
# More detailed information about the individual options can also being # found in the manual. # # CLIENT Section #----------------------------------------------------------------------# # The following  
The options would be read by the MySQL client applications. # that is only the client applications shipped by the MySQL are guaranteed # to read this section. If you are want your own MySQL client program to # Honor this values, you need to specify it as an option during the # MySQL client library initialization. # [client] port=3306 [MySQL] <span style= "color: #ff0000;" >default-character-set=utf8 </span> # SERVER Section #--------------------------------------------- -------------------------# The following options would be read by the MySQL Server. Make sure that # See more highlights in this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Java/# You have installed the SER  
Ver correctly (above) so it reads this # file. # [MYSQLD] # The TCP/IP Port the MySQL Server would 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:/Documents and Setting S/all users/application data/mysql/mysql Server 5.5/data/"# The default character set that'll be used when a n EW schema or table is # CReated and no character the set is defined <span style= "color: #ff0000;" >character-set-server=utf8 </span># The default storage engine that'll be used when create new tables When Default-storage-engine=innodb # Set the SQL mode to strict sql-mode= "Strict_trans_tables,no_auto_create_ User,no_engine_substitution "# The maximum amount of concurrent sessions the MySQL server'll # Allow.  One of these connections would be reserved for a user with # SUPER privileges to allow the administrator to login even if  
The # connection limit has been reached. MAX_CONNECTIONS=100 # Query Cache is used to cache SELECT results and later return them # without actual execut ing the same query once again. Having the query # cache-enabled may-in significant speed improvements, if your # have a lot of identical Es and rarely changing tables. The # "Qcache_lowmem_prunes" status variable to check if the value # are high enOugh for your load. # note:in Case your tables change very often or if your queries are # textually different every time, the query cache m  
ay result in a # slowdown instead of a performance improvement. Query_cache_size=0 # The number of open tables for all threads.  
Increasing this value # increases the number of file descriptors that mysqld requires. # therefore you have to make sure to set amount of open files # allowed to at least 4096 in the variable -limit "in *" section [Mysqld_safe] table_cache=256 # Maximum size for internal (in-memory) temporary tables. If A table # grows larger than this value, it's automatically converted to disk # based table this limitation be for A single table.  
There can be many # of them. tmp_table_size=17m # How many threads we should keep in a cache for reuse. When a client # disconnects, the client's threads are put in the cache if there aren ' t # more than Thread_cache_siZe threads from before. This is greatly reduces # The amount of thread creations needed if you have a lot of new # connections.  
(Normally this doesn ' t give a notable performance # improvement if you have a good thread implementation.) Thread_cache_size=8 #*** MyISAM Specific Options # The maximum size of the temporary file MySQL is allow  
Ed to use while # recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE.  
# If The file-size would be bigger than this, the index would be created # through the key cache (which is slower). myisam_max_sort_file_size=100g # If The temporary file used for fast index creation would is bigger # than usin  G The key cache by the amount specified and then prefer the # Key cache method. This is mainly used to force long character keys into # large tables to ' slower key cache method to create the Inde X. myisam_sort_buffer_size=34m # Size of the Key buffer, used to cache index blocks foR MyISAM tables. # do not set it larger than 30% of your available memory, as some memory # are also required by the OS to cache rows. Even if you are not using # MyISAM tables, your should still set it to 8-64m as it'll also be # used for internal temp  
Orary disk tables.  
key_buffer_size=25m # Size of the buffer used for doing full table scans of MyISAM tables.  
# Allocated per thread, if a full scan is needed.  read_buffer_size=64k read_rnd_buffer_size=256k # This buffer was allocated when MySQL needs to rebuild the index In # REPAIR, Optimze, ALTER table statements as as-in-LOAD DATA INFILE # into a empty table.  
It is allocated each thread so to careful with # large settings. sort_buffer_size=256k #*** INNODB Specific Options * * Use this option if you have a MyS QL server with InnoDB support enabled # but ' do not ' to use it.  
This would save memory and disk # and speed up some things. #skip-I.NNODB # Additional Memory pool that are used by InnoDB to store metadata # information.  If InnoDB requires more memory for this purpose it'll # start to allocate it from the OS. As this is fast enough on most # recent operating systems, you normally does not need to change this # value.  
Show INNODB STATUS would display the current amount used. INNODB_ADDITIONAL_MEM_POOL_SIZE=2M # If set to 1, InnoDB'll flush (fsync) The transaction logs to the # disk At a commit, which offers full ACID behavior. If you are are # willing to compromise this safety, and you are running small # transactions, with may set this to 0 or 2 t o Reduce disk I/O to the # logs. Value 0 means that "log is" written to "log file and #" log file flushed to disk approximately once per sec Ond. Value 2 # means the "log is written" to "log file at each commit, but the log # file ' only flushed to disk Approxim  
Ately once per second. Innodb_flush_log_at_trx_commit=1 
      
# The size of the buffer InnoDB uses for buffering log data. As soon as # It's full, InnoDB'll have to flush it to disk. As it is flushed # once per second anyway, it does don't make sense to have it very large # (even with long transactions  
). INNODB_LOG_BUFFER_SIZE=1M # InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and # row data. The bigger your set this less disk I/O is needed to # Access data in tables. On a dedicated database server your may set this # parameter up to 80% of the machine physical size. Do not set it # too large, though, because competition of the physical memory could # cause paging in the operating Syst  Em. Note This on 32bit systems your # might is limited to 2-3.5g of the user level memory the per process, and so does not # set it too h  
IgH. innodb_buffer_pool_size=47m # Size of each log file in a log group. You should set the combined size # of log files to about 25%-100% of your buffer pool size to Avoid # unneeded buffer pool flush activity on log file overwrite.  
However, # Note that a larger logfile size would increase the time needed for the # recovery process. innodb_log_file_size=24m # Number of threads allowed inside the InnoDB kernel. The optimal value # depends highly on the application, hardware as as as the OS # Scheduler properties.  
A too high value may leads to thread thrashing. Innodb_thread_concurrency=8
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.