让MySQL与OpenOffice共舞

2007-01-01     推荐:12394    收藏:8003    评论:5999     来源:网络

一年前,我成为了Linux用户的一员,但是多年使用Windows,让我觉得Linux有的工具使用不很习惯。就拿数据库来说,在Windows下,开发一些数据库驱动的网站或者小型管理系统时可以选择使用Access。Access不仅易于使用,而且非常方便。转到Linux上后,做同样事情时发现MySQL是一个不错的选择,但其没有图形界面,使用起来不是很方便,于是希望能够找到解决的方案。经过一段时间的探寻,终于找到了解决办法,即把MySQL和OpenOffice结合使用。根据资料显示,实现MySQL和OpenOffice协同工作的方法有很多种,不过大都过于复杂,难于实现。在此我介绍两种安装和配置过程。

我使用的操作系统是Red Hat 8.0,同样的方法用于其它的发行版可能稍有不同。在安装配置过程中,需要MySQL和unixODBC软件包(OpenOffice缺省情况下已经安装好了)。这些软件包在Red Hat 8.0的光盘中都已经自带,但在我的测试中,使用安装盘的方法似乎无法成功。

安装配置方法一

1.下载软件

所需要的软件包有:

mysql-3.23.55-pc-linux-i686.tar

MySQL-client-3.23.55-1.i386

MySQL-shared-3.23.55-1.i386

MyODBC-2.50.39-1.i386

unixODBC-2.2.4.tar

这些软件包可分别可从以下站点下载:

http://mirrors.sunsite.dk/mysql/Downloads/MySQL-3.23/

http://mysql.azc.uam.mx/Downloads/MyODBC/

http://www.unixodbc.org

上面所列的是我感觉速度比较快的站点,事实上在很多镜像站点都可以下载到这些软件包。

2.安装软件

使用以下命令(以root身份)来查看以前是否安装过:

rpm -qa | grep -i mysql

rpm -e (发现的所有软件包)

updatedb

rpm -qa | grep -i odbc

rpm -e (所有发现的软件包)

切换至下载的软件包所在的目录,以root用户的身份执行以下命令:

$cd /usr/local

$tar xzf mysql-3.23.55-pc-linux-i686.tar.gz

$ln -s mysql.3.23.55-pc mysql

$cd mysql

$scripts/mysql_install_db

$chown -R root .

$chown -R mysql data

$chgrp -R mysql .

$bin/safe_mysqld --user=mysql &

下面运行一个MySQL会话:

$./mysql -utest

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1 to server version: 3.23.55

Type ''help;'' or ''\h'' for help. Type ''\c'' to clear the buffer.

这说明MySQL已经成功安装,现在输入:

mysql> select version();

+-----------+

| version() |

+-----------+

| 3.23.55 |

+-----------+

1 row in set (0.01 sec)

使用命令“\s”来查看一些基本信息:

mysql> \s

--------------

./mysql Ver 11.18 Distrib 3.23.55, for pc-linux (i686)

Connection id: 4

Current database:

Current user: test@localhost

Current pager: stdout

