lizongbo at 618119.com 工作,生活,Android,前端,Linode,Ubuntu,nginx,java,apache,tomcat,Resin,mina,Hessian,XMPP,RPC

2010年11月17日

在Ubuntu10.04上通过mysql源代码进行编译安装

Filed under: Linux,mysql — 标签:, , , , — lizongbo @ 00:10

在Ubuntu10.04上通过mysql源代码进行编译安装MySQL Community Server

操作系统是linode上的Ubuntu 10.04,
MySQL Community Server目前最新正式版为:mysql 5.1.51 GA.
源代码下载地址为:
http://www.mirrorservice.org/sites/ftp.mysql.com/Downloads/MySQL-5.1/mysql-5.1.51.tar.gz

来源:http://www.mysql.com/downloads/mirror.php?id=394595#mirrors
http://www.mysql.com/downloads/

1.先下载源代码到本地:
root@618119.com:/usr/local/app# wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.51.tar.gz/from/http://www.mirrorservice.org/sites/ftp.mysql.com/
2.解压mysql-5.1.51.tar.gz到/usr/local/app/mysql-5.1.51:
root@618119.com:/usr/local/app# tar -zxvf mysql*
3.进入解压得到的源码目录中:
root@618119.com:/usr/local/app# cd mysql*
4.运行configure进行检查:
root@618119.com:/usr/local/app/mysql-5.1.51# ./configure -prefix=/usr/local/app/mysql -with-charset=utf8 -with-collation=utf8_general_ci -with-extra-charsets=latin1
提示信息:checking for termcap functions library… configure: error: No curses/termcap library found
5.安装libncurses5-dev进行解决:
root@618119.com:/usr/local/app/mysql-5.1.51# sudo apt-get install libncurses5-dev
6.在编译安装nginx时候已经安装了 gcc libc6-dev build-essential 组件
直接开始运行make编译源代码:
root@618119.com:/usr/local/app/mysql-5.1.51# make
7.等待一段时间后,源码编译完成,运行make install进行安装:
root@618119.com:/usr/local/app/mysql-5.1.51# make install
8.复制系统服务脚本:
root@618119.com:/usr/local/app/mysql# cp /usr/local/app/mysql/share/mysql/mysql.server  /etc/init.d/mysql
9.再运行命令: sudo /usr/sbin/update-rc.d -f mysql defaults,将mysql安装为默认服务。
root@618119.com:/usr/local/app/mysql# sudo /usr/sbin/update-rc.d -f mysql defaults
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = “zh_CN.UTF-8”
are supported and installed on your system.
perl: warning: Falling back to the standard locale (“C”).
Adding system startup for /etc/init.d/mysql …
/etc/rc0.d/K20mysql -> ../init.d/mysql
/etc/rc1.d/K20mysql -> ../init.d/mysql
/etc/rc6.d/K20mysql -> ../init.d/mysql
/etc/rc2.d/S20mysql -> ../init.d/mysql
/etc/rc3.d/S20mysql -> ../init.d/mysql
/etc/rc4.d/S20mysql -> ../init.d/mysql
/etc/rc5.d/S20mysql -> ../init.d/mysql
10.复制默认配置到/etc目录:
root@618119.com:/usr/local/app/mysql# cp /usr/local/app/mysql/share/mysql/my-medium.cnf /etc/my.cnf
11:添加名字为mysql的用户:
root@618119.com:/usr/local/app/nginx# sudo adduser –system –no-create-home –disabled-login –disabled-password –group mysql
12.初始化数据库(如果没初始化,启动mysql会提示“Manager of pid-file quit without updating file”):
root@618119.com:/usr/local/app/mysql/bin# ./mysql_install_db –user=mysql
Installing MySQL system tables…
101022 15:24:16 [Warning] ‘–skip-locking’ is deprecated and will be removed in a future release. Please use ‘–skip-external-locking’ instead.
OK
Filling help tables…
101022 15:24:16 [Warning] ‘–skip-locking’ is deprecated and will be removed in a future release. Please use ‘–skip-external-locking’ instead.
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:

/usr/local/app/mysql/bin/mysqladmin -u root password ‘new-password’
/usr/local/app/mysql/bin/mysqladmin -u root -h 618119.com password ‘new-password’

