创建数据库: create database 数据库名;
创建表(主键一般都要设置,后面的是设置字符集是 utf-8,区分字母大小写): create table 表名(字段 类型, 字段 类型, …, primary key(字段)) character set utf8 collate utf8_general_ci;
添加: insert into 表名 values(值, 值, …);
删除: delete from 表名 where 字段 = 条件;
查询: select 字段 from 表名 where 字段 = 条件;
修改: update 表名 set 字段 = 值 where 字段 = 条件;
删除表: drop table 表名;
清空表: set foreign_key_checks=0; // 非必须 truncate table 表名; set foreign_key_checks=1; // 非必须
查看表结构 desc 表名
查询数据库中所有的表名 select table_name from information_schema.tables where table_schema=‘数据库名’");
查询表的主键 select column_name from information_schema.key_column_usage where table_name = ‘表名’ and constraint_name=‘primary’
查询表的字段名 select column_name from information_schema.columns where table_name = ‘表名’;
MySQL 用户登录 mysql -u 用户名 -p 密码
MySQL root用户授权user用户拥有mdb的所有操作权限 grant all privileges on mdb.* to ‘user’@‘localhost’ identified by ‘你的user用户的密码’;
为创建的表添加外键 alter table 表名 add foreign key(要成为外键的字段) references 外表名(外表的主键);
重置 MySQL 数据库密码