import java.sql.*public class SqlUtil{ public static void main(String[] args) {try{ String url="jdbc:mysql:localhost/mydb" String user="root"使用者名称 String pwd="123456"密码 载入驱动,这一句也可写为:Class.forName(".mysql.jdbc.Driver")Class.forName(".mysql.jdbc.Driver").newInstance() 建立到MySQL的连线 Connection conn = DriverManager.getConnection(url,user, pwd) 执行SQL语句 Statement stmt = conn.createStatement()建立语句物件,用以执行sql语言 ResultSet rs = stmt.executeQuery("select * from student") 处理结果集 while (rs.next()) {String name = rs.getString("name") System.out.println(name) } rs.close()关闭资料库 conn.close() }catch (Exception ex){ System.out.println("Error : " + ex.toString()) } }}
jdbc:mysql:localhost:3306/sample_db?user=root&password=browser&useUnicode=true&characterEncoding=UTF-8
汇入mysql的驱动Jar包
Class.forName(".mysql.jdbc.Driver")
Connection con = null
String url = "资料库的url"
String user = "资料库登入名"
String password = "资料库密码"
con = DriverManager.getConnection(url, user, password)
oracle.jdbc.driver.OracleDriver
jdbc:oracle:thin:@127.0.0.1:1521:ORCL
字串内容
jdbc:mysql:localhost/资料库名称,“登入名”,“密码”
mysql cluster的hibernate连线字串怎么写
Driver template :选择要连线资料库型别我用mysql选择MYSQL Connector/J Driver name :所建立连线名字,随便写
Driver classname:.mysql.jdbc.Driver要Add JARs选择 .mysql.jdbc.Driver路径显示
使用oracle参考我面式
Dreamweaver连线MySql的连线字串
在Dreamweaver里连线mysql可以不用写连线字串的。
1、建立好站点
2、编辑站点属性-->测试伺服器,右边伺服器模型和访问选择:PHP MySQL,本地/网路
3、应用程式-->资料库一栏里点加号建立MySQL连线
4、连线名称(随意),MySQL伺服器(localhost),使用者名称(root),密码(*******),资料库(你要连线的资料库名,键入或选取都行)
5、测试连线-->确定,即可。
c#连线到mysql 的连线字串怎么写
ODBC DSN
ODBC -- MyODBC Driver -- local database
ODBC -- MyODBC Driver -- remote database
ODBC -- MySQL ODBC 3.51 Driver
OleDb
.NET DataProvider from CoreLab
ODBC DSN
using System.Data.Odbc
OdbcConnection conn = new OdbcConnection()
conn.ConnectionString =
"Dsn=DsnName" +
"Uid=UserName" +
"Pwd=Secret"
conn.Open()
ODBC -- MyODBC Driver -- local database
using System.Data.Odbc
OdbcConnection conn = new OdbcConnection()
conn.ConnectionString =
"Driver={MySql}" +
"Server=localhost" +
"Option=16834" +
"DataBase=DataBaseName"
conn.Open()
ODBC -- MyODBC Driver -- remote database
using System.Data.Odbc
OdbcConnection conn = new OdbcConnection()
conn.ConnectionString =
"Driver={MySql}" +
"Server=db.domain." +
"Option=131072" +
"Port=3306" +
"Stmt=" +
"DataBase=DataBaseName" +
"Uid=UserName" +
"Pwd=Secret"
conn.Open()
ODBC -- MySQL ODBC 3.51 Driver
using System.Data.Odbc
OdbcConnection conn = new OdbcConnection()
conn.ConnectionString =
"Driver={MySql ODBC 3.51 Driver}" +
"Server=ServerName" +
"Option=16834" +
"Port=3306" +
"Stmt=" +
"DataBase=DataBaseName" +
"Uid=UserName" +
"Pwd=Secret"
conn.Open()
or
using System.Data.Odbc
OdbcConnection conn = new OdbcConnection()
conn.ConnectionString =
"DRIVER={MySql ODBC 3.51 Driver}" +
"SERVER=ServerName" +
"DATABASE=DataBaseName" +
"USER=UrerName" +
"PASSWORD=Secret"
conn.Open()
OleDb
using System.Data.OleDb
OleDbConnection conn = new OleDbConnection()
conn.ConnectionString =
"Provider=MySqlProv" +
"Data Source=ServerName" +
"User id=UserName" +
"Password=Secret"
conn.Open()
.NET DataProvider from CoreLab
using CoreLab.MySql
MySqlConnection conn = new MySqlConnection()
conn.ConnectionString =
"Host=ServerName" +
"DataBase=DataBaseName" +
"Protocol=TCP" +
"Port=3306" +
"Direct=true" +
"Compress=false" +
"Pooling=true" +
"Min Pool Size=0" +
"Max Pool Size=100" +
"Connection Lifetime=0" +
"User id=UserName" +
"Password=Secret" +
conn.Open()
Server=localhostDatabase=drive_baseUser=otnp80Password=123Use Procedure Bodies=falseCharset=utf8Allow Zero Datetime=TruePooling=falseMax Pool Size=50
1. 获取这个不必多言吧,到 MySQL 网站上面下载就是了。MySQL Cluster 的英文部署测试手册很简明,这里和其内容基本一样。喜欢读英文版的朋友可以直接下载,略过本文。
2. 安装
先解压,然后创建一个 symbolic link:
michael@linux:~$ tar xvf mysql-cluster-gpl-7.2.4-linux2.6-x86_64.tar
michael@linux:~$ ln -s mysql-cluster-gpl-7.2.4-linux2.6-x86_64 mysqlc
如果你愿意,可以将~/mysqlc/bin加入到你的 path 里,方便使用。
3. 配置
作为在开发环境上第一次部署,还是以测试为主要目的。一个完整的 MySQL Cluster 由 MySQL Server,Data Nodes,Management Node 三部分组成。首先我们为它们创建一些必须的目录:
michael@linux:~$ mkdir mysql-cluster
michael@linux:~$ cd mysql-cluster
michael@linux:~$ mkdir conf ndb_data mysqld_data
然后在conf目录下创建如下两个文件,分别是config.ini和my.cnf,内容如下:
config.ini
用于 MySQL Server 的配置,端口号port根据你自己的情况设定。
[mysqld]
ndbcluster
datadir=/home/user1/my_cluster/mysqld_data
basedir=/home/user1/mysql-cluster
port=5050
my.cnf
该文件用于配置各结点的 NodeId 和 Data Nodes 与 Management Node 的数据目录。
[ndb_mgmd]
hostname=localhost
datadir=/home/user1/my_cluster/ndb_data
NodeId=1
[ndbd default]
noofreplicas=2
datadir=/home/user1/my_cluster/ndb_data
[ndbd]
hostname=localhost
NodeId=3
[ndbd]
hostname=localhost
NodeId=4
[mysqld]
NodeId=50
这时你的目录结构应该如下:
~
+-- /mysql-cluster-gpl-7.2.4-linux2.6-x86_64
+-- /mysqlc ->mysql-cluster-gpl-7.2.4-linux2.6-x86_64
+-- /mysql-cluster
+-- /conf
+-- /ndb_data
+-- /mysqld_data
4. 运行
MySQL Cluster 的启动顺序是有要求的,如下:
Management Node
Data Nodes
MySQL Server
命令如下:
michael@linux:~$ cd ../mysql-cluster
michael@linux:~/mysql-cluster$ $HOME/mysqlc/bin/ndb_mgmd -f conf/config.ini --initial --configdir=$HOME/mysql-cluster/conf/
michael@linux:~/mysql-cluster$ $HOME/mysqlc/bin/ndbd -c localhost:1186
michael@linux:~/mysql-cluster$ $HOME/mysqlc/bin/ndbd -c localhost:1186
检查已经启动的结点的状态,命令为:
poecahnt@linux:~$ $HOME/mysqlc/bin/ndb_mgm -e show
输出如下:
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=3@127.0.0.1 (mysql-5.5.19 ndb-7.2.4, Nodegroup: 0, Master)
id=4@127.0.0.1 (mysql-5.5.19 ndb-7.2.4, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1@127.0.0.1 (mysql-5.5.19 ndb-7.2.4)
[mysqld(API)] 1 node(s)
id=50 @127.0.0.1 (mysql-5.5.19 ndb-7.2.4)
表示已经可以启动 MySQL Server 了。最后启动 MySQL Server,命令为:
michael@linux:~/mysql-cluseter$ $HOME/mysqlc/bin/mysqld --defaults-file=conf/my.cnf &
输出信息如下:
120223 15:29:02 InnoDB: The InnoDB memory heap is disabled
120223 15:29:02 InnoDB: Mutexes and rw_locks use GCC atomic builtins
120223 15:29:02 InnoDB: Compressed tables use zlib 1.2.3
120223 15:29:02 InnoDB: Using Linux native AIO
120223 15:29:02 InnoDB: Initializing buffer pool, size = 128.0M
120223 15:29:02 InnoDB: Completed initialization of buffer pool
120223 15:29:02 InnoDB: highest supported file format is Barracuda.
120223 15:29:02 InnoDB: Waiting for the background threads to start
120223 15:29:03 InnoDB: 1.1.8 startedlog sequence number 1595675
120223 15:29:04 [Note] NDB: NodeID is 50, management server 'localhost:1186'
120223 15:29:04 [Note] NDB[0]: NodeID: 50, all storage nodes connected
120223 15:29:04 [Warning] NDB: server id set to zero - changes logged to bin log with server id zero will be logged with another server id by slave mysqlds
120223 15:29:04 [Note] Starting Cluster Binlog Thread
120223 15:29:04 [Note] Event Scheduler: Loaded 0 events
120223 15:29:04 [Note] $HOME/mysqlc/bin/mysqld: ready for connections.
Version: '5.5.19-ndb-7.2.4-gpl' socket: '/tmp/mysql.sock' port: 5050 MySQL Cluster Community Server (GPL)
120223 15:29:05 [Note] NDB: Creating mysql.ndb_schema
120223 15:29:08 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql/ndb_schema
120223 15:29:09 [Note] NDB Binlog: logging ./mysql/ndb_schema (UPDATED,USE_WRITE)
120223 15:29:09 [Note] NDB: Creating mysql.ndb_apply_status
120223 15:29:09 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql/ndb_apply_status
120223 15:29:09 [Note] NDB Binlog: logging ./mysql/ndb_apply_status (UPDATED,USE_WRITE)
120223 15:29:09 [Note] NDB: missing frm for mysql.ndb_index_stat_sample, discovering...
120223 15:29:09 [Note] NDB: missing frm for mysql.ndb_index_stat_head, discovering...
2012-02-23 15:29:10 [NdbApi] INFO -- Flushing incomplete GCI:s <579/14
2012-02-23 15:29:10 [NdbApi] INFO -- Flushing incomplete GCI:s <579/14
120223 15:29:10 [Note] NDB Binlog: starting log at epoch 579/14
120223 15:29:10 [Note] NDB Binlog: ndb tables writable
5. 测试
连接 MySQL Server 进行测试,确认可以用ndb存储引擎来创建数据库中的表,如下:
michael@linux:~$ $HOME/mysqlc/bin/mysql -h 127.0.0.1 -P 5050
mysql>create database clusterdb
mysql>use clusterdb
mysql>insert into simples values (1),(2),(3),(4)
mysql>select * from simples
+----+
| id |
+----+
| 3 |
| 1 |
| 2 |
| 4 |
+----+
6. 停止
MySQL Cluster 必须手动停止,Data Nodes 可以用 ndb_mgm 来停止:
michael@linux:~$ $HOME/mysqlc/bin/mysqladmin -h 127.0.0.1 -P 5050 shutdown
如果提示:
/home/michael/mysqlc/bin/mysqladmin: shutdown failederror: 'Access deniedyou need (at least one of) the SHUTDOWN privilege(s) for this operation'
则在shutdown命令前加上sudo。
michael@linux:~$ $HOME/mysqlc/bin/ndb_mgm -e shutdown
正常停止的信息类似如下:
120223 16:44:11 [Note] /home/michael/mysqlc/bin/mysqld: Normal shutdown
michael@linux:~/mysql-cluster$ 120223 16:44:11 [Note] Event Scheduler: Purging the queue. 0 events
120223 16:44:13 [Warning] /home/michael/mysqlc/bin/mysqld: Forcing close of thread 2 user: 'michael'
120223 16:44:13 [Note] Stopping Cluster Utility thread
120223 16:44:13 [Note] Stopping Cluster Index Stats thread
120223 16:44:13 [Note] Stopping Cluster Binlog
120223 16:44:13 [Note] Stopping Cluster Index Statistics thread
120223 16:44:14 InnoDB: Starting shutdown...
120223 16:44:15 InnoDB: Shutdown completedlog sequence number 1595675
120223 16:44:15 [Note] /home/michael/mysqlc/bin/mysqld: Shutdown complete
7. 总结
有序启动:Management Node,Data Nodes,MySQL Server
配置项与各节点的对应
每个结点都单独启动
Management Node 提供状态查看等多种功能
mysql-cluster可以用于生产环境。MySQL Cluster是一套独立的分布式储存数据的高可用产品,事实上,很多人并不具备MySQL Cluster的测试条件,并不是简单的把功能搭建起来就可以使用了。
MySQL
Cluster主要解决两方面的问题,一是写的扩展性问题,二是分布式数据储存带来的高可用性,可达99.999%;最新发布的MySQL
Cluster在一定的硬件和网络环境下,测试的指标可达到:10亿查询/分钟,1亿修改/分钟,性能还是非常强劲的。但要知道,完成这样的测试,不仅需要大内存的数据库服务器,还可能需要万兆网卡支持,否则测试就没有什么意义了。
MySQL Cluster 是一种技术,该技术允许在无共享的系统中部署“内存中”数据库的 Cluster 。通过无共享体系结构,系统能够使用廉价的硬件,而且对软硬件无特殊要求。此外,由于每个组件有自己的内存和磁盘,不存在单点故障。
MySQL Cluster 由一组计算机构成,每台计算机上均运行着多种进程,包括MySQL服务器,NDB Cluster 的数据节点,管理服务器,以及(可能)专门的数据访问程序。关于 Cluster 中这些组件的关系。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)