Archive for the ‘MySQL’ Category

Setting up MySql on Mac OSX for Jena SDB

Friday, October 17th, 2008

Awhile ago I installed MySQL 5.0.37 on my MacBook Pro using the default mysql settings.

Recently I installed Jena SDB 1.1, following the instructions on the wiki.

As part of the install I created a mysql database, specifying utf8, e.g.

mysql> create database sdb-index character set utf8 ;

and set up a store description (named sdb-index.ttl) based on the SDB example, changing it to use mysql and the “layout2/index” layout.

The create command worked fine
SDBROOT > bin/sdbconfig –sdb=sdb-index.ttl –create

but when I ran the testsuite
SDBROOT > bin/sdbtest –sdb=sdb-index.ttl testing/manifest-sdb.ttl

I got the following error in the Unicode-5 test.

Checking out the SDB notes for Mysql it seemed likely that the problem was related to the msyql default character set.

To see what was currently set I ran the “show variables” command below

mysql> show variables like ‘character%’;
+————————–+————————————————————+
| Variable_name | Value |
+————————–+————————————————————+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.0.37-osx10.4-i686/share/mysql/charsets/ |
+————————–+————————————————————+

The SDB notes for Mysql recommends setting default-character-set=utf8. The Mysql documentation seemed to favour setting character-set-server=utf8 and collation-server=utf8_general_ci.

To make the changes I needed to create a config file with the changed settings that mysql reads on startup.

To do this I copied the example config file for small installations to /etc/my.cnf.

cp /usr/local/mysql-5.0.37-osx10.4-i686/support-files/my-small.cnf /etc/my.cnf

In the [mysqld] section of my.cnf I added the lines:
# utf8
init-connect=’SET NAMES utf8′
character-set-server=utf8
collation-server=utf8_general_ci

After restarting mysql the “show variables” command showed the following utf8 updates.
mysql> show variables like ‘character%’;
+————————–+————————————————————+
| Variable_name | Value |
+————————–+————————————————————+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.0.37-osx10.4-i686/share/mysql/charsets/ |
+————————–+————————————————————+

When I tried it again the SDB testsuite ran without errors.

SDBROOT > bin/sdbtest –sdb=sdb-index.ttl testing/manifest-sdb.ttl

MySQL Commands

Friday, January 25th, 2008

MySQL commands I use but can never remember:

  • Logon> mysql –user=userame –password=password
  • Create a database> create database richard_projects character set utf8;
  • Explain> explain select * from projects
  • Alter Table> alter table PROJECTS add primary key (ID);
  • Alter Table> alter table USER modify password varchar(255);
  • Add Foreign Key> alter table`USER_ROLE` add foreign key(`USER_ID`) references `USER`(`ID`) on delete cascade on update cascade;
  • Create Index> create index USER_PASSWORD on USER(PASSWORD);
  • Create Unique Index> create unique index CATEGORY_NAME on CATEGORY(NAME);
  • Insert> insert into CATEGORY VALUES (6, ‘Food’,'Generic Food Category’);
  • Update> update CATEGORY set NAME=’Other’ ,DESCR =’Other’ where NAME=’Food’;
  • Delete> delete from CATEGORY where NAME=’Food’;

User Management

Add a user with both remote and local access:

  • Grant>GRANT ALL PRIVILEGES ON *.* TO ‘richard’@'localhost’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;
  • Grant>GRANT ALL PRIVILEGES ON *.* TO ‘richard’@'%’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;

References

MySQL 5 Reference Manual Online

W3Schools SQL Quick References