1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| + 创建数据库测试连接的php文件 vim mysql.php <?php $servername = "MYSQL服务器IP"; $username = "用户名"; $password = "密码"; $conn = mysqli_connect($servername,$username,$password); if($conn->connect_error){ die("数据库连接失败: ".$conn->connect_error); } echo "数据库连接成功"; phpinfo(); ?>
+ 如何确定数据库是否真的与站点形成联动? - mysqli函数的调用是否成功? --- active links 是否为1 1成功 0失败
vim /etc/php.ini display_errors = On - 开启php的报错信息
- 排错 Warning: mysqli_connect(): (HY000/1130): Host '192.168.137.136' is not allowed to connect to this MySQL server in /usr/local/nginx/html/mysql.php on line 5 数据库无法正常连接
- 修改数据库服务用户的host update mysql.user set host='%' where user='root'; //将root用户的权限改成任何主机都能访问 flush privileges; //刷新权限设置
Warning: mysqli_connect(): (HY000/2059): Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory in /usr/local/nginx/html/mysql.php on line 5 身份认证模块不匹配
alter user 'root'@'%' identified with mysql_native_password by 'Aa@123456'; //修改身份验证插件
+ 最后要查看 - mysqli函数的调用是否成功? --- active links 是否为1 1成功 0失败
|