Archive

Posts Tagged ‘MySQL’

How to convert String to Date in SQL statement?

December 24th, 2008 No comments

This is a list of handy tips that could help you in a blink on how to convert String to Date in SQL. This post cover 5 popular databases (Oracle, MySQL, DB2, PostgreSQL, Informix)

Post your comment here if you find this post useful or want to contribute more explaination.

Oracle

Syntax:

to_date(date_string, format)

Example:

SELECT user.name, user.location FROM user
WHERE user.starteddtm = to_date('20/10/2007 16:01', 'dd/mm/yyyy hh24:mi');

Read more…

Categories: Programming

How to install PHPMyAdmin in Ubuntu Server?

December 8th, 2008 No comments

If you are using Ubuntu version 7.10 or above, you can install PHPMyAdmin using apt-get.

I assume that you have apache and php installed on your system.

The following steps is guiding you to install PHPMyAdmin and get it running

  1. Run this command

    sudo apt-get install phpmyadmin

  2. Edit this file

    sudo vi /etc/apache2/apache2.conf

  3. Add this line
    Include /etc/phpmyadmin/apache.conf
  4. Save file and exit
  5. Now go to http://localhost/phpmyadmin
  6. Login using your mysql root account and make sure all the databases/tables are showing
Advertisement ยป PHPMyAdmin Book for your further reading
Categories: FAQ & Tip

How to reset MySQL root password

September 2nd, 2008 No comments

One day you forgot your root password for your MySQL database server and blaming yourself for not written it somewhere for easy access.

Ok, do it no more! here’s my short version (of official instruction) for advance user who does not need too much of instruction details

On Windows

  1. As admin, Stop the MySQL server, make sure it’s completely stop
  2. Create a text file eg. C:mysql-init.txt and past the following statement in
    UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root';
    FLUSH PRIVILEGES;
  3. Open up your Windows Command Prompt
  4. Run this command
    C:mysqlbinmysqld-nt --init-file=C:mysql-init.txt

    Change path if your sever install on somewhere else.
    For wizard installation of mysql, you might have to do this

    "C:Program FilesMySQLMySQL Server 5.0binmysqld-nt.exe"
    --defaults-file="C:Program FilesMySQLMySQL Server 5.0my.ini"
    --init-file=C:mysql-init.tx
  5. Now delete C:mysql-init.txt then restart MySQL server again

On Linux or Unix

  1. Stop MySQL server as follow
    Find .pid file in /var/lib/mysql/, /var/run/mysqld/ and /usr/local/mysql/data/
  2. Now run
    $ kill `cat /mysql-data-directory/host_name.pid`
  3. Create a text file eg. /home/yourid/mysql-init and past the following statement in
    UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root';
    FLUSH PRIVILEGES;
  4. Start mysql server with the following options
    mysqld_safe --init-file=/home/me/mysql-init &
  5. Delete mysql-init file then finished

Alternative but less secure

  1. Stop mysqld and restart it with the --skip-grant-tables option.
  2. Connect to the mysqld server with this command
    $ mysql
  3. Now run the following statement
    UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root';
    FLUSH PRIVILEGES;
  4. Finished
Categories: FAQ & Tip