Mysql 百万数据limit 查询

SELECT * FROM db_storage limit 1085031,20
查询时间为0.486s

SELECT * FROM db_storage WHERE ID >= (select id from db_storage limit 1085031, 1) limit 20

SELECT a.* FROM db_storage a INNER JOIN (SELECT id FROM db_storage LIMIT 1085031,20) b ON a.id = b.id;

上面两个类似,为0.27s左右,此处需要优化pagehelper 逻辑

Mysql数据库在服务器上优化

[client]
port=3306
socket=/tmp/mysql/mysql.sock
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

[mysqld]
port=3306
user=mysql
socket=/tmp/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log-error=error.log
#允许最大连接数
max_connections=200
#允许连接失败的次数,这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10

# innodb 优化
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 缓存池
innodb_buffer_pool_size=8G
# 脏页占innodb_buffer_pool_size的比例时,触发刷脏页到磁盘
# 25%~50%
innodb_max_dirty_pages_pct=30
# 限制Innodb能打开的表的数据,如果库里的表特别多的情况,请增加这个。这个值默认是300
innodb_open_files = 500
# 此参数确定写日志文件所用的内存大小,以M为单位。缓冲区更大能提高性能,但意外的故障将会丢失数据。MySQL开发人员建议设置为1-8M之间
innodb_log_buffer_size = 2M

#开启记录慢查询 设置慢查询界定时间为1秒
long_query_time=1
slow-query-log=On
slow_query_log_file="mysql_slow_query.log"

transaction_isolation = READ-COMMITTED
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
# lower_case_table_names = 1 这个不能要

#skip-grant-tables

在linux中使用yum安装mysql 安装完成后可以通过下面的语句查询各个路径。

show global variables like "%dir%";

springboot 以jar包方式在windows服务中运行的初始配置

1.在任务管理器中可以看到java运行的进程名

2.初始化winsw的名称及winsw.xml配置信息

 

@echo off

setlocal & pushd

set /p project_name=Jar名称(英文):

set /a sum=0

 set /a jarName=null

echo Jar名称:%project_name%

set filepath=%cd%

if not exist "%filepath%%project_name%_java.exe" (   
    goto copy 
) else ( 
    goto check_winsw 
)

:copy
    echo -----------------------------重命名java.exe----------------------------------
    echo 项目名称对应的java文件不存在
    echo 复制Java.exe 到当前文件夹并命名
    copy "%JAVA_HOME%binjava.exe" "%filepath%%project_name%_java.exe"
    if not exist "%filepath%%project_name%_java.exe" ( 
        echo 文件复制失败,JAVA_HOME环境变量不存在 
        echo --------------------------------------------------------------------------
        pause
        goto :eof
    ) else ( 
        echo --------------------------------------------------------------------------
        goto :check_winsw 
    )


:check_winsw
    echo -----------------------------检查winsw.exe----------------------------------
    if not exist "%filepath%%project_name%_win.exe" if not exist "%filepath%winsw.exe" ( 
        echo --------------------------------winsw 文件不存在------------------------------
        pause
        goto :eof
    )
    if not exist "%filepath%%project_name%_win.exe" ( 
        echo --------------------------------%project_name%_win.exe 文件不存在------------
        echo --------------------------------重命名winsw.exe 文件不存在------------
        ren "%filepath%winsw.exe" "%project_name%_win.exe"
        pause
        goto :check_winsw
    )
    goto :check_winsw_xml

:check_winsw_xml
    echo -----------------------------检查winsw.xml----------------------------------
    if not exist "%filepath%%project_name%_win.xml" if not exist "%filepath%winsw.xml" ( 
        echo --------------------------------winsw.xml 文件不存在------------------------------
        pause
        goto :eof
    )
    if not exist "%filepath%%project_name%_win.xml" ( 
        echo --------------------------------%project_name%_win.xml 文件不存在------------
        echo --------------------------------重命名winsw.xml 文件不存在------------
        ren "%filepath%winsw.xml" "%project_name%_win.xml"
        pause
        goto :check_winsw_xml
    )
    goto :renameJar

:renameJar
    for /r "%filepath%" %%a in (*.jar) do (
        SET "jarName=%%~nxa"
        echo %%~dpa%%~nxa
        echo %%~dpa
        echo %%~nxa
        set /a sum +=1
    )
    echo -------------------------------- 共%sum% 个jar------------------------------
    if %sum% NEQ 1 (
        echo --------------------------------Jar 包不存在或者数量大于1------------------------------
        pause
        goto :eof
    ) else (
        ren "%filepath%%jarName%" "%project_name%.jar"
        echo --------------------------------Jar 包重命名成功------------------------------
    )
    goto :configXml

:configXml
    echo -------------------------------------配置xml文件--------------------------------------------
    setlocal enabledelayedexpansion

    for /f "skip=2 tokens=1-4 delims=^<^>" %%i in ('find /i "id" %project_name%_win.xml') do (
        set id=%%k
        echo id当前值为!id!
    )

    for /f "skip=2 tokens=1-4 delims=^<^>" %%i in ('find /i "name" %project_name%_win.xml') do (
        set name=%%k
        echo name当前值为!name!
    )

    for /f "skip=2 tokens=1-4 delims=^<^>" %%i in ('find /i "description" %project_name%_win.xml') do (
        set description=%%k
        echo description当前值为!description!
    )

    for /f "skip=2 tokens=1-4 delims=^<^>" %%i in ('find /i "executable" %project_name%_win.xml') do (
        set executable=%%k
        echo executable当前值为!executable!
    )

    for /f "skip=2 tokens=1-4 delims=^<^>" %%i in ('find /i "arguments" %project_name%_win.xml') do (
        set arguments=%%k
        echo arguments当前值为!arguments!
    )

    pause
    chcp 65001
    for /f "tokens=* delims=" %%a in (%project_name%_win.xml) do (
        set "content=%%a"
        call set "content=%%content:<id>!id!</id>=<id>!project_name!</id>%%"
        call set "content=%%content:<name>!name!</name>=<name>!project_name!</name>%%"
        call set "content=%%content:<description>!description!</description>=<description>!project_name!_winsw</description>%%"
        call set "content=%%content:<executable>!executable!</executable>=<executable>!project_name!_java</executable>%%"
        call set "content=%%content:<arguments>!arguments!</arguments>=<arguments>-Dfile.encoding=utf8 -jar !project_name!.jar</arguments>%%"
        echo !content!>>result.xml
    )
    del %project_name%_win.xml
    ren result.xml %project_name%_win.xml
    chcp 936

endlocal & popd
pause

 

运行后输入项目名称,要求是英文,不要有空格
执行过程:

1.复制JAVA_HOME 中的java.exe到当前目录,并将名称修改成项目名称
2.检查winsw.exe信息,并进行命名
3.检查winsw.xml信息,并进行命名
4.判断当前目录jar包的数量,有且只允许有一个
5.重命名当前的jar文件
6.修改.xml文件中的信息

 

下面就是 winsw install 及winsw start

WINSW 的使用注意事项

1.WINSW 的xml 文件最好为ANSI编码(windows电脑上)

2.WINSW使用时最好重新命名下winsw.exe和winsw.xml。相同名称情况下可能会有冲突,我有两个没有改名字,第三个服务死活启动不了。