Allow Your Applications To Access The XAMPP MySQL Server Directly

Want to support HowtoForge? Become a subscriber!
 
Submitted by mrashad (Contact Author) (Forums) on Tue, 2010-04-06 12:22. :: Linux | MySQL

Allow Your Applications To Access The XAMPP MySQL Server Directly

 1- Preliminary Note

- I'm using "Ojuba 2" Linux ("Fedora 10" based distribution).
- To work with this HowTo you have to be "root".
- You need you to stop your local MySQL database server (if you have a local version).

/etc/init.d/mysqld stop

 

2- What is the situation

If you want to have a full featured "LAMP" server with one step you can use "XAMPP", it's easy and fast but .......
You can't access its MySQL database server using the regular "mysql" client (/usr/bin/mysql), you have to use its own client (/opt/lampp/bin/mysql) to do that.

 

3- What is the problem

This was a problem for me, I have some databases in the server and some other scripts and applications need these databases and using the regular "mysql" client (/usr/bin/mysql) by default, and there is no option to change all these scripts and applications' code to point to the "XAMPP" client.

 

4- The first solution (short one)

Move the original "mysql" client (/usr/bin/mysql) to a backup copy.

mv /usr/bin/mysql /usr/bin/mysql.original

Then create a symbolic link to the "XAMPP" client (/opt/lampp/bin/mysql) in the original location like this:

ln -s  /opt/lampp/bin/mysql /usr/bin/mysql

 

5- The second solution (full solution)

The second solution to solve that problem is to work with the sock file directly, the sock points us to the database server, applications that want to access the database server are looking for that file to know how to access it.

XAMPP saves its sock file in this location:

/opt/lampp/var/mysql/mysql.sock

But the regular applications will deal with the file in this location (if there is one):

/var/run/mysqld/mysqld.sock

To make all applications able to use the "XAMPP" database server we need to tell all these applications to deal with the "XAMPP" file, or simply we create a link from the "XAMPP" file into the regular file location, so every application that wants to access the database server will be forwarded to the "XAMPP" server.

We do this in one step:

ln -s /opt/lampp/var/mysql/mysql.sock /var/mysql/mysql.sock

After that all your applications should work as expected without problems. 

 

6- Thank you

Thank you for reading this and I hope to hear from you even in this site or directly on my site.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Maciek (not registered) on Tue, 2010-04-06 16:28.

Edit your my.cnf file (typically /etc/my.cnf or /etc/mysql/my.cnf) and add the following section or modify the existing one:

[client]
socket=/opt/lampp/var/mysql/mysql.sock

It should make the standard /usr/bin/mysql binary to locate and use the proper socket file.

Submitted by gm (not registered) on Tue, 2013-03-12 07:03.
Hi, I do mv on /usr/bin/msql to /usr/bin/mysql.orginal and i need to revert it reversing the process but it doesn't work. what will i do? Anyway, i have web (Centos 5.5) and database server (fedora 5) running on different machine in LAN, i wanted to connect the php scripts located in /var/www/html to mysql running in xammp linux "/opt/lampp/" but no query took placed. However, i can connect to the mysql from my web server using (mysql -u "username" -h "IP address on database" -p). What is problem on this. Please help gm
Submitted by mrashad (registered user) on Sat, 2010-04-10 20:44.

Thank you for your help, I didn't know that before

in my machine I found the file in "/etc/my.cnf" and the socket was under "[mysqld]" part like this "socket=/var/lib/mysql/mysql.sock"