Install mysql
sudo apt-get install mysql-server mysql-client
sudo snap install mysql-workbench-community
sudo snap connect mysql-workbench-community:password-manager-service :password-manager-service
# for check
sudo netstat -tap | grep mysql
# get pwd
sudo cat /etc/mysql/debian.cnf
sql example
mysql -udebian-sys-maint -pqqdWvUpyYdfW9crD # depend on ur machine
show databases; # 查看有哪些数据库
create database test; # 创建名为test的数据库
use test; # 使用名为test的数据库
create table pet(name varchar(20), age int, sex char(1), brith date) # 创建表
show tables; # 查看所有的表
describe pet; # 查看表结构
select * from pet; # 查看表中所有记录
select * from pet where name='haha'; # 条件查找
insert into pet values('asd', '1999-03-30'); # 插入记录到表
delete from pet where name='haha'; # 条件删除
update pet set value='1111-01-01' where name='asd'; # 条件更改
create table user(id int primary key, name varchar(20)); # primary key 为主键
create table user(id int, name varchar(20), primary key(id, name)); # 联合主键
create table user3(id int primary key auto_increment, name varchar(20)); # 自增约束
insert into user3 (name) values('asdasd'); # 插入自增约束
alter table user3 add primary key(id); # 对已有的表进行主键约束
alter table user3 drop primary key; # 对已有的表删除主键约束
alter table user3 modify id int primary key; # 修改主键约束
create table user(id int, name varchar(20) unique); # 唯一约束
create table user(id int, name varchar(20) not null); # 非空约束
create table user(id int, name varchar(20), age int default 10); # 默认约束
# 以下为外键约束,classid的取值必须为classes表中id列中出现过的
create table user(id int, classid foreign key references classes(id));