mysql 设置主键命令_MySQL常用命令

mysql 设置主键命令_MySQL常用命令1、修改MySQL密码方法一:usemysql;updateusersetpassword=PASSWORD(“123456”)whereuser=‘root’;flushprivileges;忘记密码:sed-ri’3dskip-grant-tables’/etc/my.cnfsystemctlrestartmariadbusemysql;updateuse…

大家好,又见面了,我是你们的朋友全栈君。

1、修改MySQL密码

方法一:

use mysql;

update user set password=PASSWORD(“123456”) where user=‘root’;

flush privileges;

忘记密码:

sed -ri ‘3d skip-grant-tables’ /etc/my.cnf

systemctl restart mariadb

use mysql;

update user set password=PASSWORD(“123456”) where user=‘root’;

flush privileges;

sed -i ‘4d’ /etc/my.cnf

systemctl restart mariadb

注意一点:

如果你是源码安装MySQL5.7以上的版本,并且不是安装的Mariadb,那么password字段要改成authentication_string

创建数据库用户:

单纯的创建:create user ‘name’@‘host’ identified by ‘密码’

创建时设置用户权限:grant 权限 on 操作的表 to ‘name’@‘host’ identified by ‘密码’

all:表示所有权限

select:查询权限

delete:删除权限

update:更新权限

.:可以代表所有的表

回收用户权限:revoke 权限 on 操作的表 from ‘name’@‘host’

删除用户:drop user ‘name’@‘host’;

2、创建数据库以及删除数据库

创建:create database 数据库名称;

删除:drop database 数据库名称;

3、创建表以及删除表

create table 表名称(表中字段名称 类型);

创建:create table test(id int(10) not null) #int表示id字段为值为整型,且长度为10,不允许该字段为空

删除:drop table 表名称

drop table test

4、表中插入数据

insert into test(id) values(1002); #此处注意如果字段值设置为char字符型的,需要将values值加双引号

批量插入数据:insert into test values(1002),(1003),(1004);

5、表中更新修改数据

update test set id=’1005′ where id=1002;

6、表中字段的删除和增加

增加:alter table test add name char(12) after id; #alter 表示在什么字段之后

删除:alter table test drop name;

7、表名称修改

rename table test to nameinfo;

8、表中主键创建

方式一:

创建表时创建主键:create table test(id int(10),name char(20),primary key id);

方式二:

创建完表之后添加主键:alter table userinfo add primary key (id);

删除主键:alter table userinfo drop primary key;

9、创建索引

方式一:

创建表时创建索引:create table test(id int(10),name char(20),primary key id,key ‘index_name’ (‘name’));

方式二:

创建完表后添加索引:alter table userinfo add index user(name); #user表示索引名称,自定义

删除索引:alter table userinfo drop index user;

10、常用查询命令

查询所有数据库名称:

show databases;

查询数据库默认字符集:

show variables like ‘character%’;

查询指定数据库默认字符集

show create database userinfo;

模糊查询数据库

show databases like ‘user%’;

查询mysql有哪些用户

select user from mysql.user\G

查询指定字段信息

select user,host,password from mysql.user;

查询指定用户权限信息

show grants for root@host;

查询表创建过程

show create table userinfo;

查询表内所有字段信息

select * from userinfo;

带条件的查询指定字段信息

select user from user where id=’1002′

查询表内有哪些字段信息

desc userinfo;

查询数据库有哪些表

show tables;

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/151267.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • linux top cpu核数查看,Linux怎么查看CPU核数?

    linux top cpu核数查看,Linux怎么查看CPU核数?在Linux中,可以使用“cat/proc/cpuinfo|grep”cpucores”|uniq”来查看CPU核数,即每个物理CPU中core的个数。课程推荐:《linux课程》一、知识点介绍1、cpu信息记录在/proc/cpuinfo中。2、Linux中的Top相当于win系统下的任务管理器,也可以用来查询3、CPU总核数=物理CPU个数*每颗物理CPU的核数4、总逻辑CP…

    2025年6月26日
    2
  • Android 编译_android线程

    Android 编译_android线程之前本地环境编译一直是正常的,后来更新代码后,出现编译不过。提示outofmemory,但是查看swap和内存都还是够的。里面有个提示,tryincreasingheapsizewithjavaoption’-Xmx’,就按照这个来改。失败截图:解决方案:exportJACK_SERVER_VM_ARGUMENTS=”-Dfile.e

    2025年9月18日
    4
  • a*算法最短路径_最长路径算法

    a*算法最短路径_最长路径算法#include#include#include#include#include#defineN1000#defineinf1<<30;usingnamespacestd;/* a星算法,找寻最短路径 算法核心:有两个表open表和close表 将方块添加到open列表中,该列表有最小的和值。且将这个方块称为S吧。 将S从open列表移除,然后添加

    2022年10月6日
    3
  • 批处理远程执行bat_bat循环执行命令

    批处理远程执行bat_bat循环执行命令privatestaticfinalintTIME_OUT=2000;privatefinalstaticStringip=”192.168.70.147″;privatefinalstaticStringusername=”Administrator”;privatefinalstaticStringpasswd=”Yanfa_1304″;/***执行远程电脑下的脚本*/privat

    2022年9月23日
    5
  • 带通滤波器设计要注意采样率

    带通滤波器设计要注意采样率设计为采样频率600M,中心频率140M,带宽2M,Fs_org=140e6;Fs=Fs_org;T=1/Fs;%600/140=4.28,约600M采样率,t1=[0:T/4.28:1000*T];%原先错误代码,几乎就没有滤波%t1=[0:T/200:1000*T];%错误在于采样率远远大于600Mp=3*sin

    2022年5月27日
    29
  • 基于RDP开源许可rdesktop基本介绍

    基于RDP开源许可rdesktop基本介绍

    2022年1月4日
    61

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号