查看当前用户信息

MariaDB [aa]> select user();

查看所有存储用户信息

MariaDB [aa]> desc mysql.user;

MariaDB [aa]> select user,host,password from mysql.user;

user@host 才是完整的用户名

%指的是在任意地点登录

在另一个服务器上登录MySQL(IP=192.168.100.4)

首先安装client端

# yum install mariadb -y

# mysql -uroot -p redhat -h 192.168.100.3

设置密码

第一种方法:

直接回车,密码为空

注意:-p可以不写,因为是第一次设置密码

# mysqladmin -uroot -p password 'redhat'

再次登录等不上去了

# mysql

输入密码登录

# mysql -uroot -predhat

第二种方法:

为当前用户设置密码

调用password()函数

MariaDB [(none)]> set password=password('redhat123');

指明具体用户设置密码

MariaDB [(none)]> set password for root@'localhost' =password('redhat');

第三种方法:

直接更改mysql.user表中数据

注意:此方法不能临时生效,得刷新内存

MariaDB [(none)]> update mysql.user set password=password('redhat') where user='root' and host='localhost';

刷新内存生效

MariaDB [(none)]> flush privileges;

重置MySQL密码

方法一:

往配置文件中添加内容

#vi /etc/my.cnf

skip-grant-tables

重启服务

# systemctl restart mariadb

进入安全模式

# mysql

这种方法不能修改密码

MariaDB [(none)]> set password=password('redhat');

只能使用update

MariaDB [(none)]> update mysql.user set password=password('redhat') where user='root' and host='localhost';

MariaDB [(none)]> flush privileges;

注释或删除配置文件里面的内容

# vi /etc/my.cnf

# systemctl restart mariadb

方法二:

# systemctl stop mariadb

# mysqld_safe --skip-grant-tables

然后在另一个终端进入MySQL安全模式

# mysql

MariaDB [(none)]> update mysql.user set password=password('redhat123') where user='root' and host='localhost';

MariaDB [(none)]> flush privileges;

MariaDB [(none)]> quit

[root@localhost ~]# killall -9 mysqld_safe

# systemctl start mariadb


管理普通用户

 create user '用户名';

注意:这样添加的用户,权限是非常少的,得赋权限。(不建议使用)

创建一个普通用户

MariaDB [(none)]> create user 'tom';

MariaDB [(none)]> create user bob;

给普通用户设置密码

MariaDB [(none)]> set password for tom =password('redhat');


客户端连接

[root@localhost ~]# mysql -utom -predhat -h192.168.100.3

查看普通用户的权限

MariaDB [(none)]> show grants for tom\G

权限非常少,不提倡用create user创建用户


删除普通用户

MariaDB [(none)]> drop user bob;

给普通用户授权

列出所有权限

MariaDB [(none)]> show privileges;

创建一个bob用户并设置密码

MariaDB [(none)]> grant select on aa.* to bob@'%' identified by 'redhat';

给bob用户在aa库中添加insert权限

MariaDB [(none)]> grant insert on aa.* to bob@'%';


客户端使用root登录

[root@localhost ~]# mysql -uroot -predhat -h192.168.100.3

对其他用户授权,被拒绝

MariaDB [(none)]> grant create on aa.* to tom@'%';

原因:root@%也是我们创建的,创建的时候,权限是不能进行传递的

设置进行权限的传递,只需要加with grant option

MariaDB [(none)]> grant all on *.* to root@'%' identified by 'redhat' with grant option;

客户端连接,并验证


收回权限

revoke 权限1,权限2,…… on 库,表 from 用户;

MariaDB [(none)]> revoke create on aa.* from tom@'%';

在命令行里面使用sql语句

一般用作写shell脚本

[root@localhost ~]# mysql -uroot -predhat123 -e 'show databases'

[root@localhost ~]# mysql -uroot -predhat123 -e 'show databases;use aa;show tables'

数据库的备份

备份某库中的某张表

mysqldump -uroot -predhat 库 表

同时备份某个库中的多张表

mysqldump -uroot -predhat 库 表1 表2 表3……

备份某个库中所有的表

mysqldump -uroot -predhat 库 

