首页 > 技术文章 > MySQL基本操作命令

caoyusang 2021-01-15 16:42 原文

连接MySQL

mysql -u用户名 -p密码

退出连接

exit;

更改用户密码

update mysql.user set authentication_string=password('新密码') where user='用户名' and Host = 'localhost';

刷新权限

flush privileges;

展示所有数据库

show databases;

切换数据库

use 数据库名

查看数据库中所有表的信息

describe 表名

创建数据库

create database `数据库名`	--(加`声明为字符串,防止数据库名与关键字重名出错的问题);

删除数据库

drop database if exists `数据库名`

建表实例

create table if not exists `teacher` (
    `stuffID` int(3) not null auto_increment comment '职工号',
    `name` varchar(10) not null comment '姓名',
    `gender` varchar(1) not null comment '性别',
    `birthday` datetime default null comment '出生日期',
    `tel` varchar(11) not null comment '电话号码',
    `email` varchar(30) not null comment '电子邮箱',
    primary key (`stuffID`)
)engine=innodb default charset =utf8

展示创建数据库/表的语句

show create database 数据库名
show create table 表名
desc 表名 	--显示表的结构

SQL的注释

  • 单行注释 —— --
  • 多行注释 —— /* ... */

推荐阅读