Re: #2002 - The server is not responding (or the local MySQL server's socket is not correctly configured)
Posted by: Michael Felt
Date: March 31, 2006 01:31AM

For connecting using mysql there are two areas to be concerned with:

1. The GRANT access in the mysql admin
2. The arguments passed to mysql_connect()

First step is to be sure you have a valid 'root' user. The documentation I learned this from is here: http://dev.mysql.com/doc/refman/4.1/en/default-privileges.html

You will need these 'root' access rights to be able to perform the following steps.

(New users (prior to version 5.0) were created using the GRANT syntax. Starting with 5.0.2 There are new commands (link below). I shall continue here with the 'simplier' 4.1 documentation and examples.)

The following documents how to create a database that can be connected to with no password.

1. In mysql, or using mysqladmin: (from http://dev.mysql.com/doc/refman/4.1/en/adding-users.html)
=========================
First, use the mysql program to connect to the server as the MySQL root user:

shell> mysql --user=root mysql

If you have assigned a password to the root account, you also need to supply a --password or -p option for this mysql command and also for those later in this section.

After connecting to the server as root, you can add new accounts. The following statements use GRANT to set up four new accounts:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
-> IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
-> IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
mysql> GRANT USAGE ON *.* TO 'dummy'@'localhost';
===================
Note the last statement "GRANT USAGE ON *.* TO 'dummy'@'localhost';"

There is no 'IDENTIFIED BY' so there is no password needed to connect. As the user only has USAGE privileges the user 'dummy'@'localhost' can only read/select, etc.

Note that 'dummy'@'localhost' is a different USER than 'dummy'@'%'

To see the users known to your mysql you may want to use the following statements from the commandline...

$ mysql -u root -p mysql
mysql> SELECT user,host,password FROM user;

I have one user I permit to connect from other computers in my network. The output looks like this:

mysql> select user,host,password from user where user like 'eve%';
+---------+-------------------------------+------------------+
| user | host | password |
+---------+-------------------------------+------------------+
| evedb | % | 10f0cc3642fead47 |
| evedb | localhost | 10f0cc3642fead47 |
| evedb | 192.168.129.0/255.255.255.128 | 10f0cc3642fead47 |
| evedata | % | |
| evedata | localhost | |
| evedata | x121 | |
+---------+-------------------------------+------------------+
6 rows in set (0.00 sec)

the user evedb can connect from any computer in the network 192.168.129/25 while evedata can only connect from localhost,%,and x121.

The other difference is that evedb has a password and evedata does not.

So, moving on the the php part.

I have a very simple connect.inc template that I use. Basically, there are two mysql_foo() functions we are concerned with. The first is connecting to the mysql server, the second is the "optional" setting of the default database (the mysql use statement).

<?php

function my_connect()
{

$link = mysql_connect('x054', 'evedata', NULL);
return $link;
}

function db_start($dbname)
{
$link = my_connect();
mysql_select_db($dbname, $link);
}
?>

In a program I generally just make a call like:

db_start("eve");

Reviewing, the my_connect() function connects to the mysql server running on host 'x054', as user 'evedata', with NO PASS (NULL).

In db_start the mysql_select_db() uses the $link as credentials to set the default database (in this case "eve").

===============

Prior to version 5.0.2 GRANT implicitly created USERS
Starting with version 5.0.2 there is a specific statement for creating and deleting users. A link for those interested ....

http://dev.mysql.com/doc/refman/5.0/en/account-management-sql.html

Much more detail, similiar to above, but updated to version 5.0 is at:

"root" user rights -> http://dev.mysql.com/doc/refman/5.0/en/default-privileges.html

other user rights -> http://dev.mysql.com/doc/refman/5.0/en/user-account-management.html

Hope this helps, and is not too verbose.

Michael

Options: ReplyQuote


Subject
Written By
Posted
Re: #2002 - The server is not responding (or the local MySQL server's socket is not correctly configured)
March 31, 2006 01:31AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.