Mysql学习---基础操做学习

1.1. 基本操做

数据库引擎html

Inodb:支持事务[原子性操做,完成一些列操做后才算完成操做,不然rollback] mysql

MyISAM: 支持全文索引,强调了快速读取操做,主要用于高负载的selectsql

建立数据库,表:数据库

show databases;  # 查看当前Mysql都有那些数据,根目录都有那些文件夹
create datab  ase 数据库名;  # 建立文件夹
use 数据库名;  # 使用选中数据库,进入目录
show tables;  # 查看当前数据库下都有那些表
create table 表名(nid int, name varchar(20), pwd varchar(64));  # 建立数据库表
select * from 表名;  # 查看表中的全部数据
insert into 表名(nid, name, pwd) values(1, 'alex', '123');  # 插入数据
select * from 表名 where id = 1;

用户管理特殊命令:框架

建立用户
create user '用户名'@'IP地址' identified by '密码';
create user 'hhh'@'192.168.25.%' identified by '777';  # 远程链接 %表示通配符
删除用户
drop user '用户名'@'IP地址'; 
修改用户
rename user'用户名'@'IP地址' to '新用户名'@'IP地址';
修改密码
set password for '用户名' @ 'IP地址' = Password('新密码')
flush privileges;  # 命令即时生效

权限管理:默认无ide

show grants for sh0731@localhost; # 查看权限
grant all privileges on mysql.test to ftl@localhost; # 受权
grant all privileges on mysql.user  to hhh@'192.168.25.%';# 远程受权
revoke all privileges on mysql.test from ftl@localhost; # 收权
flush privileges;  # 命令即时生效

远程链接:spa

mysql -u root -h 192.168.25.100 -P 3306 –p

数据库级别操做:code

SHOW DATABASES;
CREATE DATABASE 数据库名称;
CREATE DATABASE 数据库名称 DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
USE 数据库名称;
drop database 数据库名称;

表级别操做:htm

show tables; 
desc tb1;
drop table hhh;  # 删除表
delete from hhh where id = 1; # 清空表内容
truncate table hhh; # 清空表,可是保留表的框架
select * from hhh;
update hhh set sex = 'm' where id = 1;
create table hhh (
    id  int, 
   name varchar(12),
   sex  varchar(2)
)

忘记密码:索引

# 启动免受权服务端
mysqld --skip-grant-tables
# 客户端
mysql -u root -p
# 修改用户名密码
update mysql.user set authentication_string=password('666') where user='root';
flush privileges;
相关文章
相关标签/搜索