MySQL: 除了root用户,拒绝用户'test'@'localhost'访问(密码验证:是)
P粉080643975
P粉080643975 2023-08-21 13:05:31
0
1
496
<p>我在使用mysql的非root/admin用户时遇到了问题,我按照下面的步骤创建用户和权限,请纠正我是否做错了:</p> <p>我在<code>RHEL 5.7 64bit</code>上安装<code>mysql</code>,安装包如下,一旦我完成了<code>rpm install</code>,我们就会</p> <ol> <li>使用<code>mysql_install_db</code>创建mysql数据库,然后</li> <li>启动mysql服务,然后</li> <li>使用<code>mysql_upgrade</code>也会对服务器进行操作。</li> </ol> <p>在这个过程之后,我可以使用<code>root</code>登录,但是用非root用户无法登录到服务器:</p> <pre class="brush:php;toolbar:false;">[root@clustertest3 ~]# rpm -qa | grep MySQL MySQL-client-advanced-5.5.21-1.rhel5 MySQL-server-advanced-5.5.21-1.rhel5 [root@clustertest3 ~]# cat /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwords=1 # Disabling symbolic-links is recommended to prevent assorted security risks; # to do so, uncomment this line: # symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [root@clustertest3 ~]# ls -ld /var/lib/mysql/mysql.sock srwxrwxrwx 1 mysql mysql 0 Nov 30 11:09 /var/lib/mysql/mysql.sock mysql> CREATE USER 'golden'@'%' IDENTIFIED BY 'password'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON * . * TO 'golden'@'%'; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> SELECT USER(),CURRENT_USER(); +----------------+----------------+ | USER() | CURRENT_USER() | +----------------+----------------+ | root@localhost | root@localhost | +----------------+----------------+ 1 row in set (0.00 sec) [root@clustertest3 ~]# mysql -ugolden -p Enter password: ERROR 1045 (28000): Access denied for user 'golden'@'localhost' (using password: YES)</pre> <p>这就是我遇到的问题,有没有解决办法?</p>
P粉080643975
P粉080643975

全部回复(1)
P粉301523298

不要将所有数据库的所有权限授予非root用户,这是不安全的(而且您已经有了具有该角色的"root"用户)

GRANT <privileges> ON database.* TO 'user'@'localhost' IDENTIFIED BY 'password';

此语句创建一个新用户并授予选定的权限。 例如:

GRANT INSERT, SELECT, DELETE, UPDATE ON database.* TO 'user'@'localhost' IDENTIFIED BY 'password';

请查看文档以查看所有详细的权限

编辑:您可以使用此查询查找更多信息(以"root"身份登录):

select Host, User from mysql.user;

查看发生了什么

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板