MySQL常用命令

1.MySQL常用命令:

create database name;  创建数据库

use databasename;     选择数据库

drop database name;     直接删除数据库,不提醒

drop table tablename    删除数据表      

show databases;         显示数据库

show tables;            显示表

show engines;     查看数据库支持的引擎

desc  tablename;        表的详细描述

mysqladmin drop database name; 删除数据库,有提示。

显示当前mysql版本和当前日期

select version(),current_date;

2.修改mysql中的root密码;

mysql>update user set password=password("wwy123456") where user='root';

mysql>flush privileges   //刷新数据库

mysql>use dbname;        //打开数据库

mysql>show databases;    //显示所有数据库

mysql>show tables;        //显示数据库中的所有表,要先use你的数据库

mysql>desc user;          //显示数据库中user表的列信息

3.创建数据表student

mysql>create table student(

mysql>id varchar(50) primary key,

mysql>username varchar(50),

mysql>password varchar(50)

mysql>);

4.修改数据表结构

mysql>下执行

#在表student中增加列test

alter table student add(test carchar(50));

#在表student中修改列test

alter table student modify test varchar(10) not null;

#在表student中修改列test的默认值

alter table student alter test set default 'system';

#在表student中去掉列test的默认值

alter table student alter test drop default;

#在表student中去掉列test

alter table student drop column test;

#表student中删除主键

alter table student drop primary key;

#表student中增加主键

alter table student add primary key (id);

5.在表student中插入数据

insert into student (id,username,opassword) values('123','wwy','456'); insert into student (id,username,opassword) values('124','wwy','456');

6.查询、删除及更新操作

#显示student中的人员的名字

select username from student;

#显示收student中的人数

select count(*) from student;

#删除124

delete from student where id='124';

#将wwy改为zyj

updata student set username='zyj' where username='wwy';

7.对表重新命名

alter table table1 rename as table2;

8.导入.sql文件命令(例如D:\user.sql)

mysql>use database;

mysql>source d:/user.sql;

9.txt文件导入MySQL数据库

load data local infile "D:/student.txt" into table student fields terminated by ',' lines terminated by '\r\n'; 其中‘,’为分隔符

原文地址:https://www.cnblogs.com/wwy209/p/2617935.html