MySQL数据库常用命令行整理(表格)

MySQL常用命令行
1、登陆、退出MySQL
作用命令行
本地登陆数据库服务器。mysql -u<用户名> -p<你的密码>
如:mysql -uroot -p123456
远程登陆数据库服务器。mysql -h<主机地址> -u<用户名> -p<你的密码>
如:mysql -h127.00.000 -uroot -p123456
退出数据库服务器。exit;
2、密码操作
作用命令行
创建密码。mysqladmin -u<用户名> password <新密码>;
如:mysqladmin -uroot -password 123456;
修改密码(适用于MySQL8.0以上版本)。alter user'root'@'localhost' identified by '<新密码>';

alter user'root'@'localhost' identified with mysql_native_password by '<新密码>';
如: alter user'root'@'localhost' identified by '123456';

alter user'root'@'localhost' identified with mysql_native_password by '123456';
3、数据库相关操作
作用命令行
在数据库服务器中创建数据库。create database <数据库的名称>
如:create database test;
查询数据库服务器中的所有数据库。show databases;
删除数据库。drop database <数据库名称>
如:drop database test;
连接一个数据库进行操作。use <数据库名称>;
如:use test;
4、数据表相关操作
作用命令行
创建一个数据表(关系)。create table <表名>
 (<列名> <列数据类型>,
<列名> <列数据类型>,……);
如:create table Student
(name VARCHAR(16),
ID INT(4),
sex CHAR(1),
birth DATE);
删除一个数据表。drop table <表名>
如:drop table Student;
查看当前操作的数据库中的所有数据表。show tables;
查看数据表的标题(模式)。describe <表名>;
如:describe Student;
在数据表中增加列(字段/属性/数据项)。alter table <表名> add <列名> <类型> <其他>;
如:alter table Student add province VARCHAR(24);
删除列。alter table <表名> drop <列名>;
如:alter table Student drop province;
修改表名。rename table <原表名> to <新表名>;
如:rename table Student to AllStudent;
5、数据的增删查改
作用命令行
往数据表中添加行(元组/记录)。insert into <表名> values (<数据值>,<数据值>,……);
如:insert into  Student values ('John',2018123456,'m','2000-01-01');
注意:每个数据值类型要与数据表的对应列的标题相匹配。
删除行。delete from <表名> where <列名>=<数据值>;
如:delete from Student where ID=2018123456;
查看数据表中的所有行。select * from <表名>;
如:select * from Student;
精确查找数据表中的行。select <列名>,…,<列名> from <表名> where <定位数据所在行的列名>=<该列的数据值>;
如:select name,ID from Student where sex='m';
修改行。update <表名> set <要修改的数据所在列名>=<要修改为的数据值> where <定位数据所在行的列名>=<该列的数据值>
如:update Student set ID=2018654321 where name='John';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值