mysql服务器端口号
我刚刚在我的服务器上的 mysql 上创建了一个数据库。我想使用 php 通过我的网站连接到此。这是我的连接文件的内容:
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass)
or die('Error connecting to mysql');
$dbname = 'epub';
mysql_select_db($dbname);
我知道用户名/密码是什么,并且我知道服务器的 IP 地址。我只是想知道我如何知道要使用哪个端口?
I've just made a database on mysql on my server. I want to connect to this via my website using php. This is the contents of my connections file:
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass)
or die('Error connecting to mysql');
$dbname = 'epub';
mysql_select_db($dbname);
I know what the username/passwords are, and I know the IP address of the server. What I'm just wondering is how do I know which port to use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
如果您的 MySQL 服务器以默认设置运行,则无需指定。
默认 MySQL 端口为 3306。
[已更新以显示 mysql_error() 用法]
If your MySQL server runs on default settings, you don't need to specify that.
Default MySQL port is 3306.
[updated to show mysql_error() usage]
对于 Windows,如果您想知道运行 Mysql 的本地主机的端口号,您可以在 MySQL 命令行客户端上使用此查询 -
它将为您提供 MySQL 所在的端口号跑步。
For windows, If you want to know the port number of your local host on which Mysql is running you can use this query on MySQL Command line client --
It will give you the port number on which MySQL is running.
看看这个伙计
check this out dude
如果你想让你的端口作为变量,你可以这样编写 php:
if you want to have your port as a variable, you can write php like this:
如果您指定“localhost”,则客户端库默认使用 Unix 系统上的文件系统系统套接字 - 尝试 php.ini 中的 mysql_default_socket 值(如果已设置),然后尝试 my.cnf 值。
如果您使用其他工具进行连接,请尝试发出命令“显示变量,如'%socket%'”。
如果您想使用网络端口(速度稍慢),请尝试指定 127.0.0.1 或与机器。
If you specify 'localhost' the client libs default to using the filesystem system socket on a Unix system - trying the mysql_default_socket value from php.ini (if set) then the my.cnf value.
If you connect using a different tool, try issuing the command "show variables like '%socket%'"
If you want to use a network port (which is a wee bit slower) then try specifying 127.0.0.1 or a physical interface asociated with the machine.
这是仅 PDO 可视化,因为
mysql_*
库已弃用。请注意,这个OP问题似乎与端口号无关。如果您始终使用默认端口
3306
,请考虑将其从 uri 中删除,即删除port=$port;
部分。如果您经常更改端口,请考虑上述端口用法,以提高对
$port
变量进行更改的可维护性。上面返回的一些可能的错误:
在下面的错误中,在更改我们的连接信息之后,我们至少更接近了:
经过进一步的更改,我们现在确实很接近,但还不够:
从手册中PDO 连接:
This is a PDO-only visualization, as the
mysql_*
library is deprecated.Note that this OP Question appeared not to be about port numbers afterall. If you are using the default port of
3306
always, then consider removing it from the uri, that is, remove theport=$port;
part.If you often change ports, consider the above port usage for more maintainability having changes made to the
$port
variable.Some likely errors returned from above:
In the below error, we are at least getting closer, after changing our connect information:
After further changes, we are really close now, but not quite:
From the Manual on PDO Connections:
端口号 3306 用于使用 8080 端口的 MySQL 和 tomcat。更多端口号可用于运行服务器或软件,无论我们的即时编译是什么。8080 是默认端口号,因此只有我们在 eclipse IDE 中收到端口错误。 jvm和tomcat总是更喜欢8080.3306作为MySQL的默认端口号。所以只是不想每次都提到“localhost:3306”
port number 3306 is used for MySQL and tomcat using 8080 port.more port numbers are available for run the servers or software whatever may be for our instant compilation..8080 is default for number so only we are getting port error in eclipse IDE. jvm and tomcat always prefer the 8080.3306 is default port number for MySQL.So only do not want to mention every time as "localhost:3306"
尝试
try