Thursday, 26 May 2011

Database copy with minimal access rights

Currently, I faced a very specific problem. I needed to duplicate a remote database locally. The problem was that I had only rights to execute SELECT statements on the remote computer. Maybe this post will help others to save time looking for the solution.

The reference manual of MySQL describes how to copy a database from one computer to another. Using the instructions in the manual, I ended up using mysqldump and mysql programs on my local computer. This utility programs are parts of the Community Server package and not of Workbench Tools as some people would assume ;-)

Once the software is installed. Run


mysqldump -h <remote_db_hostname> -u <username> -p --compress --single-transaction db_name | gzip > db_name.gz

to save the tables of the database locally. And then

gunzip < db_name.gz | mysql db_name

to create the tables in the local database.

Without the parameter --single-transaction for mysqldump I received the error message

mysqldump: Got error: 1044: Access denied for user 'username'@'%' to database 'Databasename' when using LOCK TABLES

P.S. If you are using SQuirreL SQL client, there is a plugin DBCopy available for these purposes.

Wednesday, 30 March 2011

Serialisation of trees in Matlab

I have written a small but handy Matlab function to serialise tree structures from an adjacency matrix. I use the string then to process the trees in Python, but one can come up with some other reasons to do that.

The function has some constraints, i.e. since there is no separators between node indices it will only work for trees with small number of nodes, but it was sufficient for me and it is easy to extend.

function str = adjmatrix2string( adjmatrix, node, parent )
%ADJMATRIX2STRING converts an adjacency matrix of a tree to 
string
%   Converts an adjacency matrix of a tree to its 
%   string representation of 
%   the form 1(2(34)5(67))
%   adjmatrix - adjacency matrix
%   node - index of the current node
%   parent - index of parrent node, 0 for root
%   call example: adjmatrix2string(adjmatrix, 1, 0)

str = int2str(node);
childnodes = find(adjmatrix(node, :));
% only one node in a tree
if isempty(childnodes)
str = strcat(str, node);
elseif length(childnodes) == 1
% node is a root
if parent == 0
str = strcat(str, '(', adjmatrix2string(adjmatrix, 
             childnodes(1), node), ')');
end
else
str = strcat(str, '(');
for childnode = childnodes
if childnode ~= parent
str = strcat(str, adjmatrix2string(adjmatrix, 
      childnode, node));
end
end
str = strcat(str, ')');
end
end

It will convert an adjacency matrix
$\begin{pmatrix}0&1&1&0&1&0&0\\1&0&1&1&0&0&0\\0&1&0&0&0&0&0\\0&1&0&0&0&0&0\\1&0&0&0&0&1&1\\0&0&0&0&1&0&0\\0&0&0&0&1&0&0\\\end{pmatrix}$
to the string '1(2(34)5(67))'.

Wednesday, 15 September 2010

Journals and Conferences Titles Abbreviations in BibTeX

Writing the report for my current project, I came across the problem of finding appropriate abbreviations for titles of journals and conferences. So for example one should write "Ann." instead of "Annals", "Conf." instead of "Conference on", etc.

mrabbrev.bib can be used to substitute keywords with abbreviated journal titles. Just include it in your main latex file as described in this example. However, for me  this is not a handy solution, since I import most of the BibTeX key from the web sources like CiteSeerX instead of writing them manually.

So I decided to write the abbreviations by hand. I found this IEEE Computer Society Style Guide very useful together with this abbreviation list created by Dr. Mark Wilson from School of Mechanical Engineering at University of Leeds.

Does anybody have a better idea how to deal with abbreviations in BibTeX?