创建root用户密码为123
use mysql;
grant all on *.* to root@'%' identified by '123' with grant option;
commit;
3、修改密码
grant all on *.* to xing@'localhost' identified by '123456' with grant option;
update user set password = password('newpwd') where user = 'xing' and host='localhost';
flush privileges;
4、创建数据库testdb:
create database testdb;
5、预防性创建数据库:
create database if not testdb;
6、创建表:
use testdb;
create table table1( username varchar(12), password varchar(20));
7、预防性创建表aaa:
create table if not exists aaa(ss varchar(20));
8、查看表结构:
describe table1;
9、插入数据到表table1:
insert into table1(username,password) values ('leizhimin','lavasoft'), ('hellokitty','hahhahah');
commit;
10、查询表table1:
select * from table1;
11、更改数据:
update table1 set password='hehe' where username='hellokitty';
commit;
12、删除数据:
delete from table1 where username='hellokitty';
commit;
13、给表添加一列:
alter table table1 add column( sex varchar(2) comment '性别', age date not null comment '年龄');
commit;
14、修改表结构
从查询创建一个表table1:
create table tmp as select * from table1;
15、删除表table1:
drop table if exists table1;
drop table if exists tmp;