-
登录MySQL:mysql -u username -p
-
显示所有数据库:show databases;
-
创建数据库:create database dbname;
-
进入数据库:use dbname;
-
显示数据库中所有表:show tables;
-
创建表:create table tablename(col1 datatype1, col2 datatype2, ...);
-
插入数据:insert into tablename(col1, col2, ...) values(val1, val2, ...);
-
查找数据:select * from tablename where condition;
-
更新数据:update tablename set col = val where condition;
-
删除数据:delete from tablename where condition;
-
删除表:drop table tablename;
-
删除数据库:drop database dbname;
-
修改表名:rename table oldname to newname;
-
查看表结构:desc tablename;
-
查看服务器版本:select version();
-
查看当前时间:select now();
-
查看当前用户:select user();
-
查看当前用户权限:show grants;
-
创建用户:create user username identified by 'password';
-
授权用户权限:grant privileges on dbname.tablename to username;
-
撤销用户权限:revoke privileges on dbname.tablename from username;
-
列出所有用户:select user from mysql.user;
-
列出所有权限:show grants for username;
-
退出MySQL:exit;
MySQL 常用命令整理
7 min read