mysql 一些知识点
常用的实用sql语句:
1.example: SELECT *,FROM_UNIXTIME(f_create_time/1000,'%Y-%m-%d %H:%i:%s') date from report.t_org_exam_num_day ORDER BY date desc
FROM_UNIXTIME()把毫秒级别的时间转换为年月日,时分秒格式的
2.查询mysql 建表时间:SELECT CREATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='db_campus(库名)' AND TABLE_NAME='tb_ilovi_device(表名)';
MySQL 查看表结构简单命令。
一、简单描述表结构,字段类型desc tabl_name;
显示表结构,字段类型,主键,是否为空等属性,但不显示外键。
二、查询表中列的注释信息
select * from information_schema.columns where table_schema = 'db' #表所在数据库
and table_name = 'tablename' ; #你要查的表
三、只查询列名和注释
select column_name,
column_comment from information_schema.columns where table_schema ='db' and
table_name = 'tablename' ;
四、#查看表的注释
select table_name,table_comment from information_schema.tables where table_schema = 'db' and table_name ='tablename'
查看MYSQL数据库中所有用户
mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
查看数据库中具体某个用户的权限
mysql> show grants for 'cactiuser'@'%';
mysql> select * from mysql.user where user='cactiuser' \G
查看user表结构 需要具体的项可结合表结构来查询
mysql> desc mysql.user;
Mysql数据库自带四个数据库的解析
参考网址见:https://www.cnblogs.com/bobi-PHP-blog/p/7508660.html
显示表的索引状态信息:
show index from [表名]
例如:
Show index from report.t_org_exam_join_member_day;
show databases;
show tables;
show table status;
show table status like 't_org_exam_join_member_day';
增加索引操作:
1.添加PRIMARY KEY(主键索引)
mysql>ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` )
2.添加UNIQUE(唯一索引)
mysql>ALTER TABLE `table_name` ADD UNIQUE (
`column`
)
3.添加INDEX(普通索引)
mysql>ALTER TABLE `table_name` ADD INDEX index_name ( `column` )
4.添加FULLTEXT(全文索引)
mysql>ALTER TABLE `table_name` ADD FULLTEXT ( `column`)
5.添加多列索引
mysql>ALTER TABLE `table_name` ADD INDEX index_name ( `column1`, `column2`, `column3` )
参考网址见:https://www.cnblogs.com/a-du/p/7117837.html
删除索引操作:
4.删除索引
可利用ALTER TABLE或DROP INDEX语句来删除索引。类似于CREATE INDEX语句,DROP INDEX可以在ALTER TABLE内部作为一条语句处理,语法如下。
(1)DROP INDEX index_name ON talbe_name
(2)ALTER TABLE table_name DROP INDEX index_name
(3)ALTER TABLE table_name DROP PRIMARY KEY
重命名表名操作:
mysql中如何修改表的名字?修改表名?
mysql> create table ts01 like ti_o_sms; #创建表结构.这样的建表方式,不仅仅是表的结构,连带着索引也会同时创建.
Query OK, 0 rows affected (0.02 sec)
mysql> alter table ts01 rename to ts01_new; #修改表名的语法:alter table rename to/as new_tablename;
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+--------------------+
| Tables_in_mytest |
+--------------------+
| sms_send_blacklist |
| td_b_sendobject |
| ti_o_sms |
| ts01_new |
+--------------------+
rows in set (0.00 sec)
或者
mysql> alter table ts01_new rename AS ts02;
Query OK, 0 rows affected (0.03 sec)
mysql> show tables;
+--------------------+
| Tables_in_mytest |
+--------------------+
| sms_send_blacklist |
| td_b_sendobject |
| ti_o_sms |
| ts02 |
+--------------------+
rows in set (0.00 sec)
参考网址见: https://www.cnblogs.com/chuanzhang053/p/9506674.html