Linux下mysql数据库基本操作

1.改密码5.7后操作

1.1 alter改密码

mysql> alter user root@localhost identified by '1';
Query OK, 0 rows affected (0.00 sec)

1.2 update改密码

mysql5.7后user表下的password字段改为了authentication_string

mysql> update mysql.user set authentication_string=password('1') where user='root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

在这里插入图片描述

1.3 set修改密码

mysql> set password for root@localhost=password('1');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

1.4 mysqladmin修改密码

1.4.1 root没有密码

假如你的root没有密码,你希望将密码改成123456,执行

mysqladmin -u root password 

在这里插入图片描述

1.4.2 root有密码

假如你的root有密码,你希望将密码改成123456,执行:

mysqladmin -u root -p password

在这里插入图片描述

2.库管理命令

  • show databases;
  • use 库名;
  • select database();
  • create database 库名;
  • show tables;
  • drop database 库名;

3.表管理命令

  • 新建表

    create table 库名.表名(
    字段名1 字段类型(宽度) 约束条件,
    字段名2 字段类型(宽度) 约束条件,
    字段名N 字段类型(宽度) 约束条件
    )
    
    mysql> create table test.study1(
        -> name char(20),
        -> age int);
    
    • desc 表名;
    • select * from 表名;
    • drop table 表名;
  • 记录管理命令

    • select * from 表名;

    • insert into 表名 values(值列表);

      mysql> insert into study1 values('liuneng',21),('zhaosi',22);
      
    • update 表名 set 字段=值;

      mysql> update study1 set age=30; #所有人的age都改为30
      mysql> update study1 set age=25 where name='huanhuan'; #将huanhuan的age改为25
      
    • delete from 表名;

      mysql> delete from study1 where name='zhaosi'; #删除zhaosi的记录
      mysql> delete from study1; #删除表中所有的记录
      
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

河 静

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值