MySQL 常用命令总结

Tag: SQL Posted on 2020-04-18 09:43:30 Edited on 2020-04-18 10:02:40 Views: 16

数据库管理

  1. 登录数据库:mysql -u username -p
  2. 列出所有数据库:show databases;或者是show schemas;
  3. 使用指定数据库:use database_name;
  4. 列出指定数据库的所有表:show tables;
  5. 列出指定表的信息:show columns from table_name;
  6. 列出指定表的索引信息:show index from table_name;
  7. 创建一个新用户:
    create user 'username'@'%' indentified by 'password';
    grant all privileges on *.* to 'username'@'%';
    flush privileges;

CRUD

插入

insert into table_name (column1, column2) (value1, value2);

查询

select * from table_name where column1=value1;

修改

update table_name set column1=value1, column2=value2 where column3=value3;

删除

delete from table_name where column1=value1;

其他

  1. 切换用户的认证方式:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

未经允许,禁止转载,本文源站链接:https://iamazing.cn/