xx.xx.xx.151 或 xx.xx.xx.158 johntest数据库NDBCluster引擎在进行join操作时,开销巨大,应避免使用
一、常用查看命令show table status where name='tb01'; 或 show table status;show create table xxx;show variables like '%max%'; show variables like 'datadir'; 可显示数据库文件存储位置 show variables like 'log_error';show engines; 或 show engine ndbcluster status;show global status; 或 show global status like "ndb%";二、常用操作命令create table xxx engine=MyISAM as select * from xxxx;alter table xxx engine=xxx;alter table xxx CONVERT TO CHARACTER SET gbk;select hex('ab') 6162 select char_length('我们') 2 select length('我们') 4 //基于GBK编码mysqldump -uxxx -pxxxx --default-character-set=latin1 -h58.129.0.xxx xxxdb update user set password = password('新密码') where user='root';flush privileges;三、具体操作实践mysql -uxxxx -pxxxxx -h58.129.0.151同时在158上进行了监控create database johntest default character set gbk;
CREATE TABLE `tb01` ( `idkey` int(11) unsigned NOT NULL AUTO_INCREMENT, `ipadd` varchar(20) DEFAULT NULL, `posttime` datetime DEFAULT NULL, `rnum` int(11) unsigned DEFAULT NULL, `txt` varchar(2048), `port` int(11) unsigned DEFAULT NULL, PRIMARY KEY (`idkey`)) ENGINE=ndbcluster DEFAULT CHARSET=gbk;
alter table tb01 auto_increment=1; //设置起始的 auto_increment 值set names gbk;insert into tb01 values (null,'58.129.0.171',now(),unix_timestamp(now()),'我们共有一个家,名字叫中国',3777);insert into tb01 values (null,'58.129.1.171',now(),unix_timestamp(now()),'兄弟姐妹都很多,景色也不错',3777);insert into tb01 values (null,'58.129.1.31',now(),unix_timestamp(now()),'家里藏着两条龙是长江与黄河',3777);insert into tb01 values (null,'58.129.1.244',now(),unix_timestamp(now()),'还有珠穆朗玛峰儿是最高山坡',3777);alter table tb01 add sex enum('男','女') default '男';alter table tb01 add gbname varchar(20);导入了新表 ftschool 文件为ftsch.sql文件描述如下CREATE TABLE `ftschool` ( `idkey` int(11) NOT NULL AUTO_INCREMENT, `oname` varchar(200) NOT NULL DEFAULT '', `sname` varchar(200) NOT NULL DEFAULT '', `jname` varchar(200) DEFAULT NULL, `pname` varchar(20) DEFAULT NULL, `12code` varchar(12) DEFAULT NULL, `stype` varchar(20) DEFAULT NULL, `leader` varchar(40) DEFAULT NULL, `leadertel` varchar(80) DEFAULT NULL, `lxr` varchar(40) DEFAULT NULL, `lxrtel` varchar(80) DEFAULT NULL, `lxrmail` varchar(80) DEFAULT NULL, `address` varchar(250) DEFAULT NULL, `jcode` char(3) DEFAULT NULL, `scode` char(3) DEFAULT NULL, `ipaddress` varchar(40) DEFAULT NULL, `intelcode` varchar(9) DEFAULT NULL, `wmap` varchar(50) DEFAULT NULL, `xmap` varchar(50) DEFAULT NULL, `surl` varchar(255) DEFAULT NULL, `ipaddress_s` int(11) unsigned NOT NULL DEFAULT '0', `ipaddress_e` int(11) unsigned NOT NULL DEFAULT '0', `picpath` varchar(255) DEFAULT NULL, `amap` varchar(50) DEFAULT NULL, `miaoshu` text, `incodes` text, `incodefile` varchar(255) DEFAULT NULL, `typeint` tinyint(4) DEFAULT NULL, PRIMARY KEY (`idkey`)) ENGINE=ndbcluster AUTO_INCREMENT=220 DEFAULT CHARSET=gbk;
导入了新表 ganbu 文件为ganbu.sql文件描述如下CREATE TABLE `ganbu` ( `idkey` int(11) NOT NULL AUTO_INCREMENT, `cp_index` int(11) NOT NULL DEFAULT '0', `zhiwu` varchar(20) NOT NULL DEFAULT '', `gbname` varchar(20) NOT NULL DEFAULT '', `status` int(4) NOT NULL DEFAULT '1', `zhiwucode` int(4) NOT NULL DEFAULT '0', PRIMARY KEY (`idkey`)) ENGINE=ndbcluster AUTO_INCREMENT=334 DEFAULT CHARSET=gbk;alter table ganbu modify idkey int(11) unsigned NOT NULL AUTO_INCREMENT; 将idkey 改为 unsigned类型1、存储过程的相关实验查看存储过程 show procedure status; 或 show create procedure johntest.XXXXX;注意:在ndbcluster 中,不同设备中的存储过程并不同步存储过程 将 ganbu 表是 idkey 与 tb01 idkey相同的 gbname赋值//以下过程中 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;中 02000对应SQLSTATE意为取到空行状态,其它可查相关资料 23000表示无法写入或复制表的键。
delimiter //CREATE PROCEDURE upgbname()begin DECLARE done INT DEFAULT 0; DECLARE theid int(11) unsigned; DECLARE cur1 CURSOR FOR select idkey from johntest.tb01; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; OPEN cur1; REPEAT FETCH cur1 INTO theid; IF NOT done THEN update tb01 set gbname= (select gbname from ganbu where idkey= theid) where idkey=theid; END IF; UNTIL done END REPEAT; CLOSE cur1; end;//执行如下,可正常运行call upgbname();2、触发器的相关实验向tb01表中增加数据时,自动将 ganbu表中idkey 对应gbname值赋给tb01表//update tb01 set gbname= (select gbname from ganbu where idkey= new.idkey) where idkey=new.idkey; 不能对本表操作向tb01表中增加数据时,自动将 tb02表中的idkey 与 txt 赋值CREATE TABLE `tb02` ( `idkey` int(11) unsigned DEFAULT NULL, `txt` varchar(2048) DEFAULT NULL) ENGINE=ndbcluster DEFAULT CHARSET=gbk;
DELIMITER |CREATE TRIGGER upgb AFTER INSERT ON tb01 FOR EACH ROW BEGIN insert into tb02 values(NEW.idkey,NEW.txt);end|DELIMITER ;show triggers;删除 drop trigger upgb;