不会的要多查多问,不然不会的永远不会,哪怕你离会就差了那么一点点
mysql 常用SQL汇总
[ 2016/09/07 15:17 | by 刘新修 ]
SQL代码
- 1.用管理员登陆
- mysql -u root -p;
- 2.创建数据库
- create database nodeDB;
- 3.删除数据库
- drop database nodeDB;
- 4.查看数据库
- show databases;
- 5.选择目标库
- use nodeDB;
- 6.查看目标表所有字段
- select * from user;
- 7.创建用户
- //user01只能本地访问
- CREATE USER user01@'localhost' IDENTIFIED BY 'user01';
- //user02可以远程访问
- CREATE USER user02@'%' IDENTIFIED BY 'password1';
- 8.修改user01密码
- SET PASSWORD FOR 'user01'@'localhost'=PASSWORD('password2');
- 9.授权
- //user01管理db01全部权限
- GRANT ALL PRIVILEGES ON nodeDB.* TO user01;
- //user02查看权限,并修改密码
- GRANT SELECT ON *.* TO 'user02'@'%' IDENTIFIED by 'password2';
- 10. 刷新数据库
- flush privileges;
创建测试表:
SQL代码
- //判断有库就删除
- drop database if exists school;
- create database school;
- use school;
- create table teacher(
- id int(3) auto_increment not null primary key,
- name char(10) not null,
- address varchar(50) default '深圳',
- year date
- );
- //以下为插入字段
- insert into teacher values(null,'allen','大连一中','1976-10-10');
- insert into teacher values(null,'jack','黄冈中学','1975-12-23');
- insert into teacher values(null,'jesse','北京四中','1980-6-23');
- insert into teacher values(null,'tony','衡水中学','1982-2-12');