Sunday, November 18, 2007

MySQL macport install on Mac OS X Tiger

I have installed mysql5 macport on the MacBookPro laptop running OS X Tiger 10.4.

There are a few steps that needs to be done once the port is installed. These steps are not documented (see Ticket #12694 on macports.org). So, after reading a few blogs and analyzing mysql startup error messages, I figured out what needs to be done in order to get it running. That info might be useful to others, so I’ve decided to publish the solution here.

First of all, we need to create the initial database database

$ sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql

Here is the output of the command:


$ sudo ./mysql_install_db --user=mysql

Installing MySQL system tables...
071118 0:06:29 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive
OK
Filling help tables...
071118 0:06:29 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive
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:
/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h my-computer.local password 'new-password'
See the manual for more instructions.
You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com


Next, I’ve tried to start the database and got this error message:

$ sudo /opt/local/lib/mysql5/bin/mysqld_safe
mkdir: /opt/local/var/run: No such file or directory
chown: /opt/local/var/run/mysql5: No such file or directory
chmod: /opt/local/var/run/mysql5: No such file or directory
Starting mysqld daemon with databases from /opt/local/var/db/mysql5
STOPPING server from pid file /opt/local/var/db/mysql5/mykola-dzyubas-computer-2.local.pid
071118 00:27:12 mysqld ended

I’ve created /opt/local/var/run and /opt/local/var/run/mysql5 folders:

sudo mkdir /opt/local/var/run
sudo chmod g+w /opt/local/var/run
sudo mkdir /opt/local/var/run/mysql5
sudo chown mysql /opt/local/var/run/mysql5

Once it is done, the mysql server has started successfully

$ sudo /opt/local/lib/mysql5/bin/mysqld_safe &
Starting mysqld daemon with databases from /opt/local/var/db/mysql5

Here is a quick check that the database server is up:

$ mysqladmin5 -u root -p ping
Enter password:
mysqld is alive

In case you don't have mysql binary files in your path, please edit ~/.profile and add /opt/local/bin to the path:

# Setting the path for MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH

By default all scripts refer to mysql command, however the installation package creates mysql5. To fix that, create mysql symbolic link that points to mysql5.

$ cd /opt/local/bin
$ ln -s mysql5 mysql

To improve security of the mysql server configuration, please run mysql_secure_installation5 script and configure mysql password for root, network access, etc:




$ cd /opt/local/bin
$ ./mysql_secure_installation5

mykola-dzyubas-computer-2:/opt/local/bin mykola$ ./mysql_secure_installation5




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
... Success!

Cleaning up...



All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Thursday, November 1, 2007

How To Run Java EE 5 Tutorial Examples On Mac

I spent some time configuring Java environment on Mac. Here are a few tips on how to get it going.

The Max OS X comes with Java 5 installed. So, here are main steps:

* Download Java EE 5 Tutorial package from http://java.sun.com/javaee/5/docs/tutorial/information/download.html

* Download Sun Java System Application Server 9.1 from http://java.sun.com/javaee/downloads/. I downloaded Java EE 5 SDK Update 3 that comes with the application server.

* Use instructions posted here on how to install it

http://java.sun.com/javaee/sdk/javaee5sdk_install.jsp

Also use Application Server Installation Tips posted here: http://java.sun.com/javaee/5/docs/tutorial/doc/gexaj.html

Once the application server is installed, change permissions on the SDK/javadb, so the folder permissions allow creating a database. Here is an example on how to do that:


cd SDK
sudo chown –R your_name javadb


In general, I believe it is a good idea to change permissions to other files in SDK to some less privileged user than root.

Once I started playing with bookstore example, I’ve got some build and deployment errors. I found that I need to create a password file and point to it with the javaee.server.passwordfile property.

Create a new file app-server-psw.properties in the javaeetutorial5/examples/bp-project/ folder. Edit the file and add


AS_ADMIN_PASSWORD=admin_password


The admin_password should be the same as it was specified during the Application Server installation.
Update javaeetutorial5/examples/bp-project/app-server.properties by adding these properties:


db.vendor=javadb
javaee.tutorial.home=/Users/mykola/java/j2ee/javaeetutorial5
javaee.server.passwordfile=${javaee.tutorial.home}/examples/bp-project/app-server-psw.properties


Once that is done, the bookstore example build and deployment works fine.

Saturday, October 27, 2007

Java Unboxing and Null

While playing with boxing/unboxing in Java 5, I found an interesting case. If my collection has a null value, the unboxing fails with a NullPointerException at runtime. Here is an example


Set s = new HashSet();
for (int i=0; i < 10; i++) {
s.add(i);
}
s.add(null);

System.out.println("s: " + s);
// this is a problem. The unboxing does not handle null
for (int sx : s) {
System.out.println("sx: " + sx);
}



The output of the progam is here:


s: [2, 4, null, 9, 8, 6, 1, 3, 7, 5, 0]
sx: 2
sx: 4
Exception in thread "main" java.lang.NullPointerException
at com.mykola.TestSets.main(TestSets.java:21)


So, unboxing is fine, unless a collection has a null element.

Friday, August 17, 2007

Macrodef makes Ant stronger

I found new macrodef feature in ant extremely useful in my code development. It allows me to reuse lots of code and save time. Here is a quick example on how to use macrodef and why it is cool

Let’s say I have several web applications that I need to deploy on the same web server. If I use a regular Ant task, I would have to replicate these lines of code for every application:


<wldeploy action="deploy"
verbose="${verbose}"
debug="${debug}"
name="myApp"
source="${output.dir}/myApp.war"
user="${admin.username}"
password="${admin.password}"
adminurl="${adminurl}"
targets="myWebSiteDomain" />


I know it does not look that bad, but this is just a short sample. In a real world case, I also need to compile the application, generate a WAR file, deploy it, generate a client stub, etc. So, the Ant build.xml tends to grow very fast. In one of my previous project with about #5,000 the build.xml was over 700 lines of code.

Here is a solution that I like. I define a macro that deploys my application:


<macrodef name="myApp.deploy">
<attribute name="name" />
<sequential>
<wldeploy action="deploy"
verbose="${verbose}"
debug="${debug}"
name="@{name}"
source="${output.dir}/@{name}.war"
user="${admin.username}"
password="${admin.password}"
adminurl="${adminurl}"
targets=" myWebSiteDomain " />
</sequential>
</macrodef>


Once it is defined, I can deploy a set of applications simply by calling:


<myApp.deploy name="myApp1" />
<myApp.deploy name="myApp2" />

<myApp.deploy name="myAppN" />


The macro above can be enhanced to do other tasks. I find it very convenient. I think it is a good practice to replace lots of repetitive tasks in Ant build file with a macro.

Friday, August 10, 2007

Some Perforce Tips

Here is a small one line command that I created to find all local files, i.e. the files that still need to be added to the repository:


find . -type f -print | xargs p4 filelog -m 1 | grep "not on client"


I like to work with svn more. The "svn status" makes the same thing much more easier.

Thursday, July 5, 2007

Weblogic 10.0 Classpath

The classpath in Weblogic 10.0 has changed comparing to 9.2 version. Here is what I have in my build.xml now. It works for a simple web service and Weblogic tools such as jwsc, clientgen, wldeploy.


<path id="wl.class.path">
<pathelement location="${wl.home}/jrockit_150_08/lib/tools.jar" />
<pathelement location="${wl.home}/patch_wls1000/profiles/default/sys_manifest_classpath/weblogic_patch.jar" />
<fileset dir="${wl.home}/wlserver_10.0/server/lib">
<include name="weblogic_sp.jar" />
<include name="weblogic.jar" />
<include name="webservices.jar" />
<include name="xqrl.jar" />
</fileset>
<fileset dir="${wl.home}/modules/features">
<include name="features/weblogic.server.modules_10.2.0.0.jar" />
<include name="features/com.bea.cie.common-plugin.launch_2.2.0.0.jar" />
<include name="org.apache.ant_1.6.5/lib/ant-all.jar" />
<include name="net.sf.antcontrib_1.0b2.0/lib/ant-contrib.jar" />
</fileset>
</path>


The wl.home is set to d:/bea10 in my case. It is a pointer to a folder where Weblogic is installed.

How to post a code snippet here?

I have a few lines of code that I want to post here. The cut and paste does not work. Here is a simple solution I found in posts on groups.google.com. The idea is to replace < and > with & lt;, & gt; symbols. Here is how it looks like:


<tag>value<tag>

Wednesday, June 13, 2007

Why Blog?

I always keep notes when I am working on a project or study. I found it very useful. I write some tips on how to do something. I write some ideas. I use my notes a lot. So, I thought maybe I should share my notes with others and maybe it will be helpful to them too. Here you go. This blog is for me and everybody who might find it useful.