准备:1、下载 MySQL-Cluster-gpl-7.3.8-1.el6.x86_64.rpm-bundle.tar
下载地址: http://mirrors.sohu.com/mysql/MySQL-Cluster-7.3/MySQL-Cluster-gpl-7.3.8-1.el6.x86_64.rpm-bundle.tar
解压:
[root@test1 files]# tar -xvf MySQL-Cluster-gpl-7.3.8-1.el6.x86_64.rpm-bundle.tar MySQL-Cluster-test-gpl-7.3.8-1.el6.x86_64.rpm MySQL-Cluster-shared-compat-gpl-7.3.8-1.el6.x86_64.rpm MySQL-Cluster-client-gpl-7.3.8-1.el6.x86_64.rpm MySQL-Cluster-embedded-gpl-7.3.8-1.el6.x86_64.rpm MySQL-Cluster-server-gpl-7.3.8-1.el6.x86_64.rpm MySQL-Cluster-devel-gpl-7.3.8-1.el6.x86_64.rpm MySQL-Cluster-shared-gpl-7.3.8-1.el6.x86_64.rpm
2、停掉原有mysql 删除开机自动运行 卸载原有mysql 相关(未有任何相关则忽略)
[root@test1 files]# service mysql stop
Shutting down MySQL.. SUCCESS!
[root@test1 files]# chkconfig mysql off
[root@test1 files]# rpm -qa | grep MySQL
MySQL-client-5.6.24-1.el6.x86_64
MySQL-server-5.6.24-1.el6.x86_64
MySQL-devel-5.6.24-1.el6.x86_64
[root@test1 files]# rpm -e --nodeps MySQL-client-5.6.24-1.el6.x86_64 MySQL-server-5.6.24-1.el6.x86_64 MySQL-devel-5.6.24-1.el6.x86_64
进行安装操作
[root@test1 files]# rpm -ivh MySQL-Cluster-server-gpl-7.3.8-1.el6.x86_64.rpm
[root@test1 files]# rpm -ivh MySQL-Cluster-client-gpl-7.3.8-1.el6.x86_64.rpm
添加用户信息:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges ;
创建工作目录及文件配置:
[root@test1 var]# mkdir /var/mysql-cluster
[root@test1 var]# mkdir /var/lib/mysql/data
[root@test1 var]# mkdir /var/run/mysqld
[root@test1 var]# chmod -R 1777 /var/lib/mysql
[root@test1 var]# chmod -R 1777 /var/run/mysqld
[root@test1 var]# chmod -R 1777 /var/lib/mysql-cluster
[root@test1 var] vi /etc/config.ini
[computer]
Id=mgr-server-01
HostName=192.168.1.240
[mgm default]
datadir=/var/lib/mysql-cluster
[mgm]
HostName=192.168.1.240
NodeId=60
ExecuteOnComputer=mgr-server-01
PortNumber=1186
ArbitrationRank=2
[ndbd default]
NoOfReplicas=2
DataMemory=500M
IndexMemory=500M
[ndbd]
HostName=192.168.1.240
DataDir=/var/lib/mysql
NodeId=1
[ndbd]
HostName=192.168.1.241
DataDir=/var/lib/mysql
NodeId=2
[root@test1 var] vi /etc/my.conf
[client]
socket=/var/lib/mysql/mysql.sock
[mysqld]
max_connections=100
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
ndbcluster
ndb-connectstring=192.168.1.240
[mysqld_safe]
log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid
pid-file=/var/lib/mysql/mysqld.pid
[mysql_cluster]
ndb-connectstring=192.168.1.240
启动:
注:关闭防火墙设置(可待调试成功后重新开启防火墙仅开放用到的端口),selinux 设为 disabled
顺序:管理节点->均衡节点->数据节点 (关闭时相反:数据节点 service mysql stop ->均衡节点 ndb_mgm -e shutdown)
[root@test1 mysql-cluster]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini //启动 管理节点 操作
MySQL Cluster Management Server mysql-5.6.22 ndb-7.3.8
[root@test1 mysql-cluster]# ndbd --initial //均衡节启动 首次启动加 --initial 再次不需加
[root@test1 mysql-cluster]# mysqld_safe --defaults-file=/etc/my.cnf --explicit_defaults_for_timestamp & //启动数据节点
查看连接情况:
[root@test1 ~]# ndb_mgm -- NDB Cluster -- Management Client -- ndb_mgm> show Connected to Management Server at: 192.168.1.240:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=1 @192.168.1.240 (mysql-5.6.22 ndb-7.3.8, Nodegroup: 0) id=2 @192.168.1.241 (mysql-5.6.22 ndb-7.3.8, Nodegroup: 0, *) [ndb_mgmd(MGM)] 1 node(s) id=60 @192.168.1.240 (mysql-5.6.22 ndb-7.3.8) [mysqld(API)] 2 node(s) id=81 @192.168.1.240 (mysql-5.6.22 ndb-7.3.8) id=82 @192.168.1.241 (mysql-5.6.22 ndb-7.3.8)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
进入mysql出错处理:
mysqld_safe --skip-grant-tables &
mysql -uroot -p
>use mysql;
>update mysql.user set password=PASSWORD('123456') where User='root' ;
>flush privileges ;
or
//在mysql 配置文件中加入以下一句话 ,重新启动输入 mysql 进入命令行修改密码
[root@test1 files]# vi /etc/my.cnf
[mysqld]
skip-grant-tables
[root@test1 files]# mysql
出错:
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
>SET PASSWORD = PASSWORD('123456');