Using outfile: ''''

Server version: 3.23.55

Protocol version: 10

Connection: Localhost via UNIX socket

Client characterset: latin1

Server characterset: latin1

UNIX socket: /tmp/mysql.sock

Uptime: 6 min 57 sec

Threads: 1 Questions: 6 Slow queries: 0 Opens: 6 Flush tables:

 1 Open tables: 0 Queries per second avg: 0.014

为了实现我们的目的,需要安装另外三个软件包。和MySQL不同的是,这三个软件都是以RPM的格式给出的。切换至软件包所在的目录,运行以下命令:

[root@myserver odbc]#su

[root@myserver odbc]# rpm -Uvh MySQL-client-3.23.55-1.i386.rpm

Preparing... ########################################### [100%]

1:MySQL-client ########################################### [100%]

[root@myserver odbc]# rpm -Uvh MySQL-shared-3.23.55-1.i386.rpm

Preparing... ########################################### [100%]

1:MySQL-shared ########################################### [100%]

[root@myserver odbc]# rpm -Uvh MyODBC-2.50.39-1.i386.rpm

Preparing... ########################################### [100%]

1:MyODBC ########################################### [100%]



这些软件包的安装一般都不会有什么问题。下面来安装unixODBC。在我写本文时最新的unixODBC是2.2.5版,提供下载的文件是unixODBC-2.2.5.tar.gz。切换至软件包所在目录,运行以下命令:

tar xzf unixODBC-2.2.5.tar.gz

切换至unixODBC-2.2.5目录,运行下述命令:

su

./configure

make

make install

但是,这个安装过程并不顺利,出现了一些问题。首先是一些库文件的位置问题,这两个库文件是libodbcmyS.so和libmyodbc.so,它们一般位于/usr/local/lib目录之下。而在安装过程中,odbcinst.ini配置文件中指示这两个文件的位置却在usr/lib目录之下。所以需要对/etc/odbcinst.ini文件进行一些编辑。编辑完成后,我的odbcinst.ini文件内容如下所示:

[MySQL]

Description = ODBC Driver for MySQL

Driver = /usr/local/lib/libmyodbc.so

Setup = /usr/local/lib/libodbcmyS.so

FileUsate = 1

CPTimeout =

CPReuse =

然后再创建一个/etc/odbc.ini文件,内容如下所示:

Description = MySQL database test

Driver = MySQL

Server = localhost

Database = test

Port = 3306

Socket =

Option =

Stmt =

[MySQL-test]

但是,当我按照手册完成这个文件时,发现原来unixODBC已经建好了这个文件,不过它不在/etc目录之下,而是在/usr/local/etc目录下。于是我把上述两个编辑好的文件拷贝至该目录中。

此外,安装库unixODBC时还需要KDE软件开发工具包(其中已经包含了Qt)和X软件开发工具包,否则安装过程将无法进行下去。如果没有安装该软件包,那么可以选择:开始选单→系统工具→软件包。这时就会启动Red Hat软件包管理工具,选中上述两项内容(如图1所示),点击确定进行安装。

560)this.style.width=560;'' onmousewheel = ''javascript:return big(this)'' src="/files/uploadimg/20051017/1159270.gif" border=0>

3.进行测试

首先看一看ODBC和MySQL是否可以正确沟通。我使用isql MySQL-test -v命令来进行测试,结果出现了“Could not SQLConnect”的错误信息。因为我使用了显示详细信息的-v选项,因此系统提示无法找到/var/lib/mysql/mysql.sock的信息。后来我发现MySQL是把mysql.sock文件存储在了/tmp目录下,而ODBC则是在/var/lib/mysql目录下查找该文件,难怪它们不能顺利沟通。

现在以root身份来创建一个/var/lib/mysql目录,随后运行以下命令:

chown -R mysql.mysql /var/lib/mysql

然后重新启动mysqld,并且指明了用户名和socket的位置,命令如下所示:

bin/safe_mysqld --user=mysql --socket=/var/lib/mysql/mysql.sock &

再测试一遍,结果一切正常。现在可以进行以下测试了:

/ isql MySQL-test -v

+---------------------------------------+

| Connected! |

| |

| sql-statement |

| help [tablename] |

| quit |

| |

+---------------------------------------+

SQL> select version();

+----------+

| version()|

+----------+

| 3.23.55 |

+----------+

1 rows affected

1 rows returned

经过前面不断地失败,我都不赶相信软件用户手册了。接着,启动OpenOffice Writer,然后选择工具→数据源。这时,又一个错误出现,OpenOffice显示说无法找到libodbc.so。我把libodbc.so从/usr/local/lib拷贝到/usr/lib后,问题就解决了。于是,一切都正常了。图2是OpenOffice的表设计窗口,在这个窗口中,我很容易就完成了一个表的设计,真是太棒了。

560)this.style.width=560;'' onmousewheel = ''javascript:return big(this)'' src="/files/uploadimg/20051017/1159271.gif" border=0>

虽然已经成功,但是我还是不觉得轻松,毕竟这个方法过于复杂。于是,我开始寻求更简单的解决办法。工夫不负有心人,最后,我终于找到了解决的办法,也就是我将要给大家介绍的方法二。

安装配置方法二

这种方法的基本思想是,通过RHN让Red Hat自己进行软件更新和依赖性的检查,至于如何设置RHN,请参考本刊2003年第1期“使用RHN让Red Hat Linux自动更新”的文章。

在Red Hat 8.0中,安装的步骤如下:

第一步 up2date mysql mysql-server and mysql-devel

如果网速足够快,那么这个步骤也不会花太多的时间。在我的机器上,这个过程只花费了4分钟,如图3所示。

560)this.style.width=560;'' onmousewheel = ''javascript:return big(this)'' src="/files/uploadimg/20051017/1159272.gif" border=0>

第二步 /usr/bin/mysql_install_db

第三步 chown -R mysql.mysql /var/lib/mysql

第四步 chmod -R 666 /var/lib/mysql

第五步 /usr/bin/safe_mysqld-u mysql &

第六步 up2date unixODBC unixODBC-devel

第七步 up2date --src MyODBC

第八步 rpmbuild --rebuild /var/spool/up2date/MyODBC-2.50.39-7.src.rpm

第九步 rpm -Uvh --force /usr/src/redhat/RPMS/i386/MyODBC-2.50.39-7.i386.rpm

第十步 参照方法一编辑/etc/odbc.ini和/etc/odbcinst.ini

但是不知是什么原因,每次当我使用up2date列表中的软件包时都有一些问题。也许是某一次的安装过程中,我没有清理好系统,或者是当目录树下有如此多的软件包时,up2date无法正确应对。不管怎么说,我还是正确完成了安装。

小结

现在再来做另外一件事情,就是从刚建立的表中提取内容,并且打印地址标签。完成这个步骤花费了我大量的时间。按照帮助系统的指示,我大概了解了配置的过程,但是最后没有成功。并且,这个配置过程非常的不直观,更何况有的步骤根本就无法正常工作。

为此,我在网上进行了大量检索,并且分别到OpenOffice.org和MySQL的论坛中进行了提问,但问题都没有得到解决。功夫不负有心人,最后我终于获知原来出错的原因居然是OpenOffice.org的帮助系统文件档有一些错误。我终于找到了可以让它正常工作的方法。

当我第一次尝试打印地址标签时,MySQL提示出错信息:“Too many connections.”,原来页面中的每一个标签都需要一个自己的连接。于是,我做了两件事情来解决这个问题。首先,把下面这些加入到了/etc/my.cnf的MySQL章节中:

set-variable = max_connections=200

中止了正在运行的进程之后,在重新启动之前执行了su mysql。我在网上看到有一个MySQL开发人员建议,如果不以root身份来启动mysqld的话可以解决“Too many connection”的问题。于是我以MySQL的身份重新启动了mysql,并且在命令行中加入了一个用户参数。这样改变以后,数据库的访问就正常了。当然,到底哪一个方法有效还要经过一些实验。

整个使用过程中,我的感觉是OpenOffice.org要远比我想象的复杂和强大得多,它可以和各种数据库管理系统一起工作。如果你的SOHO办公环境需要数据库访问和操作,那么我建议不要马上切换至OpenOffice.org,而是先对其进行测试,看一看其是否可以满足你的需求。需要指出的是,任何软件无论是代码还是文档,都会有一些错误,所以不要对使用过程中出现的一些问题大加抱怨,应该以更积极的态度来发现和解决问题。



您可以针对本文进行:[评论]  [收藏]  [推荐]   [查看原文链接]  
  • [5999楼] 2008-04-29 12:21:32.0  网友
  • [回复]
  • Cabinet <a href="http://certad.rack111.com/136.html ">subaru victor ny</a> <a href="http://certad.rack111.com/421.html ">oil smell in 2006 subaru legacy</a> <a href="http://certad.rack111.com/154.html ">subaru stumble engine</a> <a href="http://certad.rack111.com/275.html ">pepsi subaru free ride</a> [URL=http://certad.rack111.com/292.html]john phils toyota subaru scion[/URL] [URL=http://certad.rack111.com/275.html]pepsi subaru free ride[/URL] links
  • [5998楼] 2008-04-29 11:34:46.0  网友
  • [回复]
  • Gangster <a href="http://deferfa.325mb.com/24.html ">pontiac vibes wheel alignment possible</a> <a href="http://deferfa.325mb.com/225.html ">1951 pontiac fasteners</a> <a href="http://deferfa.325mb.com/702.html ">1968 pontiac lemans for sale</a> <a href="http://deferfa.325mb.com/155.html ">1951 pontiac parts</a> [URL=http://deferfa.325mb.com/242.html]licensed daycare pre-schools on pontiac michigan[/URL] [URL=http://deferfa.325mb.com/475.html]1976 pontiac firebird formula[/URL] urls
  • [5997楼] 2008-04-29 11:13:31.0  网友
  • [回复]
  • Hello, people <a href="http://partase.info/gay_sex_in_the_seventies.html ">gay sex in the seventies</a> <a href="http://partase.info/heidi_klum_sex_clips.html ">heidi klum sex clips</a> <a href="http://partase.info/her_first_lesbian_sex_brianna.html ">her first lesbian sex brianna</a> <a href="http://partase.info/gata_sexy.html ">gata sexy</a> [URL=http://partase.info/furry_sex_toons.html]furry sex toons[/URL] [URL=http://partase.info/funnysex.html]funnysex[/URL] and other
  • [5996楼] 2008-04-29 10:48:19.0  网友
  • [回复]
  • Grand <a href="http://koldas.freehoxt.com/96.html ">1993 nissan nx</a> <a href="http://koldas.freehoxt.com/481.html ">nissan pathfinder gas tank</a> <a href="http://koldas.freehoxt.com/162.html ">2005 nissan frontier performance</a> <a href="http://koldas.freehoxt.com/611.html ">nissan frontier accesories</a> [URL=http://koldas.freehoxt.com/150.html]windshield for nissan 350z[/URL] [URL=http://koldas.freehoxt.com/25.html]nissan sports cars[/URL] world
  • [5995楼] 2008-04-29 10:02:08.0  网友
  • [回复]
  • America <a href="http://gupolo.oxyhost.com/772.html ">lelands honda suzuki</a> <a href="http://gupolo.oxyhost.com/465.html ">1973 honda ct70</a> <a href="http://gupolo.oxyhost.com/378.html ">honda cb750f super sport engine pictures</a> <a href="http://gupolo.oxyhost.com/63.html ">honda night hawk</a> [URL=http://gupolo.oxyhost.com/518.html]honda ex350 for sale[/URL] [URL=http://gupolo.oxyhost.com/793.html]eastside honda atvs[/URL] town
  • [5994楼] 2008-04-29 09:17:02.0  网友
  • [回复]
  • Cabinet <a href="http://ewlaoter.oxyhost.com/744.html ">toyota pickup sheet metal panels</a> <a href="http://ewlaoter.oxyhost.com/401.html ">new cab chassis review toyota</a> <a href="http://ewlaoter.oxyhost.com/506.html ">air vent for toyota corrola</a> <a href="http://ewlaoter.oxyhost.com/399.html ">toyota celica clutch</a> [URL=http://ewlaoter.oxyhost.com/718.html]rosner toyota[/URL] [URL=http://ewlaoter.oxyhost.com/275.html]toyota of lake norman[/URL] links
  • [5993楼] 2008-04-29 08:33:44.0  网友
  • [回复]
  • Greetings <a href="http://partasb.info/jailhouse_whore.html ">jailhouse whore</a> <a href="http://partasb.info/gta_sex_appeal.html ">gta sex appeal</a> <a href="http://partasb.info/lipstick_lesbo_threesome.html ">lipstick lesbo threesome</a> <a href="http://partasb.info/whores_on_knees.html ">whores on knees</a> [URL=http://partasb.info/aishwarya_rai_sexy_wallapers.html]aishwarya rai sexy wallapers[/URL] [URL=http://partasb.info/adultfrendfinder.html]adultfrendfinder[/URL] websites
  • [5992楼] 2008-04-29 08:30:31.0  网友
  • [回复]
  • Cabinet <a href="http://certad.rack111.com/52.html ">subaru front lip spoilers</a> <a href="http://certad.rack111.com/381.html ">subaru samba</a> <a href="http://certad.rack111.com/106.html ">cobb subaru performance</a> <a href="http://certad.rack111.com/107.html ">subaru legacy outback rims</a> [URL=http://certad.rack111.com/322.html]2003 subaru forester head gasket[/URL] [URL=http://certad.rack111.com/105.html]subaru baja in ohio[/URL] links
  • [5991楼] 2008-04-29 11:49:54.0  网友
  • [回复]
  • Gangster <a href="http://deferfa.325mb.com/312.html ">b-body pontiac</a> <a href="http://deferfa.325mb.com/213.html ">2007 pontiac g6 review</a> <a href="http://deferfa.325mb.com/646.html ">pontiac g6 convertible forum</a> <a href="http://deferfa.325mb.com/447.html ">pontiac bonneville volt gauge reading</a> [URL=http://deferfa.325mb.com/158.html]plaza pontiac[/URL] [URL=http://deferfa.325mb.com/775.html]68 pontiac fuel pressure[/URL] urls
  • [5990楼] 2008-04-29 11:08:18.0  网友
  • [回复]
  • Blogs online <a href="http://partasj.info/chlamydia_oral_sex.html ">chlamydia oral sex</a> <a href="http://partasj.info/brook_sexauer_orthopedic_surgery.html ">brook sexauer orthopedic surgery</a> <a href="http://partasj.info/blck_sex.html ">blck sex</a> <a href="http://partasj.info/bombes_sexuelles.html ">bombes sexuelles</a> [URL=http://partasj.info/chyna_and_pac_sex_tape.html]chyna and pac sex tape[/URL] [URL=http://partasj.info/brittany_murphy_sex.html]brittany murphy sex[/URL] my favourite
  • 共有5999条评论  点击查看更多评论
  • 网友评论仅供网友表达个人看法,并不表明e800同意其观点或证实其描述
我想发表评论:
用户名密码
  • 匿名发表
    验证码: