1.mysql 管理语句
1)展示数据库列表
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | data_store | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) mysql>
2)进入到相应数据库
mysql> use data_store; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed
3)显示表
mysql> show tables;
+----------------------+
| Tables_in_data_store |
+----------------------+
| sec_menu_item |
| sec_menu_role |
| sec_role |
| sec_user |
| sec_user_copy |
| sec_user_role |
| sec_user_test |
| stream_test_save |
| test1 |
| test1234 |
| test1_1 |
| test2 |
| test5 |
| test_hdfs_from_mysql |
4)显示表中的列信息
mysql> show columns from test5; +-------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------------+------+-----+---------+-------+ | name | text | YES | | NULL | | | age | bigint(20) | YES | | NULL | | +-------+------------+------+-----+---------+-------+ 2 rows in set (0.00 sec)
5)显示表中的索引信息
mysql> show index from sec_user; +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | sec_user | 0 | PRIMARY | 1 | id | A | 5 | NULL | NULL | | BTREE | | | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 1 row in set (0.00 sec)
6)显示表状态
mysql> show table status from data_store; mysql> show table status from data_store like 'test%';
2.创建数据库
mysql> create database test; Query OK, 1 row affected (0.01 sec)
删除数据库
mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)
4.创建表
create table runoob_tb1( runoob_id int not null auto_increment, runoob_title varchar(100) not null, runoob_author varchar(40) not null, submission_date date, primary key (runoob_id) )engine=innodb default charset=utf8;
not null :设置对应字段不能为null,若插入的值为null,则会报错
primary key 指定的是主键,一般是自增的
5.删除表
mysql> drop table runoob_tb1; Query OK, 0 rows affected (0.07 sec)
6.插入数据
insert into runoob_tb1( runoob_title,runoob_author,submission_date ) values ("学习python","菜鸟教程",now()), ("学习scala","菜鸟教程",now()); Query OK, 2 rows affected, 2 warnings (0.00 sec) Records: 2 Duplicates: 0 Warnings: 2