mysql general_log 开启_MySQL开启general_log跟踪数据执行过程

1. 设置general log保存路径

(1)注意在Linux中只能设置到 /tmp 或 /var 文件夹下,设置其他路径出错

mysql>set global general_log_file='/tmp/general.lg';

(2)windows:

mysql>set global general_log_file='D:\general.lg';//log文件放在D盘根目录下

2.开启general log模式

mysql>set global general_log=on;

3. 关闭general log模式

mysql>set global general_log=off;

在general log模式开启过程中,所有对数据库的操作都将被记录 general.log 文件

项目中遇到的问题:

在调试hibernate的时候发现设置hbm2ddl.auto设置为update是不能工作,eclipse中报如下错误:

Hibernate: insert into news (title, content) values (?, ?)

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [com.ericsson.ewanbao.News]

at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)

at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)

...................

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hibernate.news' doesn't exist

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

...............

问题分析:

经检查数据库发现,news表确实创建不成功,可见hbm2ddl.auto设置为update没有能够建立表

解决步骤:

1.把mysql的general-log打开,这样可以跟踪所有的sql语句;

2.再次执行程序,在general-log的最后发现如下sql语句:

3 Query  SHOW FULL TABLES FROM `hibernate` LIKE 'news'

3 Query  create table news (id integer not null auto_increment, title varchar(255), content varchar(255), primary key (id)) type=InnoDB

3 Query  SHOW FULL TABLES FROM `hibernate` LIKE 'PROBABLYNOT'

3 Query  SET autocommit=0

3 Query  SET autocommit=1

3 Query  SET autocommit=0

3 Query  insert into news (title, content) values ('???????', '???????????!')

3 Query  SHOW FULL TABLES FROM `hibernate` LIKE 'PROBABLYNOT'

3.可以发现hibernate已经发送了见表语句给数据库,为什么建表没有成功了?尝试拷贝这些建表语句到sql控制台执行,得到如下结果:

mysql> create table news (id integer not null auto_increment, title varchar(255), content varchar(255), primary key (id)

) type=InnoDB;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

for the right syntax to use near 'type=InnoDB' at line 1

4.可以看到是sql语句错误,经分析发现是hibernate.dialect的设置错误,原先设置为org.hibernate.dialect.MySQLInnoDBDialect,应该修改为org.hibernate.dialect.MySQL5InnoDBDialect

经测试,能够正常插入表

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值