sswrod -P$port
2、用户操用
(1)创建用户
方法一:
insert into mysql.user(user,host,password) values('mytest','localhost',password('1234'));
flush privilege;
方法二:create user mystest@'%' identified by '1234';
(2)用户授权
单纯的授权
grant all privileges on *.* to mytest@localhost;
grant insert,update,delete,select on *.* to mytest@localhost;
授权并创建用户
grant all privileges on *.* to mytest@localhost identified by '1234';--创建用户并刷缓存,
(等同于:insert into mysql.user ,flush privilege)
grant all privileges on *.* to mytest@localhost; --对象权限
grant super on *.* to mytest@'%'; --系统权限 (supert相当于oracle中的dba权限)
3、实操
show databases; --查看所有的
数据库
use mysql; --切到my
sql数据库
use tables; --在mysql库的tables
select user,host,password from mysql.user; ----查mysql的所有用户,这个是由mysql_install_db创建的
grant all privilege on *.* to test_1@'%'; --all代表(select update,delete,alter admin,super_acl),第一个*用户,第二个*对象,%所有的主机
mysql -h127.0.0.1 -utest_1 ----用grant创建的用户登录mysql
select user(); ---当前是什么用户
create database jianfeng; ---创建数据库(mysql中的数据库类似于oracle中的schema
create table user(id int) engine=innodb ---创建表;
grant select on jianfeng.user to test_1@'%'; ---jianfeng.user表的查询授权给test_1用户
insert into mysql.user(user,host,password) values('test_2','%',password('1234')); --用这种方法创建test_2用户,有个问题权限没有
flush privileges; ---把mysql.user表的用户权限重新刷到内存中
show master status\G;
change master to xxx;
show processlist; ---查看当前用户的连接,线程形式(类似oracle中的v$session)
4、drop table处理
rename table test_1 to test;(可以快速切回来rename table test to test_1;)
备份mysqldump:mysqldump -h127.0.0.1 -uroot mydb gyj_t1 >/tmp/gyj_t1.sql
drop table test;
5、自增主键(最好是自己定义主键,系统默认的是全局的增量)
create table test (id int primary key auto_increment,name varchar(100)) engine=innodb;
show create table test\G;
create index test_name_idx on test(name);
show create table test\G;
insert into test(name) values('test');
commit;
select * from test;
6、alter table处理 --会动原来的数据,需要拷贝数据
alter table test add coll int;
7、执行计划
select * from test where id=1\G;
explain select * from test where id=1;
create index test_id_coll_idx on test(id,coll);
explain select * from test where id=1;
create index test_col_name on test(coll,name);
explain select * from test where coll>10 and name='xx';
show create table test\G;
alter table test drop index test_name_idx;
explain select * from test where coll>10 and name>'xx';
8、数据导出
(1)用dump导出数据
mysqldump -h127.0.0.1 -uroot mydb gyj_t1 >/tmp/xx.sql
drop table test;
source /tmp/xx.sql --导入数据
(2)用select导出数据
select * from test into outfile '/tmp/yy.sql';
9、数据迁移
(1)停机方式
mysqldump/loadata
(2)不停机方式
物理上:搭备库(可以级联5.5-->5.6,向下兼容的)
把主库read only,备库就能把主库转过来的binlog消化完,再把备库切为主
show variables like '%read%';
set global read_only=on;
insert into test(name) values('xx'); --插不进的,不能用root用户
(3)不同平台小表:oracle--->mysql
脚本:synfull.pl
(4)不同平台的一个大表迁多:增量迁移
a.把数据的全量迁过去
b.把迁的过程中产生的日志传过去
c.apply增量
d.锁表切切换
(5)增量
a.Oracle:物化视图
b.MySQL:trigger
create trigger tri_test
before insert,delete,update
insert test_log value(type,id);
end;
/
insert into test values(1,'xxx');
test_log value('insert','1');
lock table test;
应用切换
10、binlog
reset master; --会把当前的binlog清掉
show binlog events;
create table x1(id int);
show binlog events;
insert into x1 values(1);
commit;
show binlog events;
类似于: mysqlbinlog -vvv binlog.00001 > /tmp/binlog.log
vi /tmp/binl |