mysql基础sql语句(2)
创建不同编码的数据库
utf8:
create database soulchild_utf8 default character set utf8 collate utf8_chinese_ci;
gbk:
create database soulchild_gbk default character set gbk collate gbk_chinese_ci;
查看所有数据库:
show databases;
根据条件查找数据库:
show databases like ‘soulchild%’;
查看当前数据库的表:
show tables;
查询mysql库中user表的,user、host字段
select user ,host from mysql.user;
查看指定数据库的表:
show tables in xxx;
show tables like ‘xxx’;
show tables from xxx;
查看当前所在数据库:
select database();
查看数据库版本:
select version();
查看当前用户:
select user();
查看当前时间:
select now();
删除数据库:
drop database soulchild;
进入数据库:
use soulchild;
删除用户:
方法1.
drop user ‘soulchild’@’localhost’;
flush privileges;
方法2.
delete from mysql.user where user=‘soulchild’ and host=‘localhost’;
flush privileges;
创建用户
方法1.(创建soulchild用户,允许10.0.0网段访问,密码为123)
create user soulchild@'10.0.0.%' identified by '123';
flush privileges;
方法2.(创建soulchild用户,对db1库拥有所有权限,允许localhost访问,密码为123)
grant all on db1.* to 'soulchild'@'localhost' identified by '123'
flush privileges;
查看用户权限
show grants for soulchild@'localhost';
收回权限
revoke delete on wordpress.* from 'soulchild'@'10.0.0.%';
修改用户密码
方法1.
alter user soulchild@‘10.0.0.%’ identified by ‘456’;
方法2.
update mysql.user set password=password('456') where user='soulchild';
建表
#字段名 类型 是否为空 default默认值
create table student(
id int(4) not null,
name char(20) not null,
age tinyint(2) not null default '0',
dept varchar(16) default null
);
清空一张表
truncate table test;