[关闭]
@weixin 2014-08-20T21:04:11.000000Z 字数 2804 阅读 1367

rest api study notes 1

rest JRA hibernate spring


this article is my study note of this tutorial - rest tutorial.
the github link is here : prjoect source

prepare database

  1. yum install mysql-server mysql
  2. chkconfig mysqld
  3. /etc/init.d/mysqld status
  4. /etc/init.d/mysql start
  5. mysqladmin -u root password 123456

login mysql as root : mysql -u root -p , then it would prompt u to input password.

  1. create user 'rest_demo'@'localhost' identified by 'rest_demo'

notice, I also tried

  1. create user 'rest_demo'@'localhost' identified password by 'rest_demo'

it prompts me to input a 41 hex hash value. that's not what I want.
see this link mysql creat user


the issue is here :

  1. CREATE TABLE `podcasts` (
  2. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  3. `title` varchar(145) NOT NULL,
  4. `feed` varchar(145) NOT NULL,
  5. `insertion_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  6. `description` varchar(500) DEFAULT NULL,
  7. `link_on_podcastpedia` varchar(145) DEFAULT NULL,
  8. PRIMARY KEY (`id`),
  9. UNIQUE KEY `feed_UNIQUE` (`feed`)
  10. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
"invalid default value for 'insertion_date'. There are some explaination : [invalid default value][4] finally find the issue :
  1. `insertion_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
after change it to:
  1. `insertion_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
then it works great.
  1. mvn jetty:run -Djetty.port=8888 -DskipTests=true

after open the /podcasts, got something like this :

53169 [qtp901914516-16] DEBUG o.c.d.r.f.LoggingResponseFilter - Response {
"status" : 500,
"code" : 5001,
"message" : "org.hibernate.exception.SQLGrammarException: Could not open connection",
"link" : "here will be the blo post url",

after dig into code, I also found :

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'rest_demo'@'localhost' to database 'rest_demo'\n\tat

after some investigation, it seems this is a privilege issue, I login as 'rest_demo', then found this :

mysql> use rest_demo;
ERROR 1044 (42000): Access denied for user 'rest_demo'@'localhost' to database 'rest_demo'

this happens becaues I ran the 'DumpRESTdemoDB.sql' by using the root account, so the user 'rest_demo' doesn't have enough privilege to access the 'rest_demo' database.

need to grant all privileges to the user 'rest_demo'.

mysql> grant all privileges on rest_demo.* to 'rest_demo'@'localhost' identified by 'rest_demo' with grant option;
Query OK, 0 rows affected (0.00 sec)

after that, finally I saw the result. so happy.

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注