注:本文加粗词表示不是固定写法,只是任意参数。
1、查询数据库
show databases;
2、删除数据库
drop database db_name;
drop database if exists db_name; --指定参数if exists,假如该数据库不存在,执行语句不报错而是报warning,可以通过show warning查看报警信息。
3、新建数据库
create database db_name;
4、新建表
create table tb_name(col1_ name col1_type,col2_name col2_type......);--(col1=列名,type=数据类型)。
5、查询表
show tables;
6、查询表内容
desc tb_name;
7、修改表内容
①向列增加内容
alter table tb_name add (col1_type,col2_type);
②删除列
alter table tb_name drop col_name;
③修改列定义,有两种写法
一、alter table tb_name change col_name new_col col_type;--可以修改列名
二、alter table tb_name modify col_name col_type;--只修改列数据类型
8、删除表
drop table tb_name;
9、移动&重命名表
rename table tb_name to new_tb_name;
10、创建用户
create user user_name@'host_name' identified by 'password' ;
11、修改用户密码
set password for user = password ('password') | old_password('password');--password和old_password是两个密码专用函数,将密码以字符串形式保存。
12、让用户的密码过期
alter user user_name password expire;--此时用户仍然可以登录,但是登录用户后不可以做任何操作。