本文共 1710 字,大约阅读时间需要 5 分钟。
在命令行或终端中,使用以下命令连接 MySQL 数据库:
mysql -u 用户名 -p
本机连接:
mysql -u root -p
远程连接:
mysql -h 主机地址 -u 用户名 -p 密码
主机地址 和 密码 为实际值。退出 MySQL:
输入exit 或按下回车键。grant select, insert, update, delete on *.* to 用户名@登录主机 identified by "密码";flush privileges;
mysql -u root -pupdate user set password="新密码" where user='旧用户名';flush privileges;
delete from user where user='用户名' and host='主机名';flush privileges;
create database if not exists 数据库名;
use 数据库名;
drop database if exists 数据库名;
create table 表名 ( id int auto_increment primary key, name char(20) not null, department_id int, position_id int, unique (department_id, position_id));
insert into 表名 (字段1, 字段2, ...) values('值1', '值2', ...); select * from 表名;
update 表名 set 字段1='新值' where 条件;
delete from 表名 where 条件;
grant select, insert, update, delete on 数据库名.表名 to 用户名@登录主机 identified by "密码";
revoke select, insert, update, delete on 数据库名.表名 from 用户名@登录主机;
show grants for 用户名@登录主机;
mysqldump -u 用户名 -p 数据库名 > 数据库名.sql
mysql -u 用户名 -p 数据库名 < 数据库名.sql
select current_date();
select version();
select user();
| 命令 | 描述 |
|---|---|
create database 数据库名; | 创建新数据库 |
use 数据库名; | 切换当前数据库 |
drop database 数据库名; | 删除指定数据库 |
create table 表名 (...); | 创建新表 |
insert into 表名 values(...); | 插入数据 |
update 表名 set 字段=值; | 更新数据 |
delete from 表名 where 条件; | 删除数据 |
grant 权限 on *.* to 用户名@主机; | 授权用户权限 |
revoke 权限 on *.* from 用户名@主机; | 撤销用户权限 |
通过以上命令,您可以在 MySQL 中完成基本的数据库管理操作。
转载地址:http://fvavz.baihongyu.com/