数据查询语言DQL
数据操作语言DML select insert update delete ←运维
事务处理语言TPL
数据控制语言DCL grant revoke commit rollback ←运维
数据定义语言DDL create drop alter
指针控制语言CCL
mysql> create database hequan;
mysql> show create database hequan\G;
Database: hequan
Create Database: CREATE DATABASE `hequan` /*!40100 DEFAULT CHARACTER SET latin1 */ //默认字符集拉丁
1 row in set (0.00 sec)
mysql> create database hequan_gbk default character set gbk collate gbk_chinese_ci;
mysql> create database hequan_utf8 default character set utf8 collate utf8_general_ci;
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
//如果编译时 指定特定的字符集 则以后创建数据库就不需要指定了。
//企业:根据开发的程序确定字符集(UTF8) 编译时指定 字符集,建库时默认创建即可。
如果不同字符集,指定字符集创建数据库。
基本用法
mysql> show databases;
mysql> use hequan; mysql> select database(); //查看当前连接的数据库
mysql> drop database hequan_gbk;
mysql> help drop database;
mysql> select version();
mysql> select user();
mysql> select now();
mysql> show tables;
mysql> show tables from mysql;
mysql> select user,host from mysql.user;
mysql> drop user ‘‘@‘hequan2.com‘; //删除多余账号
mysql> flush privileges;
授权
mysql> grant all on db1.* to ‘hequan‘@‘localhost‘ identified by ‘123123‘;
库.表 用户名 客户端主机 密码
mysql> show grants for [email protected]‘localhost‘; //查看用户权限
mysql> create user [email protected] identified by ‘123123‘;
mysql> grant all on test.* to [email protected]‘localhost‘;
mysql> grant all on test.* to [email protected]‘192.168.10.%‘;
mysql> grant all on test.* to [email protected]‘192.168.10.0/255.255.255.0‘;
mysql> create user [email protected]‘192.168.10.%‘ identified by ‘123456‘; //创建远程登陆用户
mysql -uquan -p123456 -h192.168.10.11 //登陆时 -h
mysql> revoke insert on *.* from ‘quan‘@‘192.168.10.%‘; // 收回插入权限
mysql> desc user; // 查看表
mysql> select * from mysql.user\G; //授权就是把N换成Y
Host: localhost
User: root
Password: *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
最小权限 select insert update delete create drop 安装完成后收回
mysql> create database oldboy;
create tables <表名>( <字段名1><类型1>,...<字段名n><类型n>);
create table student(
id int(4) not null,
name char(20) not null,
age tinyint(2) NOT NULL default ‘0‘ ,
dept varchar(16) default NULL
);
mysql> desc student; //查看 mysql> show create table student;
---------------+
| student | CREATE TABLE `student` (
`id` int(4) NOT NULL,
`name` char(20) NOT NULL,
`age` tinyint(2) NOT NULL DEFAULT ‘0‘,
`dept` varchar(16) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 | 引擎 及 默认字符集
mysql> show tables from oldboy;
本文出自 “何全” 博客,请务必保留此出处http://hequan.blog.51cto.com/5701886/1773728