MySql常用简单命令

来源:互联网 发布:mac air windows 驱动 编辑:程序博客网 时间:2024/06/07 02:58

1、启动和停止MySql服务

net stop mysql

net start mysql

2、登录MySql

 mysql -u用户名 -p用户密码,例如mysql -uroot -p用root账号登录

3、添加用户及权限

grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码",例如grant select,insert,update,delete on *.* to user1@localhost Identified by "password1";

4、操作数据库

4.1、显示数据库列表。

show databases;

4.2、显示某一个数据库中的数据表

use 数据库名;

show tables;

4.3、显示数据表的结构:

describe 表名;

或desc 表名;

或show columns from 表名;

4.4、新建或删除数据库

create database 库名;

drop database 库名;

4.5、新建或删除数据表

create table 表名(字段列表);

drop table 表名;

例如;

create table MyClass(
 id int(4) not null primary key auto_increment,
name char(20) not null,
sex int(4) not null default '0',
degree double(16,2));

4.6、清空数据表

delete from 表名;

4.7、插入数据

insert into 表名 values(值1,值2,...);

或insert into 表名(列1,列2,...) values(值1,值2,...);

4.8、更新数据

update 表名 set 列名1=新值2,列名2=新值2,... where 条件;

4.9、查询数据

select 列名1,列名2 from 表名;

4.10、删除数据

delete from 表名 where 列名1=值1 and 列名2=值2;

5、退出

quit;

或exit;


0 0
原创粉丝点击