1.连接数据库
1.新建用户
mysql -u用户名 -p密码
1.1 登录MYSQL:
2.显示所有数据库
@>mysql -u root -p
show databases;
@>密码
3.使用数据库
1.2 创建用户:
use 数据库名;
mysql> CREATE USER 'test'@'%' IDENTIFIED BY '1234';
4.显示某个数据库下的所有表
这样就创建了一个名为:test 密码为:1234 的用户。
show tables;
注意:此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录。也可以指定某台机器可以远程登录。
5.显示表结构
1.3 然后登录一下:
desc表明;
mysql>exit;
6.停止数据库服务
@>mysql -u test -p
net stop mysql;
@>输入密码
7.开启数据库服务
mysql>登录成功
net start mysql;
8.创建数据库
2.为用户授权
create database 数据库名;
授权格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码";
9.创建用户(注意:必须有创建用户权限的管理员)
2.1 登录MYSQL(有ROOT权限),这里以ROOT身份登录:
create user '用户名'@'IP地址' identified by '密码';
@>mysql -u root -p
eg:create user 'test'@'%' identified by 'test';
@>密码
10.授权
2.2 首先为用户创建一个数据库(testDB):
grant 操作 on 数据库.表名 to '用户名'@'IP地址';
mysql>create database testDB;
(注意:操作包括select,insert,update,delete,等,也可以使用all 关键字授权所有操作)
2.3 授权test用户拥有testDB数据库的所有权限(某个数据库的所有权限):
eg:grant all on mydb.* to 'test'@'%';
mysql>grant all privileges on testDB.* to test@localhost identified by '1234';
11.回收权限
mysql>flush privileges;//刷新系统权限表
revoke 操作 on 数据库.表名 from '用户名'@'IP地址';
格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码";
eg:revoke all on mydb.* from 'test'@'%';
2.4 如果想指定部分权限给一用户,可以这样来写:
12.删除用户
mysql>grant select,update on testDB.* to test@localhost identified by '1234';
drop user '用户名'@'IP地址'
mysql>flush privileges; //刷新系统权限表
(注意:删除用户前先回收用户权限)
2.5 授权test用户拥有所有数据库的某些权限:
eg:drop user 'test'@'%';
mysql>grant select,delete,update,create,drop,insert on *.* to test@"%" identified by "1234";
//test用户对所有数据库都有select,delete,update,create,drop 权限。
//@"%" 表示对所有非本地主机授权,不包括localhost。(localhost地址设为127.0.0.1,如果设为真实的本地地址,不知道是否可以,没有验证。)
//对localhost授权:加上一句grant all privileges on testDB.* to test@localhost identified by '1234';即可。
编辑:计算机数据 本文来源:mg娱乐电子游戏平台mySql常用命令
关键词: