dongpao5261 2015-08-29 15:30
浏览 101
已采纳

用户root @ localhost [duplicate]拒绝访问

i am trying to connect to mysql,but it gives a warning mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) .I think the username and password is correct,because i have access to mysql in komand line.I also created another user and granted him all priveleges but still i have this warning.

I have access to phpMyAdmin.I am using wamp server(apache 2.4.9) and mysql 5.1

     <?php
      $conn = mysqli_connect("localhost", "root", "password");
       ?>
</div>
  • 写回答

3条回答 默认 最新

  • dsg24156 2015-08-29 16:55
    关注

    Let the following 2 lines fail if user exists and blahblah doesnt matter for now:

    create user 'root'@'localhost' identified by 'blahblah';
    create user 'root'@'127.0.0.1' identified by 'blahblah';
    

    Do your grants:

    grant all on *.* to 'root'@'localhost';
    grant all on *.* to 'root'@'127.0.0.1';
    

    Change the password to something you will remember:

    set password for 'root'@'localhost' = password('NewPassword');
    set password for 'root'@'127.0.0.1' = password('NewPassword');
    

    See how many root users you have. A real user is a user/host combo. The password will show up hashed:

    select user,host,password from mysql.user where user='root';
    

    or

    select user,host,authentication_string from mysql.user where user='root';
    

    The 2nd one above is for MySQL 5.7

    If you get more than the two users above, drop the others such as:

    drop user 'root'@'%';   -- this is the wildcard hostname, can be a security risk
    drop user 'root'@'::1';
    

    Still have only 2? I hope so. Use the select stmts above to check.

    Don't connect a user app using root. root is for maintenance only. It doesn't matter if it is server-side code, or if an admin is running it. Code that is not secured and/or injected with harmful statements gets to run as root. So there, that is why.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化