When I use c9.io ,How can I connect to MySQL

白昼怎懂夜的黑 提交于 2019-12-10 12:27:53

问题


c9.io is a verygood website

I have a php zoon , and when I want to connect to MySQL,I don't know password. I have try [space] root ... but,all is wrong.

I can open mysql in shell , no password ,my operate return error: error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'

It's looks like, mysqld is not started 。(I have try “mysqld start”,but faild)

What I want to know, Is Mysql service free on c9.io ?


回答1:


We are extremely happy to announce our first iteration of MySQL support in Cloud9. It makes it super easy to install, start and stop a MySQL instance right in your workspace. The nice thing is that every workspace will run a separate database so your projects will never interfere with each other. You can control MySQL with the mysql-ctl command line tool run from the terminal.

# start MySQL. Will create an empty database on first start
$ mysql-ctl start

# stop MySQL
$ mysql-ctl stop

# run the MySQL interactive shell
$ mysql-ctl cli

You can then connect to the database with following parameters:

Option    Value   Comment
Hostname  $IP The same local IP as the application you run on Cloud9
Port  3306    The default MySQL port number
User  $C9_USER    Your Cloud9 user name
Password  -   No password since you can only access the DB from within the workspace
Database  c9  The database name

Of course this is just the beginning. We have for example plans to add a management UI to start and stop databases or pre-installing tools like phpMyAdmin. However we don’t want to make you wait for the fully integrated feature while we already have something that is enabling a lot of use cases and still super easy to use.

Stay tuned and happy coding.




回答2:


The documentation show how start, stop, and run the mysql environment.

Start the MySQL shell mysql-ctl start then in yor file.php:

$ip =  getenv("REMOTE_ADDR");
$port = "3306";
$user = "YorUsername";
$DB = "c9";

$conn = mysql_connect('$ip', '$user', '', '$db', '$port')or die(mysql_error());
mysql_select_db('$db','$conn')or die(mysql_error());
mysql_query("select * from YourTableName",'$conn')or die(mysql_error());

The line getenv("REMOTE_ADDR") return the same local IP as the application you run on Cloud9.



来源:https://stackoverflow.com/questions/21361376/when-i-use-c9-io-how-can-i-connect-to-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!