常用数据库操作语句(1)

建库
CREATE DATABASE IF NOT EXISTS gloryroad DEFAULT CHARSET utf8 COLLATE
utf8_general_ci;
建表
create table studentInfo(
ID int not null auto_increment comment "不为空的自增长的主键ID",
student_id varchar(20) not null,
name varchar(30) not null,
sex char(4),
tel varchar(13) unique not null,
AdmissionDate datetime default '0000:00:00 00:00:00',
primary key (ID),
unique student_id(student_id)
)engine=innodb character set utf8 comment "学生信息表";

查看有哪些数据库
show DATABASES

选择使用那个数据库
use python
查看有哪些数据库表
show TABLES
删除数据库
drop TABLE demo;

创建数据库用户
create USER 'hhq'@'%' IDENTIFIED by "123456";
%可以指定ip,只有指定ip的人可以连接此数据库

更新表字段的值
update USER set PASSWORD=PASSWORD('11111') where user='hhq1'
给用户赋权限
GRANT all privileges on . to test@'%' identified by '123456'
flush privileges;

use python;
SELECT DATABASE();查看当前的库
查看当前连接用户
SELECT user();

猜你喜欢

转载自blog.51cto.com/13496943/2139267