【数据库使用】mysql基本使用

mysql启动

../bin/mysqld --defaults-file=./mysql/my.cnf --user=root

这里的--user是什么意思呢

mysql创建一个数据表student,需要有3个字段:id、name、age,其中指定唯一的索引是id。

mysql> create table student(
    -> id int not null,
    -> name varchar(16) not null,
    -> age int not null,
    -> unique index idx (id)
    -> );

  查看数据表:

mysql> desc teacher;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| name  | varchar(16) | NO   |     | NULL    |       |
| age   | int(11)     | NO   |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

  查看索引

mysql> show index from teacherG;
*************************** 1. row ***************************
        Table: teacher
   Non_unique: 0
     Key_name: idx
 Seq_in_index: 1
  Column_name: id
    Collation: A
  Cardinality: 0
     Sub_part: NULL
       Packed: NULL
         Null: 
   Index_type: BTREE
      Comment: 
Index_comment: 
1 row in set (0.00 sec)

ERROR: 
No query specified

  

大道至简
原文地址:https://www.cnblogs.com/liurong07/p/10407096.html