shell> mysql -h host -u user -penter password: ********//如果root没有密码,以下是不成功的.(试过了) mysql> grant all privileges on *.* to [email protected] -> identified by 'javadude' with grant option;mysql> create database javatest;mysql> use javatest;mysql> create table testdata( -> id int not null auto_increment primary key, -> foo varchar(25), -> bar int);在conf/server.xml中<host></host>中添加<context path="/dbtest" docbase="dbtest" debug="5" reloadable="true" crosscontext="true"> <logger classname="org.apache. catalina.logger.filelogger" prefix="localhost_dbtest_log." suffix=".txt" timestamp="true"/> <resource name="jdbc/testdb" auth="container" type="javax.sql.datasource"/> <resourceparams name="jdbc/testdb"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp. basicdatasourcefactory</value> </parameter> <!-- maximum number of db connections in pool. make sure you configure your mysqld max_connections large enough to handle all of your db connections. set to 0 for no limit. --> <parameter> <name>maxactive</name> <value>100</value> </parameter> <!-- maximum number of idle db connections to retain in pool. set to 0 for no limit. --> <parameter> <name>maxidle</name> <value>30</value> </parameter> <!-- maximum time to wait for a db connection to become available in ms, in this example 10 seconds. an exception is thrown if this timeout is exceeded. set to -1 to wait indefinitely. --> <parameter> <name>maxwait</name> <value>10000</value> </parameter> <!-- mysql db username and password for db connections --> <parameter> <name>username</name> <value>javauser</value> </parameter> <parameter> <name>password</name> <value>javadude</value> </parameter> <!-- class name for the old mm. mysql jdbc driver - uncomment this entry and comment next if you want to use this driver - we recommend using connector/j though <parameter> <name>driverclassname</name> <value>org.gjt.mm.mysql.driver</value> </parameter> --> <!-- class name for the official mysql connector/j driver --> <parameter> <name>driverclassname</name> <value>com.mysql.jdbc.driver</value> </parameter> <!-- the jdbc connection url for connecting to your mysql db. the autoreconnect=true argument to the url makes sure that the mm.mysql jdbc driver will automatically reconnect if mysqld closed the connection. mysqld by default closes idle connections after 8 hours. --> <parameter> <name>url</name> <value>jdbc:mysql://localhost:3306 /javatest?autoreconnect=true</value> </parameter> <parameter> <name>removeabandoned</name> <value>true</value> </parameter> <parameter> <name>removeabandonedtimeout</name> <value>60</value> </parameter> <parameter> <name>logabandoned</name> <value>true</value> </parameter> </resourceparams></context>
<auth-constraint><role-name>web-user</role-name></auth-constraint><login-config> <auth-method>basic</auth-method> <realm-name>my member area</realm-name></login-config>