前言
上篇文章更改完mysql的端口号后网页无法连接数据库,按提示查看文档 “帮助->MatiaDB-MySQL",即点击下图中的“帮助->MatiaDB-MySQL"
文档说明
第二项说明“The default Database manager port is 3306. Connections that do not specify the port number will always be on the default port.”,意为默认连接数据库的端口号为3306
The default Database manager port is 3306. Connections that do not specify the port number will always be on the default port.
If the database manager (MySQL or MariaDB) you want to use is not the default one, it is therefore imperative to specify the port number in connection requests since it will not be using the default port 3306. We repeat, without specifying the port, it will be the default port that will be used, so 3306.
Normally, connection scripts do not mention the port to use. For example:
$mysqli = new mysqli('127.0.0.1', 'user', 'password', 'database');
or, in procedural :
$mysqli = mysqli_connect('127.0.0.0.1', 'user', 'password', 'database');
So, to connect with a manager that doesn't use port 3306, you have to specify the port number on the connection request:
$mysqli = new mysqli('127.0.0.1', 'user', 'password', 'database', '3307');
or, procedurally:
$mysqli = mysqli_connect('127.0.0.0.1', 'user', 'password', 'database', '3307');
To check the connections on the MySQL or MariaDB database manager, use the script:
wamp(64)\www\testmysql.php
by putting 'http://localhost/testmysql.php' in the browser address bar having first modified the script according to your parameters.
当你使用以下代码,即省略了端口号的方式连接数据库时,程序会以3306访问数据库
$mysqli = new mysqli('127.0.0.1', 'user', 'password', 'database');
或者
$mysqli = mysqli_connect('127.0.0.0.1', 'user', 'password', 'database');
解决方法
将网页文件中连接数据库的语句加上目前mysql或MariaDB使用的端口号即可
$mysqli = new mysqli('127.0.0.1', 'user', 'password', 'database', '3307');
或者
$mysqli = mysqli_connect('127.0.0.0.1', 'user', 'password', 'database', '3307');