命令行操作mysql

本文介绍了通过命令行操作MySQL数据库的方法,包括连接数据库,需输入服务IP、用户名、端口和密码;还涉及显示数据库和表、查询表结构、执行增删改查操作以及用户授权等内容。

1、通过命令行连接mysql:
1、输入命令:mysql -h localhost(服务IP地址) -u root(用户名) -P 3306(服务端口)-p
2、输入密码

2、显示数据库、表:

show databases;    //显示存在的数据库
use test;                //test为相对应的数据库名称,表示使用某个数据库
show tables;        //显示此数据库的所有表

3、命令行查询表结构

1desc tabl_name;(查询表结构信息)
2select * from information_schema.columns where table_schema = 'db' #表所在数据库 and table_name = 'tablename' ; #你要查的表(查询表结构信息)
3select column_name, column_comment from information_schema.columns where table_schema ='db' and table_name = 'tablename' ;(只查询列名、注释信息)
4select table_name,table_comment from information_schema.tables where table_schema = 'db' and table_name ='tablename'(查看表的注释)

4、执行增删改查:

create database test;    //建数据库。名字为test
create table user(id int(4) not null primary key auto_increment,username char(20)not null,password char(20) not null);

//创建数据库,名为user

insert into user (1,'duoduo','921012');        //插入一条数据

select * from user;        //查询所有的信息

5、用户授权:

grant select on *.* to 'reader'@'%' identified by '123456' WITH GRANT OPTION
flush privileges
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值