Alternatively you can run:
/usr/local/app/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr/local/app/mysql ; /usr/local/app/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/app/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/app/mysql/bin/mysqlbug script!

13.启动mysql数据库.
root@618119.com:/usr/local/app/mysql/bin# sudo /etc/init.d/mysql start

14.命令行进入数据库进行测试:
root@618119.com:/usr/local/app/mysql/bin# ./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.51-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> show databases;
+——————–+
| Database           |
+——————–+
| information_schema |
| mysql              |
| test               |
+——————–+
3 rows in set (0.00 sec)

mysql> quit
Bye

15.运行mysql自带的测试脚本需要等的时间比较久:
root@618119.com:/usr/local/app/mysql# cd /usr/local/app/mysql/mysql-test ; perl mysql-test-run.pl
测试结果是1000多项只有600项通过:
main.mysql_client_test                   [ fail ]
Test ended at 2010-10-22 15:35:39

CURRENT_TEST: main.mysql_client_test
mysqltest: At line 15: command “$MYSQL_CLIENT_TEST –getopt-ll-test=25600M >> $MYSQLTEST_VARDIR/log/mysql_client_test.out.log 2>&1” failed

Output from before failure:
exec of ‘/usr/local/app/mysql/bin/mysql_client_test –defaults-file=/usr/local/app/mysql/mysql-test/var/my.cnf –testcase –vardir=/usr/local/app/mysql/mysql-test/var –getopt-ll-test=25600M >> /usr/local/app/mysql/mysql-test/var/log/mysql_client_test.out.log 2>&1’ failed, error: 256, status: 1, errno: 0

The result from queries just before the failure was:
SET @old_general_log= @@global.general_log;
SET @old_slow_query_log= @@global.slow_query_log;

– saving ‘/usr/local/app/mysql/mysql-test/var/log/main.mysql_client_test/’ to ‘/usr/local/app/mysql/mysql-test/var/log/main.mysql_client_test/’

Only  653  of 1415 completed.
mysql-test-run: *** ERROR: Not all tests completed
166.使用符号链接方便直接运行 mysql命令:
root@618119.com:/usr/local/app/mysql# sudo ln -s /usr/local/app/mysql/bin/mysql /usr/bin/
root@618119.com:/usr/local/app/mysql# sudo ln -s /usr/local/app/mysql/bin/mysqladmin /usr/bin/

开始在resin上安装phpMyAdmin:
phpMyAdmin最新版本 3.3.7:
下载地址:http://nchc.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.7/phpMyAdmin-3.3.7-all-languages.tar.gz
来源:
http://www.phpmyadmin.net/home_page/index.php

下载后解压到:lizongbo@618119.com:/etc/init.d$ cd /usr/local/app/resin/webapps
然后改名:
lizongbo@618119.com:/usr/local/app/resin/webapps$ mv phpMyAdmin-3.3.7-all-languages/ phpMyAdmin

尝试resin最新版跑phpMyAdmin跑不了。
还是想办法配置nginx吧,可以参考:
http://www.linuxidc.com/Linux/2010-03/25161.htm
mysql JDBC驱动:
最新正式版为:Connector/J 5.1.13
下载地址:http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector- java-5.1.13.tar.gz/from/http://www.mirrorservice.org/sites/ftp.mysql.com/
来源:http://www.mysql.com/downloads/connector/j/

root@618119.com:/usr/local/app# wget http://www.mirrorservice.org/sites/ftp.mysql.com/Downloads/Connector-J/mysql-connector-java-5.1.13.tar.gz
root@618119.com:/usr/local/app# tar -zxvf mysql-c*
复制jdbc驱动到resin的lib目录:
root@618119.com:/usr/local/app/mysql-connector-java-5.1.13# cp /usr/local/app/mysql-connector-java-5.1.13/mysql-connector-java-5.1.13-bin.jar /usr/local/app/resin/lib

2007年11月20日

用JDBC连接Oracle 10g RAC遇到的问题

Filed under: DbVisualizer,Oracle,数据库 — 标签:, , , , , , , , , — lizongbo @ 08:56

数据库升级为Oracle 10g RAC,原有的连接方式下,出现如下错误:

出错信息:
– Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: “o
rg.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFacto
ry (Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169869568)(ERR=12505)(
ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))))”
at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnect
ion(QueryTagSupport.java:276)
at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag
(QueryTagSupport.java:159)

