zoukankan      html  css  js  c++  java
  • 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;
    修改密码。 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';
  • 相关阅读:
    Python 字符串格式化
    centos 7 & 6 优化脚本
    centos7.X 系统初始化>>优化
    重新嫁接rm命令
    ArcGIS Engine 10 开发常见问题的解决方法
    数据提交成功后如何避免alert被window.location.reload()影响
    服务器端IIS中部署带Office组件程序
    常用正则表达式
    C#解析XML
    使用Spire.Doc组件利用模板导出Word文档
  • 原文地址:https://www.cnblogs.com/LaplaceKang/p/12484383.html
Copyright © 2011-2022 走看看