mysql基础命令

mysql基础命令

 

 

安装与启动(rpm包) mysql(工具包)mysql-server(服务器包)

       数据库目录:/var/lib/mysql

       主配置文件:/etc/my.cnf

       端口号:3306

创建管理员用户密码:

mysqladmin –uroot password ‘123456’

 

mysql –uroot –p  -h localhost –s/var/lib/mysql/mysql.soc

-u 登入用户名

-h 什么方式登入

-s 套接字文件

 

修改当前登入密码:

       setpassword = password(“123”);

修改其他用户登入密码:

       setpassword for  ‘用户’@’地址’ = password(”123”)

      

管理员密码丢失忘记解决方法:

打开:vim/etc/my.cnf

在[mysqld]区域下面

加入skip-grant-tables

重启数据库

updata mysql.user set password=password(“789”)where user = ‘root’

(修改 mysql .user里的 密码 将账户root密码改为789)

 

创建用户:

       create user a1@’localhost’ identified by ‘123’;

       (创建 用户 luwei 只允许本地登入 用什么密码123)

       create  user a2@’%’ identified by ‘123’;

       (%表示允许用户任意远端地址登入)

grant all on nginx.* tonginx@'%' identified by '123456';完整

 

查询用户登入方式

select host,userfrom mysql.user;

 

权限:

grant all on (privilege可以不加)数据库名.*  to 用户名@’%’;

是数据库用户给予某个数据库最大权限,登入方式为任何

revoke createdeleteon 数据库名.*  from 用户名@%’;

删除数据库用户创建和删除权限

show grants  for 用户名@’%’;

数据库用户地址登入具备的权限列表

 

更改登入方式将本地改变只远程登入

首先设置

updateuser set host='%' where user='aa';

然后重置用户登入数据库权限密码

grant all onmysql.* to 'aa'@'%' identified by '123456';

 

sql语句使用

增加:

create database 名字;

       (创建数据库)

create  tables 名字;必须有框架

       (创建数据表)

create table 名字(id int,name char(30);(名字和字符类型不能有空格)

       (创建数据表名字(设置第一个字段id  int表示整数类型,name姓名char30)表示设置30个字符);

insert into 数据表名字idnamevalues 1luwei);)

插入数据到数据表名字,插入到那些字段idname插入什么样的数据1luwei

alter table 数据表名add  字符名这个随便写类型名(不能随便)(就是增加一个如age这个项)

在数据表中添加一个字符类型

alter table 数据表名add 字符名类型名aa first

表示添加字符类型到数据表中,并且是第一列

alter table 数据表名add 字符名bb 类型名 after aa

表示将创建的bb添加到aa的后一条

例:

create table a2

创建一个表叫a2

id int unsigned not null auto_increment

id 为整数字段unsigned正数(不允许为负数) not null 不允许为空 auto_increment 表示参数自增长

name char20not  null default ‘’,

name char20)名字字段最大为20个字符  not null 不允许为空default’如果不写默认为空格

age int not nulldefault 0’,

age int 正数字段not null 不允许为空 default如果是空默认为0

info char50null

info char50长度50个字节  null 可以为空

primary keyid));

主键为id字段

 

插入一条数据测试:

insert into a2(id,name,age,info) values (1,’luwei’,27,19191919);

 

插入多条数据测试:

insert into a2 namevalues (‘luwei2’),(‘luwei3’);

 

a2中的idname区域数据转移到a1

insert into a1(id,name)  select  id,name from a2;

 

删除:

drop database 名字

(删除数据库)

drop table 数据库名.数据表名;

(删除数据库下的数据表)

delete from 数据表名 where id=5

(删除数据表中的id5的行)

dalete from 数据表名where 字段类型名(age  between 20 and 25

删除数据表中的字段类型范围比如(age年龄2025的)

delete from 数据表名;

清空数据表内容

alter table 数据表名drop 字符名bb

删除字符名bb的行

改变:

update 数据表名set 字段类型名=‘要修改的名字’ where 字符类型名=6

修改数据表中匹配为6的的字段类型结果为要修改的名

update 数据表名set字段类型名=’要修改的名’ where  字段类型名between15 and 30

修改数据表中匹配为1530范围内的字段类型修改内容为要修改的名

alter table 原名 rename 修改后的名

(修改数据表名字)

alter table 数据表名 modify 字段类型名 char(100) NULL;

修改数据表中的字段类型属性 char 为(100);

alter table 数据表名 change 字段类型原名 information char(100) null

修改数据表字段类型名为information char100 null(这些为后面的原参数,不然会引起改动)

修改排序

select * from personorder by id asc; 升序排列

select * from personorder by id desc;降序排列

查询:

show database ;

(查看有那些数据库)

use mysql;

       进入mysql数据库里来(相当于use =cd

show tables

       查看有哪些数据表

select * from user;(user/G改变显示方式);

       表示把数据表里的数据全部加载出来

describe 名字

       表示显示数据表的框架

Field:  字段(默认分11个字符)

Type:  类型

Null:  是否可以为空

Key:  主键,定位快速查询

Deflule:  默认值

Extra:  额外参数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值