PHP - MySQL Verbindung über TCP/IP
PHP - MySQL Verbindung über TCP/IP
Hallo zusammen,
ich muss PHP so umstellen, dass ein mysql_connect nicht über die Socket-Datei geht sondern über TCP/IP. Kann man dies global umstellen?
Hintergrund: MySQL läuft nicht local, sondern wird aber über SSH auf einen anderen Server getunnelt und auf localhost:3306 gemappt. Alle Skripte haben als DB-Aufbau nur localhost eingetragen - darf diese nicht umstellen.
Danke & Gruß
- klerfrq -
			
			
									
						
										
						ich muss PHP so umstellen, dass ein mysql_connect nicht über die Socket-Datei geht sondern über TCP/IP. Kann man dies global umstellen?
Hintergrund: MySQL läuft nicht local, sondern wird aber über SSH auf einen anderen Server getunnelt und auf localhost:3306 gemappt. Alle Skripte haben als DB-Aufbau nur localhost eingetragen - darf diese nicht umstellen.
Danke & Gruß
- klerfrq -
Re: PHP - MySQL Verbindung über TCP/IP
Du hast nur die Möglichkeit, statt localhost den MySQL-Server über die Loopback-IP 127.0.0.1 anzusprechen. Dann wird statt dem Socket eine IP-Verbindung verwendet...
			
			
									
						
										
						Re: PHP - MySQL Verbindung über TCP/IP
-H != -h
			
			
									
						
										
						Code: Select all
ipx11XXX ~ # mysql -h 127.0.0.1
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 74327
Server version: 5.0.72-log Gentoo Linux mysql-5.0.72-r1
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> status;
--------------
mysql  Ver 14.12 Distrib 5.0.72, for pc-linux-gnu (i686) using readline 5.2
Connection id:          74327
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          /usr/bin/less
Using outfile:          ''
Using delimiter:        ;
Server version:         5.0.72-log Gentoo Linux mysql-5.0.72-r1
Protocol version:       10
Connection:             127.0.0.1 via TCP/IP
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    latin1
Conn.  characterset:    latin1
TCP port:               3306
Uptime:                 18 days 9 hours 8 min 54 sec
Threads: 4  Questions: 3627843  Slow queries: 2  Opens: 14514  Flush tables: 1                                                                                                                                 Open tables: 1384  Queries per second avg: 2.284
Re: PHP - MySQL Verbindung über TCP/IP
Deshalb ist es auch offiziell dokumentiert ;)matzewe01 wrote:Was aber ganz schon inkonsequent ist.
PayPal.Me/JoeUser ● FreeBSD Remote Installation
Wings for Life ● Wings for Life World Run
„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
			
						Wings for Life ● Wings for Life World Run
„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
Re: PHP - MySQL Verbindung über TCP/IP
PHP verhält sich normalerweise so wie von mir oben geschrieben: mysql_connect nach localhost geht über den Socket, mysql_connect über 127.0.0.1 verwendet eine IP-Verbindung zum Standard- oder angegebenen Port. Ich kann diesem Verhalten auch durchaus was abgewinnen, wenn man z.B. den SQL-Server aus irgendwelchen Gründen nicht per Socket ansprechen will, nimmt man statt localhost einfach 127.0.0.1
			
			
									
						
										
						Re: PHP - MySQL Verbindung über TCP/IP
s/normalerweise/immer/danton wrote:PHP verhält sich normalerweise so wie von mir oben geschrieben
Das liegt daran, dass PHPs MySQL-Extension gegen MySQLs libmysqlclient gelinkt wird...
PayPal.Me/JoeUser ● FreeBSD Remote Installation
Wings for Life ● Wings for Life World Run
„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
			
						Wings for Life ● Wings for Life World Run
„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
Re: PHP - MySQL Verbindung über TCP/IP
/root/.my.cnfmatzewe01 wrote: In vielen Umgebungen (was ich nicht verbrochen habe!) ist dem localhosr root kein Passwort vergeben.
Ursache / Hintergrund sind häufig automatisierte Verwaltungsscripte, die leider root Rechte benötigen.
Der Admin hingegen keine Passworte in Scripte hinterlegen wollte.
Code: Select all
[mysqlcheck]
password = ...
user=root
[mysql]
password = ...
user=root
[mysqladmin]
password = ...
user=root
[mysqldump]
password = ...
user=root
und die Sache ist erledigt.
Re: PHP - MySQL Verbindung über TCP/IP
matzewe01 wrote:Nein, leider nicht.
Was ist mit Perl, PHP etc. Scripten?
Code: Select all
system("mysql -uroot < query.sql");Es hindert dich niemand daran einen extra User für die Scripte anzulegen, der eine entsprechende ~.my.cnf hat. Das ist tatsächlich keine schlechte Idee.Und weil ich ggf. root / admin Rechte auf db Seite benötige, muss und will ich die Scripte trotzdem nicht als root ausführen.
Re: PHP - MySQL Verbindung über TCP/IP
Also wer dem MySQL-root kein PW verpasst (/usr/bin/mysql_secure_installation), der hat auch ganz andere schwere Sicherheits-Probleme. Hat der MySQL-root aber ein PW gesetzt, greift Dein Szenario nicht mehr...
			
			
									
						
							PayPal.Me/JoeUser ● FreeBSD Remote Installation
Wings for Life ● Wings for Life World Run
„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
			
						Wings for Life ● Wings for Life World Run
„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.

