Home > Database > Mysql Tutorial > mysql常用命令整理总结_MySQL

mysql常用命令整理总结_MySQL

WBOY
Release: 2016-06-01 13:02:40
Original
943 people have browsed it

#修改字段类型
alter table `table_name` modify column ip varchar(50);

#增加字段
alter table `table_name` add ip varchar(50);

#增加PRIMARY KEY(主键索引)
ALTER TABLE `table_name` ADD PRIMARY KEY ( `ip` );

#添加UNIQUE(唯一索引)
ALTER TABLE `table_name` ADD UNIQUE ( `ip` );

#添加INDEX(普通索引)
ALTER TABLE `table_name` ADD INDEX ip ( `ip` );

#添加联合索引
ALTER TABLE `table_name` ADD INDEX userip ( `ip`, `name` );

#添加FULLTEXT(全文索引)
ALTER TABLE `table_name` ADD FULLTEXT ( `column`);

#删除索引
alter table `table_name` drop index ip ;

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.3.150' IDENTIFIED BY
'mypassword' WITH GRANT OPTION;

#新增一个用户名test,密码123的用户链接host为localhost,也可以写成ip,或者192.168.0.%(192.168.0.任意),或者 %(不限制host)
insert into mysql.user(Host,User,Password,ssl_cipher,x509_issuer,x509_subject) values("localhost","test",password("123"),'','','');
#新增完成后刷新权限表
flush privileges;

#授权相关

#授权所有数据库的权限给用户名为test密码为123的用户
grant all privileges on *.* to test@localhost identified by '123';

#授权所有数据库的权限给用户名为test密码为123的用户,且test具有给其他用户授权的权限
grant all privileges on *.* to test@localhost identified by '123' WITH GRANT OPTION;

#授权testdb数据库的select权限给用户名为test密码为123的用户
grant select on testdb.* to test@localhost identified by '123';

#授权完成后刷新权限表
flush privileges;

#字段类型

数值型的列类型包括整型和浮点型两大类。

TINYINT:1字节 非常小的正整数,带符号:-128~127,不带符号:0~255
SMALLINT:2字节 小整数,带符号:-32768~32767,不带符号:0~65535
MEDIUMINT:3字节 中等大小的整数,带符号:-8388608~8388607,不带符号:0~16777215
INT:4字节 标准整数,带符号:-2147483648~2147483647,不带符号:0~4294967295
BIGINT:8字节 大整数,带符号:-9223372036854775808~9233372036854775807,不带符号:0~18446744073709551615
FLOAT:4字节 单精度浮点数,最小非零值:+-1.175494351E-38,最大非零值:+-3.402823466E+38
DOUBLE:8字节 双精度浮点数,最小非零值:+-2.2250738585072014E-308,最大非零值:+-1.7976931348623157E+308
DECIMAL(M, D):M+2字节 以字符串形式表示的浮点数,它的取值范围可变,由M和D的值决定。

字符型
一个字符一个字节,一个汉字=2个字符,2个字节

CHAR[(M)] M字节 固定长度
VARCHAR[(M)] M字节 可变长度,存储大小为输入数据的字节的实际长度
TINYBLOD,TINYTEXT 2^8-1字节 L+1字节
BLOB,TEXT 2^16-1字节 L+2
MEDIUMBLOB,MEDIUMTEXT 2^24-1字节 L+3
LONGBLOB,LONGTEXT 2^32-1字节 L+4
ENUM('value1','value2',...) 65535个成员 1或2字节
SET('value1','value2',...) 64个成员 1,2,3,4或8字节

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template