1. <legend id='lAZsr'><style id='lAZsr'><dir id='lAZsr'><q id='lAZsr'></q></dir></style></legend>
    <tfoot id='lAZsr'></tfoot>

    <i id='lAZsr'><tr id='lAZsr'><dt id='lAZsr'><q id='lAZsr'><span id='lAZsr'><b id='lAZsr'><form id='lAZsr'><ins id='lAZsr'></ins><ul id='lAZsr'></ul><sub id='lAZsr'></sub></form><legend id='lAZsr'></legend><bdo id='lAZsr'><pre id='lAZsr'><center id='lAZsr'></center></pre></bdo></b><th id='lAZsr'></th></span></q></dt></tr></i><div id='lAZsr'><tfoot id='lAZsr'></tfoot><dl id='lAZsr'><fieldset id='lAZsr'></fieldset></dl></div>
  2. <small id='lAZsr'></small><noframes id='lAZsr'>

      <bdo id='lAZsr'></bdo><ul id='lAZsr'></ul>

    1. 连接失败:用户 ''username'@'localhost

      时间:2023-07-29

        <tfoot id='pTN85'></tfoot>

      1. <small id='pTN85'></small><noframes id='pTN85'>

            <bdo id='pTN85'></bdo><ul id='pTN85'></ul>
                  <tbody id='pTN85'></tbody>

              • <legend id='pTN85'><style id='pTN85'><dir id='pTN85'><q id='pTN85'></q></dir></style></legend>
                <i id='pTN85'><tr id='pTN85'><dt id='pTN85'><q id='pTN85'><span id='pTN85'><b id='pTN85'><form id='pTN85'><ins id='pTN85'></ins><ul id='pTN85'></ul><sub id='pTN85'></sub></form><legend id='pTN85'></legend><bdo id='pTN85'><pre id='pTN85'><center id='pTN85'></center></pre></bdo></b><th id='pTN85'></th></span></q></dt></tr></i><div id='pTN85'><tfoot id='pTN85'></tfoot><dl id='pTN85'><fieldset id='pTN85'></fieldset></dl></div>
                本文介绍了连接失败:用户 ''username'@'localhost' 访问被拒绝(使用密码:YES)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试连接到服务器上的 MySQL,但出现以下错误.用户已创建并被授予所有权限.

                I am trying to connect to MySQL on the server but gives following error. User is created and granted all privileges.

                它可以在本地机器上运行,但在部署到服务器之后就不行了.

                还有 mysql_connect 函数可以工作,但是 new mysqli() 给出如下所述的拒绝访问.

                Also mysql_connect function works but new mysqli() gives access denied as mentioned below.

                也尝试添加端口.

                警告: mysqli::mysqli(): (HY000/1045): Access denied for user ''usernam'@'localhost' (using password: YES) in/home/domainname/public_html/autopublish/test.php on8号线连接失败:用户 ''username'@'localhost' 访问被拒绝(使用密码:YES)

                Warning: mysqli::mysqli(): (HY000/1045): Access denied for user ''usernam'@'localhost' (using password: YES) in /home/domainname/public_html/autopublish/test.php on line 8 Connection failed: Access denied for user ''username'@'localhost' (using password: YES)

                <?php
                    $servername = "localhost";
                    $username = "'xxxxx";
                    $password = "xxxxx";
                    $dbname = "xxxxx";
                
                    // Create connection
                    $conn = new mysqli($servername, $username, $password);  **//line 8**
                    // Check connection
                    if ($conn->connect_error) {
                        die("Connection failed: " . $conn->connect_error);
                    } else {
                        echo "no connection";
                    }
                
                    $sql = "SELECT * FROM pages";
                    $result = $conn->query($sql);
                    
                    $data = array();
                    $arr = array();
                    
                    if ($result->num_rows > 0) {
                        // output data of each row
                        while($row = $result->fetch_assoc()) {
                            
                        }
                    } else {
                        echo "No Token";
                    }
                    print_r(json_encode($data));
                    $conn->close();
                    
                ?>
                

                推荐答案

                要么用户没有数据库所需的权限,要么密码错误.

                Either the user does not have the required rights for the database or the password is wrong.

                否则删除用户并使用以下语句创建:

                Otherwise remove the user and use the following statement to create:

                1.CREATE USER 'user'@'localhost' IDENTIFIED BY '123456789';
                2.
                3.GRANT ALL PRIVILEGES ON project.* TO 'user'@'localhost' WITH GRANT OPTION;
                

                或者试试这个:

                <?php
                $servername = "localhost";
                $username = "username";
                $password = "password";
                $dbname = "dbname";
                //Create
                mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
                $conn = new mysqli($servername, $username, $password, $dbname);
                
                echo "Yaaay";
                

                这篇关于连接失败:用户 ''username'@'localhost' 访问被拒绝(使用密码:YES)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:尝试使用 mysqli 连接到数据库时出现 Codeigniter 错 下一篇:没有选择数据库错误信息

                相关文章

                最新文章

                  • <bdo id='3SaXw'></bdo><ul id='3SaXw'></ul>
                1. <i id='3SaXw'><tr id='3SaXw'><dt id='3SaXw'><q id='3SaXw'><span id='3SaXw'><b id='3SaXw'><form id='3SaXw'><ins id='3SaXw'></ins><ul id='3SaXw'></ul><sub id='3SaXw'></sub></form><legend id='3SaXw'></legend><bdo id='3SaXw'><pre id='3SaXw'><center id='3SaXw'></center></pre></bdo></b><th id='3SaXw'></th></span></q></dt></tr></i><div id='3SaXw'><tfoot id='3SaXw'></tfoot><dl id='3SaXw'><fieldset id='3SaXw'></fieldset></dl></div>
                2. <tfoot id='3SaXw'></tfoot>

                  <legend id='3SaXw'><style id='3SaXw'><dir id='3SaXw'><q id='3SaXw'></q></dir></style></legend>

                  <small id='3SaXw'></small><noframes id='3SaXw'>