MySQL的链接,查看数据库,使用数据库,查看表

MySQL的链接,查看数据库,使用数据库,查看表

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| qq                 |
| test               |
+--------------------+
5 rows in set (0.06 sec)

mysql> use qq;
Database changed
mysql> desc qq;
ERROR 1146 (42S02): Table 'qq.qq' doesn't exist
mysql> desc table;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table' at line 1
mysql> set name gbk;
ERROR 1193 (HY000): Unknown system variable 'name'
mysql> set names gbk;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
+--------------+
| Tables_in_qq |
+--------------+
| stu          |
+--------------+
1 row in set (0.01 sec)

mysql> desc stu;
+-------+------------+------+-----+---------+-------+
| Field | Type       | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| id    | int(11)    | YES  |     | NULL    |       |
| name  | varchar(4) | YES  |     | NULL    |       |
+-------+------------+------+-----+---------+-------+
2 rows in set (0.02 sec)

mysql> select * from stu;
+------+------+
| id   | name |
+------+------+
|    1 | lisi |
| NULL | 李四    |
+------+------+
2 rows in set (0.01 sec)

mysql> insert into stu values
    -> (2,'zhangsan');
ERROR 1406 (22001): Data too long for column 'name' at row 1
mysql> insert into stu values
    -> (2,'zhangsan')
    -> (3,'zhan');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(3,'zhan')' at line 3
mysql> insert into stu values
    -> (2,'zhan');
Query OK, 1 row affected (0.00 sec)

mysql> show tables;
+--------------+
| Tables_in_qq |
+--------------+
| stu          |
+--------------+
1 row in set (0.00 sec)

mysql> select (name) from stu;
+------+
| name |
+------+
| lisi |
| 李四    |
| zhan |
+------+
3 rows in set (0.00 sec)

mysql> delete form where id=3;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where id=3' at line 1
mysql> delete from stu where id=3;
Query OK, 0 rows affected (0.02 sec)

mysql> select (name) from stu;
+------+
| name |
+------+
| lisi |
| 李四    |
| zhan |
+------+
3 rows in set (0.00 sec)

mysql> select * from stu;
+------+------+
| id   | name |
+------+------+
|    1 | lisi |
| NULL | 李四    |
|    2 | zhan |
+------+------+
3 rows in set (0.00 sec)

mysql> delete from stu where id
    -> id=null;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id=null' at line 2
mysql> delete from stu where id=null;
Query OK, 0 rows affected (0.00 sec)

mysql> delete from stu where id=NULL;
Query OK, 0 rows affected (0.00 sec)

mysql> delete from stu where id='';
Query OK, 0 rows affected (0.00 sec)

mysql> delete from stu where id=2;
Query OK, 1 row affected (0.00 sec)

mysql> select * from stu;
+------+------+
| id   | name |
+------+------+
|    1 | lisi |
| NULL | 李四    |
+------+------+
2 rows in set (0.00 sec)

mysql> insert into classs
    -> /c
    -> c
mysql> 
mysql> insert into class(
    -> c
mysql> create table class(
    -> id int primary key auto_increment,
    -> sname varchar(10) not null default '',
    -> gender char(1) not null default '',
    -> company varchar(20) not null default '',
    -> salary decimal (6,2) not null default 0.00
    -> )engine myisam charset utf8;
Query OK, 0 rows affected (0.08 sec)

mysql> desc class;
+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int(11)      | NO   | PRI | NULL    | auto_increment |
| sname   | varchar(10)  | NO   |     |         |                |
| gender  | char(1)      | NO   |     |         |                |
| company | varchar(20)  | NO   |     |         |                |
| salary  | decimal(6,2) | NO   |     | 0.00    |                |
+---------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> insert into class
    -> values
    -> (1,'张三','男','百度',7000);
Query OK, 1 row affected (0.03 sec)

mysql> show table from class;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from class' at line 1
mysql> select * form class;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'form class' at line 1
mysql> select * from class;
+----+-------+--------+---------+---------+
| id | sname | gender | company | salary  |
+----+-------+--------+---------+---------+
|  1 | 张三      | 男       | 百度       | 7000.00 |
+----+-------+--------+---------+---------+
1 row in set (0.01 sec)

mysql> insert into
    -> (name,gender,company)
    -> values
    -> ('lisi','男','ibm');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(name,gender,company)
values
('lisi','男','ibm')' at line 2
mysql> insert into class
    -> (name,gender,company)
    -> values
    -> ('lisi','男','ibm')
    -> ;
ERROR 1054 (42S22): Unknown column 'name' in 'field list'
mysql> insert into class
    -> (sname,gender,company)
    -> values
    -> ('lizi','男','ibm');
Query OK, 1 row affected (0.00 sec)

mysql> select * from class;
+----+-------+--------+---------+---------+
| id | sname | gender | company | salary  |
+----+-------+--------+---------+---------+
|  1 | 张三      | 男       | 百度       | 7000.00 |
|  2 | lizi  | 男       | ibm     |    0.00 |
+----+-------+--------+---------+---------+
2 rows in set (0.00 sec)

mysql> select * from class where company;
Empty set, 2 warnings (0.00 sec)

mysql> select * from class;
+----+-------+--------+---------+---------+
| id | sname | gender | company | salary  |
+----+-------+--------+---------+---------+
|  1 | 张三      | 男       | 百度       | 7000.00 |
|  2 | lizi  | 男       | ibm     |    0.00 |
+----+-------+--------+---------+---------+
2 rows in set (0.00 sec)

mysql> select company from class;
+---------+
| company |
+---------+
| 百度       |
| ibm     |
+---------+
2 rows in set (0.00 sec)

mysql> select * from class where id=2;
+----+-------+--------+---------+--------+
| id | sname | gender | company | salary |
+----+-------+--------+---------+--------+
|  2 | lizi  | 男       | ibm     |   0.00 |
+----+-------+--------+---------+--------+
1 row in set (0.00 sec)

mysql> #改,改哪张表,哪几列, 哪几行,改成什么值。
mysql> update class
    -> set salary=7800
    -> where id=2;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from class;
+----+-------+--------+---------+---------+
| id | sname | gender | company | salary  |
+----+-------+--------+---------+---------+
|  1 | 张三      | 男       | 百度       | 7000.00 |
|  2 | lizi  | 男       | ibm     | 7800.00 |
+----+-------+--------+---------+---------+
2 rows in set (0.02 sec)
原文地址:https://www.cnblogs.com/lzzhuany/p/4659073.html