Archive for Database

Securing MySQL database on Cpanel Servers

After you setup Cpanel, you have to do few things to secure MySQL on Cpanel server.

1. Delete the test database

This can be done with command

mysqladmin drop test

2. Change MySQL root Password

This can be done through WHM, login to WHM as root

WHM > SQL Services > MySQL Root Password
WHM > SQL Services > Reset Local MySQL Root Password

3. Disable MySQL login with out user and Password

By default mysql allow login to MySQL without entering user name or password.

To disable this, delete the empty user, this can be done with phpMyAdmin

WHM > SQL Services > phpMyAdmin

Select database “mysql”, browse the table “users”, in this you will see a user with no user name, just delete it, after doing this MySQL will now allow login with out user name and password.

On Cpanel Servers, you can just enter mysql to login as root, this is because, /root/.my.cnf contains user name and password.

[client]
user = root
password = password

Comments off

Cpanel phpMyAdmin shows “test” database

On Cpanel Server, test database shows on all users phpMyAdmin.

This create problem as some new users create their tables on this “test” database and some other users delete these tables.

To correct this problem, just delete this default database with name “test”.

Before deleting the mysql database, just take a backup of it, so if some clients ask for data, you can restore the tables to users database.

# cd /root
# mysqldump test >test.sql

Now lets delete the Database, so it won’t show in phpMyAdmin

server20# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 129273 to server version: 4.1.10a

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> drop database test;
Query OK, 80 rows affected (0.02 sec)

mysql> exit
Bye
server20#

Comments off

MySQL Query Cache

The query cache stores the text of a SELECT query together with the corresponding result that was sent to the client. If an identical query is received later, the server retrieves the results from the query cache rather than parsing and executing the query again.

The query cache is extremely useful in an environment where you have tables that don’t change very often and for which the server receives a lot of identical queries. This is a typical situation for many Web servers that generate a lot of dynamic pages based on database content.

MySQL Query Cache

Comments off

MySQL Error: Can’t connect through socket /var/tmp/mysql.sock

On a Cpanel/WHM server running RHEL, after rebooting MySQL stoped working for all sites hosted on the server. I tried restarting MySQL, but it won’t solved the problem. Sites still shows the error message

Warning: mysql_pconnect(): Can’t connect to local MySQL server through socket ‘/var/tmp/mysql.sock’ (2) in /home/flashhos/public_html/index.php on line 9
Problem with dB connection!

The problem is, MySQL could not find the socket at /var/tmp/mysql.sock

So i locked the orginal location of socket with

# locate mysql.sock
/var/lib/mysql/mysql.sock
/usr/local/lib/mysql.sock
#

Found two files. So i go to /var/tmp/ and created a sym link to /var/lib/mysql/mysql.sock

# cd /var/tmp
# ln -s /var/lib/mysql/mysql.sock

After doing this, restarted MySQL server

service mysql stop
service mysql start

Now everything working fine.

Comments off

« Previous entries