Conventional query optimizer searches for the best plan using a cost model based on data statistics. However, its performance is compromised for two reasons. First, it is difficult, even impossible, to precisely estimate the costs of different relational operators, due to the complexity of database system and competition of computing resources. Second, the optimizer must produce an execution plan within a limited time budget. As a result, only a portion of the search space is explored by applying some common knowledge defined as rules. To reduce the complexity of query optimization and performance tuning, in this paper, we propose the DeepPlaner, which learns query optimization rules in an unsupervised way. DeepPlaner includes a pair of encoder and decoder trained using recurrent neural networks. The encoder accepts new queries expressed as serialized strings, while the decoder generates possible execution plans. The cost model along with the query plan search strategy is directly learned from scratch using running statistics. Given an ad hoc query, DeepPlaner is able to generate a query plan comparable to the one generated by state-of-the-art query optimizer of the existing database system.