MySQL Story December 27, 2006
Posted by Nirmal in IT, school, technology.trackback
I was doing some work regarding accessing and manipulating databases using PHP [Personal Home Pages]. Actually in the lab it was quite fun, cause the database management system we were using, MySQL, was properly setup in those lab computers. But the real fun was at home. I of course had XAMPP installed, with Apache, PHP and MySQL, but I was having some difficulty in invoking MySQL client.
Windows story
Well this is what happened in Windows. I had XAMPP installed, as I said earlier, since I started work in PHP in October 2005. XAMPP has it’s own method of starting up MySQL, but afterwards it’s impossible to connect to the MySQL client over command line. It’s annoying enough. So I tried installing MySQL separately in C:\ using install media, but it didn’t work either. This was a permissions problem, for sure, and I had a bursting amount of assignments to do. So I did it quick way: logged into a lab computer, dragged the whole MySQL folder from C:\ to my flash disk, and dragged it back ashore on my home computer’s My Documents folder. Now it’s a breeze. I cd to My Documents, say ‘mysqld start’ (opeeen sesame!), and then MySQL works without any complaint. Yeah I know it’s a bit un-sporty and ‘dirty’ quick-fix, but I didn’t have any other choice for the time being. I’m not very sure as what happened, but I’m looking into it. If someone has an idea, of course you’re very welcome to leave a helpful comment. I just can’t bear going through obscure MySQL documentation.

Can’t understand XAMPP MySQL installation’s permissions problem. I had installed WordPress lately and it had no problem connecting and writing to the MySQL database. Wonder how.
Linux story
With Linux, ahh it’s a different story. Got Red Hat 9 so MySQL and PHP come prepackaged. Installed. OK ready to rock. Hmm.. mysql, what?? the client doesn’t even start up. OH, it hasn’t been started. Hadn’t had much experience with MySQL in Linux so turn to the Lanka Linux User Group. Got an entire Gmail account dedicated to their mailing list. Got some useful help. But not right bang on point. So do a search with *mysql* on my PC, get all the locations and here’s a screendump of what happened:
[astdb@localhost astdb]$ cd /etc/rc.d/init.d
[astdb@localhost init.d]$ ls
aep1000 crond iptables lisa ntpd saslauthd syslog
anacron cups irda mysqld pcmcia sendmail tux
apmd firstboot isdn netfs portmap single winbind
atd functions kdcrotate network postgresql snmpd xfs
autofs gpm keytable nfs random snmptrapd xinetd
bcm5820 halt killall nfslock rawdevices squid ypbind
canna httpd kudzu nscd rhnsd sshd
[astdb@localhost init.d]$ mysqld
bash: mysqld: command not found
[astdb@localhost init.d]$ sh mysqld
Usage: mysqld {start|stop|status|condrestart|restart}
[astdb@localhost init.d]$ sh mysqld start
touch: creating `/var/log/mysqld.log’: Permission denied
chmod: changing permissions of `/var/log/mysqld.log’: Operation not permitted
Initializing MySQL database: mkdir: Preparing db table
cannot create directory `/var/lib/mysql/mysql’: Permission denied
chmod: failed to get attributes of `/var/lib/mysql/mysql’: No such file or direc
tory
mkdir: cannot create directory `/var/lib/mysql/test’: Permission denied
chmod: failed to get attributes of `/var/lib/mysql/test’: No such file or direct
ory
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
ERROR: 1049 Unknown database ‘mysql’
Installation of grant tables failed!
Examine the logs in /var/lib/mysql for more information.
You can also try to start the mysqld daemon with:
/usr/libexec/mysqld –skip-grant &
You can use the command line tool
/usr/bin/mysql to connect to the mysql
database and look at the grant tables:
shell> /usr/bin/mysql -u root mysql
mysql> show tables
Try ‘mysqld –help’ if you have problems with paths. Using –log
gives you a log in /var/lib/mysql that may be helpful.
The latest information about MySQL is available on the web at
http://www.mysql.com
Please consult the MySQL manual section: ‘Problems running mysql_install_db’,
and the manual section that describes problems on your OS.
Another information source is the MySQL email archive.
Please check all of the above before mailing us!
And if you do mail us, you MUST use the /usr/bin/mysqlbug script!
061224 22:18:02 Aborting
061224 22:18:02 /usr/libexec/mysqld: Shutdown Complete
[FAILED]
[astdb@localhost init.d]$ cd /usr/bin
[astdb@localhost bin]$ mysql
ERROR 2002: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/m
ysql.sock’ (2)
[astdb@localhost bin]$
The point is I cannot use MySQL other than as a superuser [su] or root in Linux. MySQL can be started and used as root or superuser. I usually use Linux as a normal user, exercising root/superuser privileges only for system administration purposes. If anybody has an idea about how to configure MySQL to use as a normal user in Linux, please leave a comment. Thanks.
xampp-linux exists and it’s great. You can try that if you don’t want to spend time fighting the MySQL package of your chosen Linux distribution.
As for your other problem, it is (as you correctly surmised) to do with permissions. MySQL uses Unix style socket files to communicate with the server. The file you see in error 2002 is the socket file used for communication. If this already exists, it will be owned by root (because your server is apparently running as root). Therefore, no other user is able to open the file. This means that they cannot connect to the server.
(You may find the –user switch on mysqld to be useful in switching your mysql install to use some other user ID. the grant table problem you saw earlier was for the same reason. No other user ID except root had permissions to write to the data area).
Solution:
a) you can try specifying a separate socket file (either in my.cnf or as a command line option). Make sure your current system user can write to that location first :) then specify the new name for the socket file.
OR
b) modify the permissions (chmod 666 or or even chown to current user) on the mysql.sock file.
That will allow you to connect.
But like I said earlier, if all you want to do is use MySQL, just download xampp for Linux and spare yourself the pain till you have time to troubleshoot.