Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Using MySQL

ashortland edited this page Jul 25, 2012 · 14 revisions

Here's the lowdown on switching Yana2 to use MySQL as opposed to H2.

Install MySQL

There are many ways to install MySQL, of course, here's a quick start for Redhat/CentOS Linux:

Install the MySQL server software:

 [root@centos62-rundeck-tomcat ~]# yum -y install mysql-server
 .
 .
 .
 Installed:
   mysql-server.x86_64 0:5.1.61-4.el6                                                                                                                                      

 Dependency Installed:
   mysql.x86_64 0:5.1.61-4.el6                                                     perl-DBD-MySQL.x86_64     0:4.013-3.el6                                                    

 Dependency Updated:
   mysql-libs.x86_64 0:5.1.61-4.el6                                                                                                                                        

 Complete!

Turn on and start the MySQL server:

 [root@centos62-rundeck-tomcat ~]# chkconfig mysqld on
 [root@centos62-rundeck-tomcat ~]# chkconfig --list mysqld
 mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
 [root@centos62-rundeck-tomcat ~]# service start mysqld
 start: unrecognized service
 [root@centos62-rundeck-tomcat ~]# service mysqld start
 Initializing MySQL database:  Installing MySQL system tables...
 OK
 Filling help tables...
 OK
 
 To start mysqld at boot time you have to copy
 support-files/mysql.server to the right place for your system
 
 PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
 To do so, start the server, then issue the following commands:
 
 /usr/bin/mysqladmin -u root password 'new-password'
 /usr/bin/mysqladmin -u root -h centos62-rundeck-tomcat password 'new-password'
 
 Alternatively you can run:
 /usr/bin/mysql_secure_installation
 
 which will also give you the option of removing the test
 databases and anonymous user created by default.  This is
 strongly recommended for production servers.
 
 See the manual for more instructions.
 
 You can start the MySQL daemon with:
 cd /usr ; /usr/bin/mysqld_safe &
 
 You can test the MySQL daemon with mysql-test-run.pl
 cd /usr/mysql-test ; perl mysql-test-run.pl
 
 Please report any problems with the /usr/bin/mysqlbug script!

                                                            [  OK  ]
 Starting mysqld:                                           [  OK  ]

Set the MySQL root user's password:

 [root@centos62-rundeck-tomcat ~]# /usr/bin/mysqladmin -u root password 'password'
 [root@centos62-rundeck-tomcat ~]# /usr/bin/mysqladmin -u root -p -h centos62-rundeck-tomcat password 'password'
 Enter password: 

Check that the database is accessible:

 [anthony@centos62-rundeck-tomcat ~]$ mysql -p -u root -h centos62-rundeck-tomcat
 Enter password: 
 Welcome to the MySQL monitor.  Commands end with ; or \g.
 Your MySQL connection id is 11
 Server version: 5.1.61 Source distribution
 
 Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
 Oracle is a registered trademark of Oracle Corporation and/or its
 affiliates. Other names may be trademarks of their respective
 owners.
 
 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
 mysql> show databases;
 +--------------------+
 | Database           |
 +--------------------+
 | information_schema |
 | mysql              |
 | test               |
 +--------------------+
 3 rows in set (0.03 sec)
 
 mysql> exit
 Bye

Create the empty Yana2 database

 [anthony@centos62-rundeck-tomcat ~]$ mysql -p -u root -h centos62-rundeck-tomcat
 Enter password: 
 Welcome to the MySQL monitor.  Commands end with ; or \g.
 Your MySQL connection id is 12
 Server version: 5.1.61 Source distribution
 
 Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
 Oracle is a registered trademark of Oracle Corporation and/or its
 affiliates. Other names may be trademarks of their respective
 owners.
 
 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
 mysql> create database yana;
 Query OK, 1 row affected (0.00 sec)
 
 mysql> create user 'yana'@'%' identified by 'yana';
 Query OK, 0 rows affected (0.00 sec)
 
 mysql> select user,host from mysql.user;
 +------+-------------------------+
 | user | host                    |
 +------+-------------------------+
 | yana | %                       |
 | root | 127.0.0.1               |
 |      | centos62-rundeck-tomcat |
 | root | centos62-rundeck-tomcat |
 |      | localhost               |
 | root | localhost               |
 +------+-------------------------+
 6 rows in set (0.00 sec)
 
 mysql> drop user ''@'localhost';
 Query OK, 0 rows affected (0.00 sec)
 
 mysql> drop user ''@'centos62-rundeck-tomcat';
 Query OK, 0 rows affected (0.00 sec)
 
 mysql> select user,host from mysql.user;
 +------+-------------------------+
 | user | host                    |
 +------+-------------------------+
 | yana | %                       |
 | root | 127.0.0.1               |
 | root | centos62-rundeck-tomcat |
 | root | localhost               |
 +------+-------------------------+
 4 rows in set (0.00 sec)
 
 mysql> grant all on yana.* to 'yana'@'%';
 Query OK, 0 rows affected (0.00 sec)
 
 mysql> exit
 Bye

Setup MySQL in Tomcat

The simplest way is to drop in the MySQL connector jar into $CATALINA_BASE/lib:

 [tomcat@centos62-rundeck-tomcat ~]$ cp ~/mysql-connector-java-5.1.21/mysql-connector-java-5.1.21-bin.jar apache-tomcat-7.0.29/lib
 [tomcat@centos62-rundeck-tomcat ~]$ jar tvf apache-tomcat-7.0.29/lib/mysql-connector-java-5.1.21-bin.jar com/mysql/jdbc/Driver.class
    692 Thu Jun 21 15:41:44 PDT 2012 com/mysql/jdbc/Driver.class

Configure Yana2 to use the database

Assuming you're using the Groovy based configuration file, update it as follows:

 // MySQL configuration:
 dataSource { 
    driverClassName = "com.mysql.jdbc.Driver"
    url = "jdbc:mysql://centos62-rundeck-tomcat:3306/yana"
    username = "yana"
    password = "yana"
 }

Bring up Yana2 and check that the tables have been created:

[anthony@centos62-rundeck-tomcat ~]$ mysql -p -u yana -h centos62-rundeck-tomcat
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.1.61 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use yana;
Database changed
mysql> show tables;
+------------------------+
| Tables_in_yana         |
+------------------------+
| attribute              |
| child_node             |
| filter                 |
| node                   |
| node_attribute         |
| node_type              |
| node_type_relationship |
| node_value             |
| persistent_logins      |
| registration_code      |
| user_role              |
| webhook                |
| yana_role              |
| yana_user              |
+------------------------+
14 rows in set (0.12 sec)

mysql> 
Clone this wiki locally