MySQL安裝后,需要允許外部IP訪問資料庫,修改加密配置與增加新用戶,配置用戶權限
修改組態檔,增加默認加密方式的配置項,
當連接資料庫的時候會報驗證方法不存在的錯誤,這是因為新版本mysql的加密規則有變化,所以連不上資料庫,具體可以看官網檔案,可以修改mysql的組態檔,修改加密規則為原來那種,然后重新加密下所使用用戶的密碼,
官網檔案的地址:https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html
修改MySQL用戶的加密方式,編輯組態檔
/etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
default_authentication_plugin=mysql_native_password
允許外部IP訪問,當使用root用戶的時候,直接修改root用戶的Host欄位
update user set host = '%' where user = 'root';
創建一個用戶并且賦予權限
CREATE USER 'tsh'@'%' IDENTIFIED BY 'tsh123';
SHOW GRANTS;
GRANT all ON *.* TO 'tsh'@'%'
flush privileges
視頻地址:
https://www.bilibili.com/video/av69432482/
PHP腳本:
$pdo=new PDO("mysql:host=127.0.0.1;dbname=my_test","tsh","tsh123");
var_dump($pdo);
$pdo->query('set names utf8');
$sth=$pdo->prepare("select * from index_test");
$sth->execute();
$res=$sth->fetchAll();
print_r($res);

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/137126.html
標籤:PHP
