在cmd中进行数据库或表的增删修改
1.cmd中直接连接数据库语法为:
>mysql -uroot -p
如果不是内部命令的话就需要去把mysql中bin目录的路径复制到计算机path路径中。
具体的操作的话,大家可以去PHP中文网或百度一下就知道如何做了。
2如果下载phpstudy则直接在MySQL工具中打开MySQL命令行即可
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 33
Server version: 5.5.53 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
虽然我们有的看不懂吧,但是嘞只要弹出这个就表示我们已经连接上了数据库。
cmd中操作数据库或表的常用命令
- <选择(使用)一个数据库>
use 数据库名称;
;一定不要忘记加上
mysql> use bss;//使用这个名为bss的数据库
Database changed
- <查数据库>
show databases ;(;是语句的结束符,一定要加上)
mysql> show databases;//这个语句可以查出所以你创建的数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| bss |
| myhtml |
| mysql |
| performance_schema |
| score |
| test |
+--------------------+
7 rows in set (0.00 sec)
- <查表>
show tables;(注意因为是查表所以一定要首先选择一个数据库才能查看)
mysql> show tables;//在这里我选择的数据库是bss
+---------------+
| Tables_in_bss |
+---------------+
| user |
| zzh |
+---------------+
2 rows in set (0.00 sec)
- <建立/删除数据库>
create database 数据库名称;建立数据库
drop database 数据库名称;删除数据库
mysql> create database xiao;
Query OK, 1 row affected (0.00 sec)//这样就新建一个数据库,我们也可以在查看一下。
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bss |
| myhtml |
| mysql |
| performance_schema |
| score |
| test |
| xiao |
+--------------------+
8 rows in set (0.00 sec)//这样数据库中便有了这个xiao数据库,接下来再删除它。
mysql> drop database xiao;
Query OK, 0 rows affected (1.85 sec)
//这样xiao数据库就被删除了。
- <创建/删除一个表>
create table 表名 ( id int ,name varchar(35),password varchar(40));
其中 id name password 是字段 ,后面的限制是类型,括号里的字段可以自己进行设置,只要格式对就可以。
drop table 表名;
注意在创建数据表时一定要先选择一个数据库。
mysql> create table hello(id int,you varchar(30),me varchar(30));
Query OK, 0 rows affected (1.78 sec)//接下来我们查看一下
mysql> show tables;
+---------------+
| Tables_in_bss |
+---------------+
| hello |
| user |
| zzh |
+---------------+
3 rows in set (0.00 sec)//这样bbs数据库中便有这个hello的数据表了
mysql> drop table hello;
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+---------------+
| Tables_in_bss |
+---------------+
| user |
| zzh |
+---------------+
2 rows in set (0.00 sec)
//这样就删除了刚才所创建的数据表
- <查看表结构>
desc 表名;
mysql> desc user;//查看表结构
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| pass | varchar(30) | YES | | NULL | |
| name | varchar(30)