使用PHP通过SSL连接到MySQL
I'm writing my first script that will connect via SSL to a MySQL database. I have been doing a lot of reading on the subject and have come across many options on how to set it up; some that apply to my situation and some that don't. Here is my situation:
The MySQL server is on the same machine as the script. My SSL Certificate is installed. Is it secure to simply connect to the database via a page that is using SSL with the following code?
Connecting via https://www.mysitehere.com/myscript.php
$con = mysql_connect("localhost", "username", "password", MYSQL_CLIENT_SSL);
if (!$con) {die('Could not connect: ' . mysql_error());}
mysql_select_db("my_database", $con);
我正在编写我的第一个脚本,它将通过SSL连接到MySQL数据库。 我一直在做很多关于这个主题的阅读,并且遇到了很多关于如何设置它的选项; 一些适用于我的情况,一些不适用于我的情况。 这是我的情况: p>
MySQL服务器与脚本在同一台机器上。 我的SSL证书已安装。 通过使用SSL并使用以下代码的页面简单地连接数据库是否安全? p>
通过https://www.mysitehere.com/myscript.php连接
$ con = mysql_connect(“localhost”,“username”,“password”,MYSQL_CLIENT_SSL);
if(!$ con){die('无法连接:'。mysql_error());}
mysql_select_db( “my_database”,$ con);
code> pre>
div>
The MySQL server is on the same machine as the script. My SSL Certificate is installed. Is it secure to simply connect to the database via a page that is using SSL with the following code?
If you control the server(VPS) and PHP is on the same machine as MySQL(only need to allow connections from same machine) than it is pointless to use SSL for MySQL and will only result in overhead. You should just use firewall to protect MySQL like you should also do with memcached.
Otherwise you could read this section from MySQL to configure SSL. I think involves a little bit more than just $con = mysql_connect("localhost", "username", "password", MYSQL_CLIENT_SSL);
. For example you need to configure your SSL Certificate:
mysqld --ssl-ca=ca-cert.pem \
--ssl-cert=server-cert.pem \
--ssl-key=server-key.pem