一、配置篇
1.链接信息配置
jdbc.properties
1 2 3 4
| driver=com.mysql.jdbc.Driver url=jdbc:mysql: username=root password=root
|
springboot:
1 2 3 4
| spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql: spring.datasource.username=root spring.datasource.password=root
|
注意:
1.低版本的mysql对应mybatis逆向工程:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration> <classPathEntry location="D:\study\software\java\jdbc\mysql-connector-java-5.1.35.jar"/> <context id="tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.10.102:3306/springboot" userId="root" password="root"> </jdbcConnection>
<javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver>
<javaModelGenerator targetPackage="com.zhkucst.springboot.model" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <sqlMapGenerator targetPackage="com.zhkucst.springboot.mapper" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="com.zhkucst.springboot.mapper" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <table tableName="t_student" domainObjectName="Student" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
</context> </generatorConfiguration>
|
jdbc.properties
1 2 3 4
| driver=com.mysql.cj.jdbc.Driver url=jdbc:mysql://192.168.10.102:3306/springboot?useUnicode=true&characterEncoding=utf8&useJDBCComplliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC username=root password=root
|
springboot:
1 2 3 4
| spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://192.168.10.102:3306/springboot?useUnicode=true&characterEncoding=utf8&useJDBCComplliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC spring.datasource.username=root spring.datasource.password=root
|
注意:
1.高版本的mysql对应mybatis逆向工程:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration> <classPathEntry location="D:\study\software\java\jdbc\mysql-connector-java-8.0.25.jar"/> <context id="tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://192.168.10.102:3306/springboot?useUnicode=true&characterEncoding=utf8&useJDBCComplliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC" userId="root" password="root"> <property name="nullCatalogMeansCurrent" value="true"/> </jdbcConnection>
<javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver>
<javaModelGenerator targetPackage="com.zhkucst.springboot.model" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <sqlMapGenerator targetPackage="com.zhkucst.springboot.mapper" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="com.zhkucst.springboot.mapper" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <table tableName="t_student" domainObjectName="Student" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
</context> </generatorConfiguration>
|
二、错误解决篇
1.数据库本身数据乱码
mysql数据库字符集默集latin
需要手动设置成utf-8
2.调用数据库数据乱码
在db.priperties中在url末尾添加
1
| ?useUnicode=true&characterEncoding=utf8
|
三、安装配置篇
第一步:上传软件包到linux操作系统
第二步:对mysql压缩包进行解压操作:tar.gz
1
| tar –zxf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz
|
第三步:移动mysql文件夹到/usr/local目录下并更名为mysql
1
| mv mysql-5.6.44-linux-glibc2.12-x86_64.tar /usr/local/mysql
|
第四步:创建一个mysql用户并更改/usr/local/mysql目录权限(用户和组)
1
| useradd –r –s /sbin/nologin mysql
|
第五步:初始化数据库
1
| [root@localhost /usr/local/mysql/]
|
初始化之前需要安装autoconf库【命令:yum-y install autoconf】
第六步:移除mariadb-libs库文件
1
| [root@localhost /usr/local/mysql/]
|
第七步:移动support-files目录下的mysql.server脚本到/etc/init.d目录一份=>service
1
| [root@localhost /usr/local/mysql/]
|
第八步:启动mysql脚本
第九步:设置密码并测试mysql数据库
1 2 3
| bin/mysqladmin -u root password 'root'; bin/mysql -uroot -p Enter Password:root
|
第十一步:mysql远程连接Navicate
授予其他用户访问权限:
1 2
| mysql> grant all privileges on . to root@"%" identified by "root"; mysql> flush privileges;
|
第十二步:
My.conf配置:
1
| cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
|
注释不带绿色,授予my.cnf具有644权限
附:
拒绝远程连接:
回收权限:
1
| Mysql>revoke all privileges,grant option from 'root'@”%”;
|