Archive for the ‘MySQL’ Category

Create a new MySQL user – Howto?

Thursday, May 22nd, 2008

There are few ways you can create a new user for a MySQL DB.

  1. Using grant command to create a new user and assign privileges to access a DB.
  2. Use the create user mysql command followed by grant command to set access privileges.
  3. Directly editing the mysql DB using insert, update etc (which is a bit complex)

Create USER

For creating user following command is used

CREATE USER user [IDENTIFIED BY [PASSWORD] 'password']

The above command creates a new user, but who has no access to any DB. In order to grant prermissions to access any DB, we need to use the grant command.

Grant Command

GRANT ALL ON *.* TO 'someuser'@'somehost';

The above will grant ALL the permission (select, insert, updat, delet etc) to someuser at somehost. If you would like to set a user from a particular IP to access the DB, you can use like

GRANT ALL ON *.* TO 'someuser'@'IPADDRESS';

The following command will give only select and insert privileges to someuser at somehost

GRANT SELECT, INSERT ON *.* TO 'someuser'@'somehost';

Starting LAMPP automatically on startup

Thursday, April 3rd, 2008

For starting LAMPP automatically on startup, add the following line to you /etc/rc.local file

/opt/lampp/lampp start

where /opt/lampp is the location where XAMPP files are kept. You will have to substitute the path to your XAMPP in the above command.

Do let me know whether it worked for you ;)

How to access mysql command mode in XAMPP

Monday, March 10th, 2008

I had searched for some time for the same thing.. But here it is..

This is only in the case of a linux system..

Say your XAMPP files are at /opt/lampp

On command line, type (assuming you want to log in as root)
/opt/lampp/bin/mysql -u root -p

This will be followed by typing the mysql password, thats it.. You are on command mode of mysql !!

How to change root password in mysql ?

Wednesday, February 27th, 2008

You might have installed mysql and would like to change / set password for root. Password for root might be empty initially.. So this is what you need to do.

There is a mysqladmin command in unix,linux,freebsd to administer mysql.

Setting root password for mysql for the first time

Here the initial password is empty. Type the following comman.

mysqladmin -u root password YOURNEWPASSWORD

Here YOURNEWPASSWORD is the password you would like to set.

Alternatively, on command line, log in to mysql as root. This time password is not required. Then run an update query to update the password of root.

mysql -u root

update mysql.user set password=’NEWPASSWORD’ where user=’root’

Changing root/user password

Run the following command to change password for root. Replace root with the user name of other users in order to change their password.

mysqladmin -u root OLDPASSWORD NEWPASSWORD

OLDPASSWORD is old password and NEWPASSWORD is the new password.

Alternatively you can run the above query to modify the user password (see above).

XAMPP an easy LAMP installation solution

Monday, February 25th, 2008

Earlier I had messed up my LAMP test server trying to upgrade PHP from 4 to 5 and it was a real headache till I got everything to work..

Someone asked me a question – is there a simple way to install everything (Apache, MySQL PHP with necessary modules) in one shot without configuring each and everything manually.. I had no clue that time but I understood that there is a solution for this..

Just browsed http://www.apachefriends.org/en/xampp.html and found proof that there is a solution available.

Have you tried this? I have to mess up my server again if I have to test this ;) So let me see when time permits :) :)

[Update] There wasn’t mysql enabled on PHP5 when I installed RHEL5 afresh. So I had to remove the rpms of PHP, stop httpd,vsftpd and mysqld forever. Installed XAMPP and everything is working perfectly now..

There is a bit of security issues in XAMPP (Not so big if you take care). So read their documents properly.

Fatal error: Call to undefined function mysql_connect() !!

Wednesday, February 13th, 2008

I was about to start using my first program on PHP5, then I received this irritating message.

I was using PHP4 these days, so this error was something which revisited after a long time. In PHP4 I new what it means and how to rectify.

The error indicates that PHP was unable to connect to the MySQL DB and it is basically an error on the PHP installation/ missing library file.

Generally, one need to check following things in order to troubleshoot the current situation.

Is it PHP5 on which this error happened and are its after you migrated to PHP5? If then, one small peiece of information for you. MySQL support is not enabled by default in PHP5. You can read http://in.php.net/manual/en/faq.databases.php#faq.databases.mysql.php5 for the reasons and how to troubleshoot.

Following are some other basic troubleshooting steps.

Windows System

  1. Make sure in your PHP.ini file , the mysql extension is enabled. Look for a line containing ‘extension=php_mysql.dll’ and if there is a semicolon in front of this, its not enabled. So remove the semicolon to enable it.
  2. Check for the extension directory path in php.ini – ‘extension_dir = “C:\Program Files\PHP5\ext”‘ . make sure the path is correct, and you have the extension files in it. For mysql extension, you will need php_mysql.dll .

With this much, if mysql is present, you should not be seeing the error message again

Linux System

Make sure PHP is compiled with mysql support. Check http://in.php.net/mysql on the installation instructions.

If you are using PHP5 , mysql is not enabled by default :( (This is where the problem starts). So if you have PHP already installed, consider removing it and recompiling from the source with mysql support.

There are easier methods to set up LAMP systems. Please check  my post about XAMPP too

MySQL Storage Engines.. Some basics

Thursday, December 13th, 2007

Storage engines decide how and where the data is stored and in which way. MySQL storage engines include both those that handle transaction-safe tables and those that handle non-transaction-safe tables

MySQL supports following storage engines.

MyISAM Storage Engine
InnoDB Storage Engine
MERGE Storage Engine
MEMORY (HEAP) Storage Engine
BDB (BerkeleyDB) Storage Engine
EXAMPLE Storage Engine
FEDERATED Storage Engine
ARCHIVE Storage Engine
CSV Storage Engine
BLACKHOLE Storage Engine

One may choose a storage engine depending on the development requirement.

For example  – MyISAM is a disk based storage engine. Aiming for very low overhead, it does not support transactions where as  InnoDB is also disk based, but offers versioned, fully ACID transactional capabilities. InnoDB requires more disk space than MyISAM to store its data, and this increased overhead is compensated by more aggressive use of memory caching, in order to attain high speeds. The CSV storage engine stores data in CSV format.

Thats some basics about storage engines in MySQL !!