# mysqldump -uroot -predhat123 aa aa > /backup/aa.sql

mysqldump备份的原理是:备份使用过的命令,而不是复制

# vi /backup/aa.sql

\c作用是不执行输入的命令

MariaDB [aa]> show tables \c

数据库的还原

MariaDB [aa]> drop table aa;

MariaDB [aa]> source /backup/aa.sql

管理MariaDB的更多相关文章

  1. 管理 MariaDB 用户账户

    哪些用户可以连接到MariaDB 服务器,他们都可以从哪些地方连接,连接到服务器后又能够做什么等,都是本文将涉及到的内容. 用户的权限信息都保存在 mysql 库中的几个权限表中.对 MariaDB ...

  2. MariaDB 备份与日志管理(13)

    MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...

  3. MariaDB 用户与权限管理(12)

    MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...

  4. Mastering MariaDB 神秘的MariaDB 中文翻译版

    是某群的哥们义务翻译的,宣传一下,还没时间时间读,粗滤看了全部翻译完了300多页佩服 https://github.com/CMant/Mastering-MariaDB- 原地址:如果你需要读,请s ...

  5. fedora安装了phpmyadmin后, mariadb无法启动?

    参考:http://www.linuxidc.com/Linux/2015-10/123945.htm where, which, when,等不但可以用在从句中, 而且可以用在 动词不定式中, 如: ...

  6. 数据库对比:选择MariaDB还是MySQL?

    作者 | EverSQL 译者 | 无明 这篇文章的目的主要是比较 MySQL 和 MariaDB 之间的主要相似点和不同点.我们将从性能.安全性和主要功能方面对这两个数据库展开对比,并列出在选择数据 ...

  7. MariaDB的备份与主从、高可用实践

    1.编写脚本,支持让用户自主选择,使用mysqldump还是xtraback全量备份. [root@test-centos7-node1 scripts]# cat chose_backup_mysq ...

  8. [数据库] MariaDB安装及使用

    一.安装MariaDB 1.使用官方源安装marisdb 如果使用阿里云的源,目前的版本号为5.5.64.如果想安装最新的10.x版本,则需要使用MariaDB的官方源. 1)配置官方源: 在/etc ...

  9. 基于centos的lnmp搭建

    部署lnmp环境 安装配置mariadb配置php配置phpmyadmin配置php-fpm配置nginx配置测试 LNMP(linux,nginx,mariadb,php)部署,以下默认在root权 ...

随机推荐

  1. hdu4998 Rotate 计算几何

    Noting is more interesting than rotation! Your little sister likes to rotate things. To put it easie ...

  2. hdu3294 Girls' research manacher

    One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...

  3. Java线程池 详解(图解)

    来源:www.jianshu.com/p/098819be088c 拓展: 手动创建 new ThreadPoolExecutor 的使用: https://segmentfault.com/a/11 ...

  4. 10 BPMN PDF books, articles and brochures

    转自:https://www.heflo.com/blog/bpm/bpmn-pdf/ If you are looking for more information about BPMN (Busi ...

  5. uname command

    The command uname helps us in development special in scripts, see help of the uname uname --help Usa ...

  6. mysql为int类型的字段php取出来之后为何变为string类型?

    https://segmentfault.com/q/1010000002957162 php从mysql取出int数据,变成了string https://blog.csdn.net/as17501 ...

  7. js技巧专题篇: 页面跳转

    本篇主要介绍网页上常见的页面跳转技术.页面跳转有几种方式,比较常用的是window.location.href,window.location.replace,window.open,当然还有目前比较 ...

  8. Delphi Json之树遍历

    procedure TForm1.VisitDirJsonTree(const AJsonObj: ISuperObject); var i: Integer; oItem: TSuperAvlEnt ...

  9. pdf.js 的使用

    现在的浏览器基本都支持直接把 pdf 文件拖到浏览器就可以打开,不用下载pdf阅读插件,但是在写网页的时候遇到了 pdf 文件怎么办呢,有两种解决办法,一种是用 falsh 来向用户展示,优点就是支持 ...

  10. jQuery的ready()事件与js中的onload事件的区别

    出处:http://blog.csdn.net/yuanmei1986/article/details/50781453