Mysql学习笔记(一):
一、如何使用终端操作数据库?
1.如何登录数据库服务器?
C:\Users\20553>mysql -uroot -p123456
2.如何查询数据库服务器中所有数据库?
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)
3.如何选中某个数据库进行操作?
mysql> select * from mysql;
ERROR 1046 (3D000): No database selected
mysql> use mysql
Database changed
--sql语句中的查询语句
mysql> select * from mysql;
ERROR 1146 (42S02): Table 'mysql.mysql' doesn't exist
3.如何退出数据库服务器?
mysql> exit;
Bye
4.如何在数据库服务器中创建我们的数据库?
mysql> create database test ;
Query OK, 1 row affected (0.02 sec)
mysql> use test
Database changed
5.如何在数据库中查看有哪些数据表?
mysql> show tables;
Empty set (0.02 sec)
6.如何创建一个数据表?
create table pet(
name varchar(20),
owner varchar(20),
species varchar(20),
sex char(1),
birth date,
death date );
Query OK, 0 rows affected (0.04 sec)
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| pet |
+----------------+
1 row in set (0.00 sec)
mysql> select* from pet;
Empty set (0.00 sec)
7.查看创建数据表的结构?
discribe pet;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| owner | varchar(20) | YES | | NULL | |
| species | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| death | date | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.01 sec)
8.如何网数据表中添加数据记录?
mysql> insert into pet values('Puffball','Diane','hamster','f','1999-03-30',null) ;
Query OK, 1 row affected (0.01 sec)
mysql> select * from pet;
+----------+-------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+----------+-------+---------+------+------------+-------+
| Puffball | Diane | hamster | f | 1999-03-30 | NULL |
+----------+-------+---------+------+------------+-------+
1 row in set (0.01 sec)
学习时间:
- 周五 2022.04.22 21.09