create table `t1` (
`id` int(11) unsigned not null auto_increment,
`user_id` int(11) not null default 0 comment'',
`title` varchar(255) not null default '' comment'',
`context` text comment'',
`money` decimal(10,2) not null default 0.00 comment'',
`status` tinyint(4) not null default '0' comment'',
`ctime` int(11) unsigned not null default 0,
`uptime` int(11) unsigned not null default 0,
primary key (`id`),
UNIQUE KEY `title` (`title`) USING BTREE,
KEY `user_id` (`user_id`) USING BTREE,
KEY `user_id_join_title` (`user_id`,`title`)
) engine=InnoDB auto_increment=1 default charset=utf8mb4 comment='';
create table `t1` (
`id` int(11) unsigned not null auto_increment,
primary key (`id`)
) engine=InnoDB auto_increment=1 default charset=utf8mb4 comment='';
alter table `t1` add column `user_id` int(11) not null default 0 comment'';
alter table `t1` add column `title` varchar(255) not null default '' comment'';
alter table `t1` add column `context` text comment'';
alter table `t1` add column `money` decimal(10,2) not null default 0.00 comment'';
alter table `t1` add column `status` tinyint(4) not null default '0' comment'';
alter table `t1` add column `ctime` int(11) unsigned not null default 0;
alter table `t1` add column `uptime` int(11) unsigned not null default 0;
alter table `t1` add PRIMARY KEY (`id`)
alter table `t1` add INDEX index_name (`user_id`)
alter table `t1` add UNIQUE (`title`)
alter table `t1` add INDEX index_name (`user_id`,`title`)
alter table `t1` add FULLTEXT (`column`)
下载mysql历史版本
https://downloads.mysql.com/archives/community/
忘记密码
关闭mysql5.7
cd /usr/local/mysql/bin/
sudo ./mysqld_safe --skip-grant-tables
开另一个窗口修改密码
mysql
update mysql.user set authentication_string=PASSWORD(‘123456’) where User=‘root’;
FLUSH PRIVILEGES;
关闭进程
ps -ef|grep mysql
登入
mysql -uroot -h127.0.0.1 -p
修改密码
alter user ‘root’@‘localhost’ identified by ‘Ma123456’;
查看数据库
show databases;
进入数据库
use databases;
查看当前所在数据库下面的所有表
show tables;
查看数据库下面的表的字段
show columns from database.table
grant 授权
grant all privileges on . to root@127.0.0.1 identified by “123456” with grant option;
grant 表示授权 all privileges表示用户可以有所有的权限 on . (.的前面表示什么数据库,后面表示数据库里面的什么表 . 表示所有的数据库里面的所有表)
to 给哪个用户授权 @表示这个用户必须在哪里登录才有这个权限 如有你想给所有ip 那么要使用 root@’%’ identified
在刷新完权限之后要执行 flush privileges; 使他生效
mysql 四种权限 增删查改 select insert update delete
定义存储过程
delimiter $$
create procedure func1()
begin
...
end
$$
delimiter ;
调用存储过程
call func1();
定义触发器
delimiter $$
create trigger add_salary
before insert on employee
for each row
BEGIN
set NEW.salary = NEW.salary + 1000;
end
$$
delimiter ;
查看触发器
show triggers;