php遠端連線伺服器報錯。

來源:互聯網
上載者:User
        $host = '遠程伺服器ip';$root = '使用者名稱';$pwd = '密碼';$con = @mysql_connect($host,$root,$pwd);mysql_query("set names 'utf8'");@mysql_select_db("XS_CQC", $con) or die(mysql_error());

我串連本地的資料庫是正常,但是串連遠端話報這個錯誤。

Access denied for user 'ODBC'@'localhost' (using password: NO)

這個是什麼意思?


回複討論(解決方案)

現在是 代碼在一個伺服器, 資料庫在另外一個伺服器。
是不是My Code有問題?

遠端連線 MySQL,需要對方授權

連結遠端資料庫的帳號要有遠程連結的許可權
在資料庫中執行
> GRANT ALL PRIVILEGES ON 資料庫名稱.* TO '使用者名稱'@'%' IDENTIFIED BY '密碼' WITH GRANT OPTION;
> FLUSH PRIVILEGES;

這樣就可以了

    $host = 'localhost';    $root = 'ODBC';    $pwd = '';        $con = @mysql_connect($host,$root,$pwd);     mysql_query("set names 'utf8'");    @mysql_select_db("XS_CQC", $con) or die(mysql_error());


敢問你的原始碼是這麼寫的麼.. 不是連遠程伺服器麼. 你的ip和使用者密碼貌似都沒改.

沒有連結許可權,
在對方的mysql 資料庫中需要什麼存取權限。
在phpmyadmin中設定user,host

    $host = 'localhost';    $root = 'ODBC';    $pwd = '';        $con = @mysql_connect($host,$root,$pwd);     mysql_query("set names 'utf8'");    @mysql_select_db("XS_CQC", $con) or die(mysql_error());


敢問你的原始碼是這麼寫的麼.. 不是連遠程伺服器麼. 你的ip和使用者密碼貌似都沒改.



源碼就是上面寫的遠程伺服器的IP,只是不方便透漏伺服器的IP跟 使用者名稱。 就打上中文了
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.