版本号
mysql -V
指定主机,用户名,密码
mysql -h主机ip -uroot -p密码
修改用户密码
mysqlladmin -u用户名 -p旧密码 password新密码
显示所有数据库
show databases;
使用数据库
use 数据库名称;
显示当前数据库
select database();
显示当前服务器版本
select version();
显示当前时间
select now();
显示当前用户
select user();
创建数据库
create database if not exists 数据库名称 default character set 编码格式;
修改数据库编码格式
alert database 数据库名称 character set 编码格式;
查看数据库的编码格式
show variables like 'character%';
删除数据库
drop database if exist 数据库名称;
查看数据表列表
show tables from db_name; 或者 show tables;
查看数据表基本结构
show columns from 表名称;或 desc 表名称;
查看数据表创建语句
show create table 表名称;
添加一列
alter table 表名称 add 字段名 字段类型 约束 after 字段;
修改列名
alter table 表明 change 旧字段名称 新字段名称 新字段类型 约束;
修改表字段的数据类型
alter table 表名称 modify 字段名 新的字段类型;
修改数据表列的位置
alter table 表名称 modify 字段 约束 after 字段;
删除数据表中某一列
alter table 表名称 drop 字段名;
修改表名称
alter table 表名称 rename to 新表名称;
删除数据库表
drop table if exist 表名称1,表名称2;
查看数据表是否支持表分区
show plugins;
对已经存在的表添加列
alter table 表名 add 新列名 数据类型 约束类型 after 已存在的列名;
修改列名称
alter table 表名 change 旧列名 新列名 新数据类型;
修改列的数据类型
alter table 表名 modify 字段名 数据类型;
修改列的排列位置
alter table 表名 modify 字段名 字段类型 after 字段名;
删除某一列
alter table 表名 drop 字段名;
修改表名称
alter table 表名称 rename to 新表名称;
删除数据表
drop table if exists 表1,表2,...........;
创建数据表的时候进行表分区
例如:create table test( book_id int, book_name varchar(10)) partition by range(book_id)(partition p1 values less than(11111),partition p2 values less than(22222),partition p3 less than MAXVALUE);
查询表分区
select * from test partition(p1);