ITeye博客

MySQL语法

tianhei · 2010-11-16 14:19 · 数据库 · 数据库 · 数据结构 · MySQL · Markdown

primary key 主键 不能为空 唯一
foreign key 外键 其它表的主键

unique key 唯一键 可以为空 唯一

 

一、mysql语句

1、显示所有数据库

     show databases;

2、使用数据库 test

     use test;

3、创建数据库 test

     create database test;

4、显示所有表

     show tables;

5、显示 user 表的结构

     show create table user;

6、在stu表中增加字段 password

     alter table stu add column(password char(16));

     alter table stu add (password char(16));

7、向stu表中插入数据

     insert into stu values('a','b',27,'d');

     insert into stu(name,password,age,sex) values('a','b',27,'d');

8、查看当前mysql字符集的参数

     show variables like 'character_set_%';
     show variables like 'collation_%';

9、修改test数据库的字符集:
     alter database test default character set utf8 collate utf8_general_ci;

10、显示user表的索引:

     show index from user;

11、在user表中创建索引,索引名为index_name,索引关联user表的name字段。

     alter table user add index index_name(name);

12、删除user表中的索引 index_name:

     drop index_name on user;

13、创建空用户
     grant all privileges on *.* to ''@localhost identified by '1';
     grant all privileges on *.* to ''@localhost identified by '';

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。