MySQL 常用命令总结
数据库管理
- 登录数据库:
mysql -u username -p
- 列出所有数据库:
show databases;
或者是show schemas;
- 使用指定数据库:
use database_name;
- 列出指定数据库的所有表:
show tables;
- 列出指定表的信息:
show columns from table_name;
- 列出指定表的索引信息:
show index from table_name;
- 创建一个新用户:
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;
其他
- 切换用户的认证方式:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Links: MySQL-常用命令总结