MySQL基本命令行

登陆:mysql –h localhost –u 用户名 –p

mysql –u 用户名 –p   (默认连接localhost服务器)

服务器中可以有多个库,库中可以有多个表。数据库的名字无法修改

查看库:show databases;   (注意分号结束,查看当前服务器中有哪些数据库)

创建库:create database 名字;  (名字以test为例)

使用库(进入库):use test;  (进入了test库)

查看表:show tables;  (进入test库后,查看test库中有哪些表)

删除库:drop database test;

创建表:create table 名字;  (进入库之后,创建表,并指定表头)

例如,创建表class,每一列用逗号隔开(可以先在记事本中编辑,复制粘贴到cmd中)

create table class(   创建表:班级class

StudentID int,      学号,int型

Name varchar(20),   姓名,字符型,限定长度不超过20字符

Age int            年龄,int型

);

修改表名:rename table 旧名字 to 新名字;

查看表头:desc class;     (以class表为例,description缩写)

【Error 1064】说明输入语句错误,命令行见到分号才执行,c 退出此语句,重新输入即可。

原文地址:https://www.cnblogs.com/xixixing/p/9600067.html