SHOW DATABASES;
CREATE DATABASE db_name;
DROP DATABASE db_name;
CREATE TABLE tb_name ( 字段1 数据类型 [列级别约束条件] [默认值], 字段2 数据类型 [列级别约束条件] [默认值], [表级约束条件] );
SHOW TAELES;
定义列的同时定义主键
CREATE TABLE tb_name ( 字段1 数据类型 PRIMARY KEY [默认值], );
最后定义
CREATE TABLE tb_name ( 字段1 数据类型 [列级别约束条件] [默认值], 字段2 数据类型 [列级别约束条件] [默认值], [CONSTRAINT <约束名>] PRIMARY KEY [字段名] );
多个主键
CREATE TABLE tb_name ( PRIMARY KEY [字段1,字段2,...] );
使用外键
[CONSTRAINT <外键名>] FOREIGN KEY 字段1[,字段2,...] REFERENCES <主表名> 主键列1[,主键列2,...]
使用非空约束
字段名 数据类型 NOT UNLL
使用唯一约束
字段名 数据类型 UNIQUE
设置自动增加
字段名 数据类型 AUTO_INCREMENT
查看表
DESCRIBE tb_name; DESC tb_name;
mysql -u user_name -p
mysqladmin -u root password "mypasswd";
create user 'user_name'@'localhost' identified by 'mypassword';
SHOW VARIABLES LIKE 'validate_password%';
LOW Length >= 8 characters. MEDIUM Length >= 8, numeric, mixed case, and special characters. STRONG Length >= 8, numeric, mixed case, special characters and dictionary file.
SET GLOBAL validate_password.policy=LOW;
alter user 'root'@'localhost' identified by '123';
4.1 Your password has expired
解决办法:
修改密码
alter user 'root'@'localhost' identified by '123';
设置永不过期
alter user 'root'@'localhost' identified by '123' expired never;
会过期
alter user 'root'@'localhost' identified by '123' expired default;