目录
1.Linux mysql 设置
1.1修改配置文件如下 在 vim /etc/my.cnf
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
#
# 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
#
# 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
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
1.2重启mysql服务
命令:
centOS7 命令:
systemctl restart mysqld
centOS6命令:
service restart mysqld
2.设置数据局连接我这里是yml
server:
port: 8081
# 该配置的名称是固定的,不可以改变,否则将不能自动加载到数据源中
spring:
datasource:
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.3.102:3306/dkspace?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
username: root
password: root
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
connection-init-sqls : set names utf8mb4
maxPoolPreparedStatementPerConnectionSize: 2
data:
mongodb:
port: 27017
host: 192.168.3.102
database: test
# uri:
option:
socket-keep-alive: true
max-connection-idle-time: 60000
# connect-timeout: 36000
# min-connection-per-host: 5
# threads-allowed-to-block-for-connection-multiplier: 5
# max-wait-time: 120000
# socket-timeout: 0
# max-connection-life-time: 0
# heartbeat-socket-timeout: 36000
# heartbeat-connect-timeout: 36000
# min-heartbeat-frequency: 5
# heartbeat-frequency: 10
redis:
host: 192.168.3.102
password: 123456
port: 6379
jedis:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
timeout: 30000
database: 0
#设置文件的上传大小
servlet:
multipart:
max-file-size: 200MB
max-request-size: 200MB
resources:
static-locations: C:\home\img\
mybatis-plus:
type-aliases-package: com.space.mapper
mapper-locations: mapper/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 打印控制台sql
#httpclient
http:
#最大连接数
maxTotal: 100
#并发数
defaultMaxPerRoute: 20
#创建连接的最长时间
connectTimeout: 1000
#从连接池中获取到连接的最长时间
connectionRequestTimeout: 500
#数据传输的最长时间
socketTimeout: 10000
#提交请求前测试连接是否可用
staleConnectionCheckEnabled: true
#可用空闲连接过期时间,重用空闲连接时会先检查是否空闲时间超过这个时间,如果超过,释放socket重新建立
validateAfterInactivity: 3000000
aes:
encodeRules: dkspace
#日志文件配置
logging:
config: classpath:logback-dk.xml
# 阿里云短信配置
aliyun:
accessKeyId: LTAI5tNTsmKpEt2TyZMpDmSY
accessKeySecret: eaXPQ36vm8BoFk9pUU7J3slKG0HEEw
templateCode: SMS_217920587
singName: ****
privateKey: MIICeAIBADANBgkqhkiG9w0BAQEFAA
file:
path:
files: C:\home\
img: img
video: video
audio: audio
icon: icon
division: \
accessFile:
resourceHandler: /show/**
location: C:\home\
3.设置DruidConfig配置文件
import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import com.alibaba.druid.pool.DruidDataSource;
@Configuration
public class DruidConfig {
private Logger logger = LoggerFactory.getLogger(DruidConfig.class);
@Value("${spring.datasource.connection-init-sqls}")
private List<String> connectionInitSqls;
@Value("${spring.datasource.url}")
private String dbUrl;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Value("${spring.datasource.driver-class-name}")
private String driverClassName;
@Value("${spring.datasource.initialSize}")
private int initialSize;
@Value("${spring.datasource.minIdle}")
private int minIdle;
@Value("${spring.datasource.maxActive}")
private int maxActive;
@Value("${spring.datasource.maxWait}")
private int maxWait;
@Value("${spring.datasource.timeBetweenEvictionRunsMillis}")
private int timeBetweenEvictionRunsMillis;
@Value("${spring.datasource.minEvictableIdleTimeMillis}")
private int minEvictableIdleTimeMillis;
@Value("${spring.datasource.validationQuery}")
private String validationQuery;
@Value("${spring.datasource.testWhileIdle}")
private boolean testWhileIdle;
@Value("${spring.datasource.testOnBorrow}")
private boolean testOnBorrow;
@Value("${spring.datasource.testOnReturn}")
private boolean testOnReturn;
@Value("${spring.datasource.poolPreparedStatements}")
private boolean poolPreparedStatements;
@Value("${spring.datasource.maxPoolPreparedStatementPerConnectionSize}")
private int maxPoolPreparedStatementPerConnectionSize;
@Value("{spring.datasource.connectionProperties}")
private String connectionProperties;
@Bean //声明其为Bean实例
@Primary //在同样的DataSource中,首先使用被标注的DataSource
public DataSource dataSource() throws SQLException {
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(this.dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
//configuration
datasource.setInitialSize(initialSize);
datasource.setMinIdle(minIdle);
datasource.setMaxActive(maxActive);
datasource.setMaxWait(maxWait);
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setValidationQuery(validationQuery);
datasource.setTestWhileIdle(testWhileIdle);
datasource.setTestOnBorrow(testOnBorrow);
datasource.setTestOnReturn(testOnReturn);
datasource.setPoolPreparedStatements(poolPreparedStatements);
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
datasource.setConnectionInitSqls(connectionInitSqls);
// try {
String filters = null;
// datasource.setFilters(filters);
// } catch (SQLException e) {
// logger.error("druid configuration initialization filter", e);
// }
datasource.setConnectionProperties(connectionProperties);
return datasource;
}
}
设置完成重启服务既可以存储表情了。实测有效,数据库结果如图: