mariadb grant ERROR 1045 (28000): Access denied for user

张映 发表于 2015-04-27

分类目录: mariadb

标签:,

用mariadb也有一段时间了,常用命令和语法,基本没变。比较复杂一点的,例如replication,也没有发现根mysql有什么不同的地方。

不过,今天真发现有不同的地方了,mariadb的权限管理根mysql不一样,mysql可以创建一个根root账户同等权限的账户,但是mariadb就不行了,写法上也所不同。

1,mariadb  grant授权报错

MariaDB [(none)]> grant all privileges on *.* TO tank@'192.168.%' IDENTIFIED BY 'test';
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

相同的命令在mysql下,执行是没有任何问题的。

一开始以为是mariadb的root账号和密码有问题,检查后没问题。

2,mariadb与mysql root权限不同

查看了一下,root账户所拥有的权限,mariadb和mysql是不一样的。

MariaDB [(none)]> show grants\G;
*************************** 1. row ***************************
Grants for root@localhost: GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'root'@'localhost' WITH GRANT OPTION
1 row in set (0.00 sec)

ERROR: No query specified
mysql> show grants;
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)

3,mariadb与mysql grant语法不同

具体的讲法以,请参考:https://mariadb.com/kb/en/mariadb/grant/

MariaDB [(none)]> grant all on test.* TO tank@'192.168.%' IDENTIFIED BY 'test';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant select on *.* TO tank@'192.168.%' IDENTIFIED BY 'test';
Query OK, 0 rows affected (0.00 sec)

第一条命令,将test库的所有权限都给tank

第二条命令,将所有库和表的select权限给tank

注意:all不能和*.*一起使用的,不然就报错了。



转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/mariadb/1721.html

1 条评论

  1. 燕子回旋 留言

    你的版本是多少,为啥我的可以呢
    [root@maria-master bin]# mysql -uroot -p
    Enter password:
    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 10
    Server version: 10.0.25-MariaDB MariaDB Server

    Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    MariaDB [(none)]>
    MariaDB [(none)]>
    MariaDB [(none)]> grant all on *.* to chenqh@'%' identified by 'haha';
    Query OK, 0 rows affected (0.00 sec)

    MariaDB [(none)]>