文章引用地址:https://www.cnblogs.com/Glory-D/p/7518541.html、https://www.cnblogs.com/zhchoutai/p/6929103.html
mysql -u root -p + 回车 -u后跟用户名,-p表示需要密码登录,首次进入mysql用root用户
如:
MariaDB>>status; —列出当前mysql的相关状态信息,注意要加分号‘;‘
MariaDB>>show databases; —显示数据库列表
MariaDB>>use LXF; —选中数据库LXF
MariaDB>>show tables; —显示LXF数据库下的tables列表
MariaDB>>create database lxf; —创建数据库lxf,需要使用root用户登录,普通用户没有创建数据库的权利
MariaDB>>drop table 数据表名; —删除表
MariaDB>>drop database 数据库名; —删除数据库
MariaDB>>quit; —退出
MariaDB>>
MariaDB>>
MariaDB>>
MariaDB>>
MariaDB>>
用户相关:
1、查看全部的用户:
SELECT DISTINCT CONCAT(‘User: ‘‘‘,user,‘‘‘@‘‘‘,host,‘‘‘;‘) AS query FROM mysql.user;
2、新建用户:
CREATE USER
‘abc‘
@
‘localhost‘
IDENTIFIED BY
‘XXXXXX‘
; —会发现用户abc以及被添加成功
3、为用户授权
grant 权限 on 数据库.* to [email protected]登录主机 identified by ‘password‘;
3.1 为用户授予部分权限:grant select,insert,delete,update on lxf.* to abc identified by ‘123456‘;
演示样例:
3.2 加全部权限到testDB数据库中
grant all privileges on testDB.* to [email protected] identified by ‘1234‘;
3.3 授予一个用户全部数据库的某些权限:
grant select,delete,update,create,drop on *.* to [email protected]"%" identified by "1234";
3.4 然后须要运行刷新权限的命令:
flush privileges;
4、删除用户:
Delete FROM user Where User=‘test‘ and Host=‘localhost‘;
然后刷新权限;
删除账户及权限:>drop user [email protected]‘%‘;
>drop user [email protected] localhost;
5、改动指定用户password
使用root登录:
mysql -u root -p
运行命令:
update mysql.user set password=password(‘新密码‘) where User="test" and Host="localhost";
刷新权限:
flush privileges;
原文地址:https://www.cnblogs.com/qianxingzhe/p/9280740.html