[jboss-cvs] jboss-docs/adminguide/docbook/en/modules ...

Sam Griffith sam.griffith at jboss.com
Mon Feb 19 13:11:09 EST 2007


  User: sgriffith
  Date: 07/02/19 13:11:09

  Added:       adminguide/docbook/en/modules  appendix-alternative_DBs.xml
  Log:
  
  
  Revision  Changes    Path
  1.1      date: 2007/02/19 18:11:09;  author: sgriffith;  state: Exp;jboss-docs/adminguide/docbook/en/modules/appendix-alternative_DBs.xml
  
  Index: appendix-alternative_DBs.xml
  ===================================================================
  <appendix id="appendix-install">
  	<section>
  		<title>How to Us Alternative Databases</title>
  		<para>
  			JBoss utilizes the Hypersonic database as it's default database. While this is good for development and prototyping, for production odds are that you or your company will require another database to be used for production. This appendix covers how to configure JBoss to use an alternatvie database. For our sample, we've choosen MySQL 5. It's free and readily available for most platforms in use today. 
  		</para>
  	</section>
  	
  	<section>
  		<title>
  			Setting up MySQL
  		</title>
  		<para>
  			MySQL is available for free from <literal>http://dev.mysql.com/downloads/ </literal> for most major OS's. For this setup sample, we've downloaded the lastest stable MySQL 5 version which happens to be MySQL 5.0.27. Follow the instructions for installing MySQL on your platform. 
  		</para>
  		<para>
  			MySQL is interacted with and administered by uinsg the <literal>mysql</literal> command. On OS X it is foudn in <literal>/usr/local/mysql/bin/mysql</literal>. To work with the <literal>mysql</literal> client you will most likely want to do it as a root user. To do so, use the<literal>-u</literal> or <literal>-user</literal> option. This allows you to specify the user name used when connecting to the database.
  			<programlisting>
  				$ mysql -u root
  				Welcome to the MySQL monitor.  Commands end with ; or \g.
  				Your MySQL connection id is 4 to server version: 5.0.27-standard
  
  				Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  
  				mysql>
  			</programlisting>
  		</para>
  		<para>
  			After you've connected to the db you'll need to create a database with the name <literal>jboss</literal>. To do so, use the <literal>create database</literal> command like so:
  			<programlisting>
  				mysql> create database jboss;
  				Query OK, 1 row affected (0.01 sec)
  			</programlisting>
  		</para>
  		<para>
  			Now that we've created a database we need to create a user for it so that we don't have to be root to access it. To do so, use the <literal>grant</literal> command like so:
  			<programlisting>
  				mysql> grant all privileges on jboss.* to sam at localhost identified by 'password';
  				Query OK, 0 rows affected (0.00 sec)
  			</programlisting>
  			With that grant command we created a user <literal>sam</literal> with a password <literal>password</literal>. User <literal>sam</literal> has access to everything in the <literal>jboss</literal> database.
  		</para>
  		<para>
  			We can look at the MySQL user table to see that <listeral>sam</literal> has been added.
  			<programlisting>
  				mysql> select user, host, password from mysql.user;
  				+------+-------------------+-------------------------------------------+
  				| user | host              | password                                  |
  				+------+-------------------+-------------------------------------------+
  				| root | localhost         |                                           | 
  				| root | sam-griffiths.sme |                                           | 
  				|      | sam-griffiths.sme |                                           | 
  				|      | localhost         |                                           | 
  				| sam  | localhost         | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | 
  				+------+-------------------+-------------------------------------------+
  				5 rows in set (0.01 sec)
  			</programlisting>
  			We can now login to the database as <literal>sam</literal> instead of <literal>root</literal>. Let's see that work. Make sure if your still logged into the MySQL client, that you exit by typing in <literal>exit</literal> at the MySQL prompt like so:
  			<programlisting>
  				mysql> exit
  				Bye
  			</programlisting>
  			Now you can login as the new user you created (in our case <literal>sam</literal>), like so:
  			<programlisting>
  				$ mysql -u sam --password=password
  				Welcome to the MySQL monitor.  Commands end with ; or \g.
  				Your MySQL connection id is 8 to server version: 5.0.27-standard
  
  				Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  
  				mysql>
  			</programlisting>
  			One thing to note is that we did not create our user with remote access permissions, so if you try to login from a remote machine to mysql with user <literal>sam</literal>, you will not be able too. See the MySQL documentation for further information on creating users with remote users.
  		</para>
  		<para>
  			So now we've downloaded and installed MySQL, logged in as <literal>root</literal>, created a database, created a user for ourselves, logged out as <literal>root</literal>, and finally logged in as our new user. We now have the database created for our application and server to use.
  		</para>
  	</section>
  	
  	<section>
  		<title>Adding the MySQL JDBC driver</title>
  		<para>
  			For the JBoss Application Server and our applications to use the MySQL database, we also need to install the MySQL JDBC drivers. They can be obtained from: <literal>http://www.mysql.com/products/connector/j/</literal>. For our 5.0.27 version download we need the 5.0 versions which can be obtained from <literal>http://dev.mysql.com/downloads/connector/j/5.0.html</literal>. The download contains documentation, etc. for the JDBC connector, but you really only need the <literal>mysql-connector-java-5.0.4-bin.jar</literal> file to get MySQL to be used by JBoss. You'll need to copy that jar file to your JBoss servers <literal>lib</literal> directory. We copied it to our <literal>server/default/lib</literal> directory. This file will now be loaded when JBoss starts up. So if you have the JBoss server running, you'll need to shut down and restart before this jar is available for the App Server to use.
  		</para>
  		<para>
  			How can we tell if JBoss found that new MySQL driver? The quickest way is to look at our JMX console to see check which JDBC driver is loaded. Open your browser and go to: <literal>http://localhost:8080/jmx-console</literal>. Towards the top of the page you'll see the JMImplementation domain. Choose the <literal>name=Default,service=LoaderRepository</literal> MBean. On the screen for the LoaderRepository MBean you'll see a MBean operation for <literal>displayClassInfo()</literal>. In it's parameterValue text field put in <literal> com.mysql.jdbc.Driver</literal> and click the "Invoke" button. you should see something like this:
  			<programlisting>
  				com.mysql.jdbc.Driver Information
  				Not loaded in repository cache
  
  
  				### Instance0 found in UCL: org.jboss.mx.loading.UnifiedClassLoader3 at 592141{ url=null ,addedOrder=2}
  			</programlisting>
  			While we haven't used the instance yet which would have caused the class to be loaded into the repository cache, we do have an instance, so JBoss knows about the driver and can see it. If we had used the class already we'd get much more information and it would look like this:
  			<programlisting>
  				???? TODO .... Need to load up sample app and capture this....
  			</programlisting>
  		</para>
  	</section>
  	
  	<section>
  		<title>
  			Creating a DataSource for MySQL
  		</title>
  		<para>
  			
  		</para>
  	</section>
  	
  	<programlisting>validate:
     ??? [java] ImplementationTitle: JBoss [Zion]
  	</programlisting>
  </appendix>
  
  



More information about the jboss-cvs-commits mailing list