最近在搞amazon ec2的服务器, 忒不熟悉, 一步一卡啊. apache2+php+mysql的环境搭好了, 在php中连接mysql始终连不上去, google了一大堆文章, 前人的智慧让人钦佩, 终于解决了. 文章地址: http://www.rackspace.com/knowledge_center/article/mysql-connect-to-your-database-remotely 步骤为: 1. c:/OpenSSH/bin/ssh 登录ec2服务器, 命令为: ssh -i AgeSecret.pem ubuntu@ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com 2. 以root登录mysql mysql –user=root -p 命令行会提示输入密码, 就是安装mysql时的密码. 3. 然后GRANT 用户 mysql>GRANT ALL ON databasename.* TO root@’xxx.xxx.xxx.xxx’ IDENTIFIED BY ‘password’ 其中databasename是你mysql中生成的数据库名字 xxx.xxx.xxx.xxx是服务器的IP地址 password是mysql的root用户的密码 4. php语句连接 $myconn=mysql_connect(“localhost”, “root”, “password”); mysql_select_db(“databasename”); |