于是根据网上的资料修改了JDBC的URL,正确jdbc的url为:

jdbc:oracle:thin:@(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.103)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.104)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA = (SERVER = DEDICATED)
(SERVICE_NAME = mydb.618119.com) ) )

或者:

jdbc:oracle:thin:@(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)
(HOST = db01.618119.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)
(HOST = db02.618119.com)(PORT = 1521))
(LOAD_BALANCE = yes)
(failover = yes)
(CONNECT_DATA = (SERVER = DEDICATED)
(SERVICE_NAME = mydb.618119.com) ) )

结果过依然存在问题:

偶尔会出现错误:

An error occurred while establishing the connection:
Type: java.sql.SQLException Error Code: 17002
Message:
Io 异常: Connection refused(DESCRIPTION=(ERR=1153)(VSNNUM=169869568)(ERROR_STACK=(ERROR=(CODE=1153)(EMFI=4)(ARGS='(ADDRESS=(PROTOCOL=TCP)(HOST=RAC02)(PORT=1521))’))(ERROR=(CODE=305)(EMFI=1))))

试了将驱动替换为10g的ojdbc14.jar.

然后再在DbVisualizer中试了很多次断开连接和重新链接,都还没出错.
但是在web页面中测试,还是经常出现获取不到数据库连接的情况.

在网上查询了很多资料,仍未能解决这个问题, 不得已,只好换成oci方式连接.
在jdbc客户端所在地服务器中,将TNSNAMES.ORA里本地服务名配置为
mydb =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.103)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.104)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = mydb.618119.com)
)
)

oci方式的jdbc url=”jdbc:oracle:oci:@mydb”;

获取数据库连接正常.

主要参考了以下资料 : http://www.ixdba.net/hbcms/article/97/244.html

http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=123&threadID=44660&messageID=264712

http://article.51edu.com/computer/shujuku/Oracle/200512/42391.html

http://www.dba-oracle.com/art_oramag_rac_taf.htm

http://www.koorka.com/download/free/Oracle_RAC_For_Windows_install.pdf

http://www.koorka.com/download/free/Oracle_RAC_For_Linux_install.pdf

update:

在使用oci模式进行连接时,整个虚拟机内只能有一份oracle的jdbc 驱动,并且所在的机器必须安装了oracle 的client,oracle client必须与驱动版本一致,即,如果是使用10g的jdbc驱动,则必须安装10g的 oracle client,需要Orace client的bin目录需要添加到环境变量的path中,例如:

Path=d:\oracle\product\10.2.0\client_1\bin;D:\Java\apache-ant-1.7.0\bin;D:\J ava\
jdk1.6.0_03\bin;D:\WINDOWS\system32;D:\WINDOWS;D:\WINDOWS\System32\Wbem;D:\Progr
am Files\Microsoft Network Monitor 3\;D:\PROGRA~1\F-Secure\Ssh;

因此在web应用中Oracle jdbc的驱动不能放在WEB-INF/lib目录下,而是要放到 server的lib目录下(例如Tomcat6的D:\Java\apache-tomcat-6.0.14\lib ,Tomcat5的D:\Java\apache-tomcat-5.5.25\common\lib) .

如果出现重复的oracle jdbc驱动文件(或者是多个不同版本的oracle jdbc驱动在一起) ,

则可能出现以下错误信息:

[code]

java.lang.UnsatisfiedLinkError: make_c_state
java.lang.UnsatisfiedLinkError: make_c_state
at oracle.jdbc.oci8.OCIDBAccess.make_c_state(Native Method)
at oracle.jdbc.oci8.OCIDBAccess.logon(OCIDBAccess.java:309)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:307)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:442)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:321)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)

[/code]

[code]

java.lang.UnsatisfiedLinkError: Native Library D:\oracle\ora92\bin\ocijdbc9.dll
already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1716)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:992)
at oracle.jdbc.oci8.OCIDBAccess.logon(OCIDBAccess.java:294)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:307)

at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
va:442)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:321)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)

[/code]

udate:

http://lhylj2.spaces.live.com/Blog/cns!7E417A90C3FE44A9!229.entry
这里提到换成 Oracle 9.0.2.4的jdbc驱动可以解决时而连不上的问题,我没有测试过 .

Powered by WordPress