Mysql基础

Mysql数据类型

字符类型

字符串类型指CHAR、VARCHAR、BINARY、VARBINARY、BLOB、TEXT、ENUM和SET

类型 大小 用途
CHAR 0-255字节 定长字符串
类型 大小 用途
类型 大小 用途
类型 大小 用途
类型 大小 用途
类型 大小 用途
类型 大小 用途
类型 大小 用途
类型 大小 用途
类型 大小 用途
类型 大小 用途
类型 大小 用途

Mysql创建用户与授权

  1. 创建用户
mysql> CREATE USER 'mike'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
  1. 授权
    命令:GRANT privileges ON databasename.tablename TO 'username'@'host'
grant all PRIVILEGES on *.* to root@'%' identified by '123456'; 
权限名称 说明
ALTER Allows use of ALTER TABLE
ALTER ROUTINE Alters or drops stored routines
CREATE Allows use of CREATE TABLE
CREATE ROUTINE Creates stored routines
CREATE TEMPORARY TABLE Allows use of CREATE TEMPORARY TABLE
CREATE USER Allows use of CREATE USER DROP USER RENAME USER and REVOKE ALL PRIVILEGES
CREATE VIEW Allows use of CREATE VIEW
DELETE Allows use of DELETE
DROP Allows use of DROP TABLE
EXECUTE Allows the user to run stored routines.
FILE Allows use of SELECT ... INTO OUTFILE and LOAD DATA INFILE >.
INDEX Allows use of CREATE INDEX and DROP INDEX
INSERT Allows use of INSERT
LOCK TABLES Allows use of LOCK TABLES on tables for which the user also has SELECT privileges
PROCESS Allows use of SHOW FULL PROCESSLIST
RELOAD Allows use of FLUSH
REPLICATION Allows the user to ask where slave or master
CLIENT servers are
REPLICATION SLAVE Needed for replication slaves
SELECT Allows use of SELECT
SHOW DATABASES Allows use of SHOW DATABASES
SHOW VIEW Allows use of SHOW CREATE VIEW
SHUTDOWN Allows use of mysqladmin shutdown
SUPER Allows use of CHANGE MASTER , KILL , PURGE MASTER LOGS , and SET GLOBAL SQL statements. Allows mysqladmin debug command. Allows one extra connection to be made if maximum connections are reached.
UPDATE Allows use of UPDATE
USAGE Allows connection without any specific privileges.
  1. 设置与更改用户密码
    命令:SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');如果是当前登陆用户用SET PASSWORD = PASSWORD("newpassword");
    修改当前登录用户的密码
SET PASSWORD = PASSWORD("newpassword"); 

root用户修改其他用户密码 貌似这种方式会报一个警告

mysql> update mysql.user set authentication_string=password("222222") where User="mike" and Host="localhost";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1
  1. 删除用户与权限
drop user 用户名@’%’; 
drop user 用户名@ localhost;
  1. mysql 查看状态 开启 关闭

查看是否已开启

ubuntu@VM-0-10-ubuntu:~$ ps -ef|grep mysqld
mysql    25240     1  0 14:21 ?        00:00:02 /usr/sbin/mysqld
ubuntu   30182 28796  0 16:07 pts/0    00:00:00 grep --color=auto mysqld

开启

ubuntu@VM-0-10-ubuntu:~$ service mysql start

关闭

ubuntu@VM-0-10-ubuntu:~$ service mysql stop
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 数据库简介关系型数据库MySQL安装和使用SQL语言 一、数据库简介 (一)数据库的发展 文件系统:磁盘文件存储数...
    哈喽别样阅读 451评论 0 1
  • 一、MySQL For Windows安装: 1. 下载: 上官网下载即可: http://www.mysql.c...
    夕望有你阅读 1,994评论 0 14
  • MySQL 数据库常用命令 1、MySQL常用命令 create database name; 创建数据库 use...
    55lover阅读 4,872评论 1 57
  • 什么是数据库? 数据库是存储数据的集合的单独的应用程序。每个数据库具有一个或多个不同的API,用于创建,访问,管理...
    chen_000阅读 4,076评论 0 19
  • 启动 mysql$ mysql -uroot -p -P3306 -h127.0.0.1-u ,--user=na...
    假装正在输入阅读 721评论 0 6