一、下载mycat,地址:https://github.com/MyCATApache/Mycat-download/tree/master/1.6-RELEASE
二、下载安装jdk-1.8以上版本
三、配置环境变量
四、修改conf/wrapper.conf,conf/schema.xml这两个文件的配置
五、启动mycat,双击bin下的startup_nowrap.bat弹框不关闭就启动成功了,当弹框关闭就停止服务或启动失败;或者,使用cmd命令创建和启动服务
六、连接navicat(注意:要使用低版本的navicat,否则报错)
七、php测试
1.insert.php
<?php
$servername = "127.0.0.1:8066";
$username = "root";
$password = "123456";
$dbname = "TESTDB";
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
$act=trim($_POST["act"]);
if($act=='add'){
$id=intval($_POST["id"]);
$name=trim($_POST["name"]);
$sqls = "INSERT INTO testqq (name, id) VALUES ('$name', '$id')";
if ($conn->query($sqls) === TRUE) {
echo "新记录插入成功";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="" method="post">
<input type="text" name="id" id="id" value="" placeholder="id"/>
<input type="text" name="name" id="name" value="" placeholder="name"/>
<input type="hidden" name="act" id="act" value="add" />
<input type="submit" value="提交"/>
</form>
</body>
</html>
2.select.php
<?php
$servername = "127.0.0.1:8066";
$username = "root";
$password = "123456";
$dbname = "TESTDB";
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
$sql = "select * from testqq";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// 输出数据
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
}
} else {
echo "0 结果";
}
$conn->close();
?>
效果如下: