mysql -h 192.168.1.163 -u root -p 123456 #h表示访问的数据库的宿主ip,u表示数据库用户名,p为密码
mysqladmin -u 用户名 -p 旧密码 password 新密码
create database <数据库名>; #创建数据库
show databases; #显示数据库
drop database <数据库名>; #删除数据库
use <数据库名>; #使用数据库
create table <表名> (<字段名1> <类型1> [,..<字段名n> <类型n>]); #创建表
desc 表名; #描述表
drop table <表名>; #删除表
rename table 原表名 to 新表名; #重命名表名
insert into <表名> [(<字段名1>[,..<字段名n > ])] values ( 值1 )[, ( 值n )]; #添加数据
select <字段1, 字段2, ...> from < 表名 > where < 表达式 >; #查询数据
delete from 表名 where 表达式 #删除数据
update 表名 set 字段=新值,… where 条件; #更新数据
alter table 表名 add字段 类型 其他; #增加字段
alter table 表名 modify column 字段 新类型(长度); #修改字段类型
alter table 表名 drop 字段; #删除字段
alter table 表名 drop index 字段 #删除字段唯一性
- 有时候正常的修改语句:ALTER TABLE table_name ALTER COLUMN column_name TYPE integer; 执行会报错,cannot be cast automatically to type integer,这个时候可以使用: ALTER TABLE table_name ALTER COLUMN column_name TYPE integer USING(column_name::integer);