# Problems with MySQL



## wmorri (May 29, 2008)

Hi,

I am having some problems with MySQL. I am not able to get to the mysql command prompt. Whenever I try to get to the prompt I get this message:

```
[[email protected] ~]$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
```
Since then I tried to get to it using the

```
mysql -u root
```
That didn't work either. The last thing that I did was to do a chkconfig, and found this for mysql:

```
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off
```
I am running Fedora 10 and don't know what to do from here. I know that I don't normally post questions but I feel helpless on this one. So I am coming to the best place I know.

Cheers!


----------



## Skie (Mar 15, 2003)

I've had these problems before and they're a pain in the rear to fix. 

First thing, restart mysql using "/etc/init.d/mysql restart". If mysql doesn't start, please post any errors you get. If that doesn't help and your system hasn't run an updatedb recently, then type "updatedb" and let it run (this may take a few hours depending on how many files you have). Once that's done, do a "locate mysql.sock". There shouldn't be many results. There may be a symlink in /tmp pointing to the file located in /var/lib/mysql. 

Another thing to check is do a locate for "my.cnf" and ".my.cnf" and open each one and see if there is a socket path listed. If not, move on. If there is, make sure the path matches where the current socket is located. If the path doesn't, change the path and restart mysql. 

If the above doesn't help, shut down mysql (if it's still running) and rename any occurance of the socket and start mysql. It should create a whole new socket. You may want to check if there's a pid file in /var/lib/mysql before you start mysql. If there is, rename it as well.

Once you get mysql running properly and if you want it to start automatically when you restart the computer, do the following:

chkconfig --level 35 mysqld on


----------



## wmorri (May 29, 2008)

Hi,

Here is some of what you asked for. First is the /etc/init.d/mysqld restart

```
[[email protected] ~]$ /etc/init.d/mysqld restart
Stopping MySQL:                                            [FAILED]
touch: cannot touch `/var/log/mysqld.log': Permission denied
chown: changing ownership of `/var/log/mysqld.log': Operation not permitted
chmod: changing permissions of `/var/log/mysqld.log': Operation not permitted
chown: changing ownership of `/var/lib/mysql': Operation not permitted
chmod: changing permissions of `/var/lib/mysql': Operation not permitted
Starting MySQL:                                            [  OK  ]
touch: cannot touch `/var/lock/subsys/mysqld': Permission denied
```
Next is a piece of the my.cnf file that lists the socked path.

```
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
```



> If the above doesn't help, shut down mysql (if it's still running) and rename any occurance of the socket and start mysql. It should create a whole new socket. You may want to check if there's a pid file in /var/lib/mysql before you start mysql. If there is, rename it as well.


I don't know how to do this part of your response. I don't to that much with mysql.

UPDATE: I found an selinux troubleshooting ticket that might help you out.


```
SELinux is preventing mysqld_safe (mysqld_safe_t) "getattr" to /var/run/mysqld/mysqld.pid (mysqld_var_run_t). 

[b]Detailed Description[/b]
SELinux denied access requested by mysqld_safe. It is not expected that this access is required by mysqld_safe and this access may signal an intrusion attempt. It is also possible that the specific version or configuration of the application is causing it to require additional access. 

[b]Allowing Access[/b]

Sometimes labeling problems can cause SELinux denials. You could try to restore the default system file context for /var/run/mysqld/mysqld.pid, restorecon -v '/var/run/mysqld/mysqld.pid' If this does not work, there is currently no automatic way to allow this access. Instead, you can generate a local policy module to allow this access - see FAQ Or you can disable SELinux protection altogether. Disabling SELinux protection is not recommended. Please file a bug report against this package. 

[b]Additional Information[/b]

Source Context:**unconfined_u:system_r:mysqld_safe_t:s0
Target Context:**unconfined_u:object_r:mysqld_var_run_t:s0
Target Objects:**/var/run/mysqld/mysqld.pid [ file ]
Source:**mysqld_safe
Source Path:**/bin/bashPort:**<Unknown>
Host:**localhostSource RPM Packages:**bash-3.2-30.fc10
Target RPM Packages:**
Policy RPM:**selinux-policy-3.5.13-45.fc10Selinux Enabled:**True
Policy Type:**targeted
MLS Enabled:**True
Enforcing Mode:**Enforcing
Plugin Name:**catchall_file
Host Name:**localhost
Platform:**Linux localhost 2.6.27.15-170.2.24.fc10.i686 #1 SMP Wed Feb 11 23:58:12 EST 2009 i686 athlon
Alert Count:**1
First Seen:**Mon 23 Feb 2009 11:01:32 PM EST
Last Seen:**Mon 23 Feb 2009 11:01:32 PM EST
Local ID:**147fd850-f93f-4225-a161-1cda31d3df44
Line Numbers:**

[b]Raw Audit Messages :[/b]

node=localhost type=AVC msg=audit(1235448092.134:443): avc: denied { getattr } for pid=26697 comm="mysqld_safe" path="/var/run/mysqld/mysqld.pid" dev=dm-0 ino=157367 scontext=unconfined_u:system_r:mysqld_safe_t:s0 tcontext=unconfined_u:object_r:mysqld_var_run_t:s0 tclass=file 

node=localhost type=SYSCALL msg=audit(1235448092.134:443): arch=40000003 syscall=195 success=yes exit=0 a0=9360ac8 a1=bf8b11c0 a2=308ff4 a3=9360ac8 items=0 ppid=1 pid=26697 auid=500 uid=500 gid=500 euid=500 suid=500 fsuid=500 egid=500 sgid=500 fsgid=500 tty=pts1 ses=43 comm="mysqld_safe" exe="/bin/bash" subj=unconfined_u:system_r:mysqld_safe_t:s0 key=(null)
```
Cheers!


----------



## shuuhen (Sep 4, 2004)

Either prefix the script with sudo or use su to get to root. Like:

sudo /etc/init.d/mysqld restart

OR

su -
/etc/init.d/mysqld restart

For shutting down mysql, you can use the init script again, but instead of *restart*, use *stop*. Scripts in */etc/init.d/* should accept *start, stop* and *restart* as arguments since they correspond to services on your computer (well, things that have to be set up before use and shut down after).

So,

sudo /etc/init.d/mysqld stop


I assume the renaming the socket stuff is just if there's a /var/lib/mysql/mysql.sock file, just rename it to something like /var/lib/mysql/old-mysql.sock, whether with mv _old-name new-name_ in the terminal or if you have root access through some file manager (I don't do much with file managers :4-dontkno ).


----------



## wmorri (May 29, 2008)

Ok,

I was able to rename the mysql.sock file to old-mysql.sock. Other than that I will wait to hear from either of you in hopes that the logs that I gave you will help a little bit.

Cheers!


----------



## Skie (Mar 15, 2003)

It looks like you were trying to restart mysqld while logged in as a regular user. That might be why you're getting the permission denied errors. As shuuhen suggests, you'll either need to add sudo to each command you type in or login as root using su. I would suggest doing this first before you try anything else. When you run the chkconfig line, you'll also need to use sudo or login as root.


----------



## wmorri (May 29, 2008)

Hi Skie,

Here is the output when I try to restart mysql from root.

```
[[email protected] ~]# /etc/init.d/mysqld restart
Stopping MySQL:                                            [  OK  ]
Starting MySQL:                                            [  OK  ]
[[email protected] ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
```

EDIT: I got in!! I just needed to use this line in terminal:

```
[[email protected] ~]# mysql -u=root -p=(this is my root password)
```
Cheers!


----------

