Thursday, November 1, 2012

wordpress - Error establishing a database connection

I once got this error, i checked wp-config.php and found the user/pwd has been typed correctly. So there's no problem with user/pwd, but still the wordpress will show error msg :
'error establishing a database connection'

This is maybe a solution :
- open wp-config.php
- go to the part define('DB_HOST', 'localhost');
- replace 'localhost' with '127.0.0.1:8889'

Cheers.

where is mysql root password ???

MAMP
Application/MAMP/bin/phpMyadmin/config.inc.php
Application/MAMP/bin/mamp/index.php

WORDPRESS
wordpress/wp-config.php


Friday, October 19, 2012

How To Change MySQL Root Password


Method 1. How to Change MySQL Root Password Using mysqladmin Command?

You can change the mySQL root password using mysqladmin command as shown below. Please note that there is no space between -p and currentpassword.
# mysqladmin -u root -pcurrentpassword password 'newpassword'
Once you’ve changed it make sure you can login with your new password successfully as shown below.
# mysql -u root -pnewpassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.25-rc-community MySQL Community Server (GPL)
mysql>

Method 2. How to Change MySQL Root Password From MySQL Prompt Using UPDATE SQL Command?

You can also use the standard update SQL command combined with the MySQL password function to change the password as shown below.

Login to MySQL root account using old password

# mysql -u root -poldpassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.25-rc-community MySQL Community Server (GPL)
mysql>

Use the UPDATE Command to change root password.

mysql> UPDATE user SET password=PASSWORD('newpassword') WHERE user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

Verify the new MySQL root password

Once you’ve changed it make sure you can login with your new password successfully as shown below.
# mysql -u root -pnewpassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.25-rc-community MySQL Community Server (GPL)
mysql>

Method 3. How to Set MySQL Root Password Using mysqladmin Command?

This method works only if there is no password currently assigned for the root account. If you don’t have any password assigned to the root account, set the password without giving current password as shown below.
# mysqladmin -u root password 'newpassword'
[Note: There is no currentpassword for root in this example]

How to Change MySQL Regular User (non-root) Password Using mysqladmin Command?

You can use the same mysqladmin command to change password for a mySQL end-user account as shown below.
# mysqladmin -u jsmith -pcurrentpassword password 'newpassword'

How to Change MySQL Regular User (non-root) Password From MySQL Prompt Using UPDATE SQL Command?

You can also use the standard update SQL command combined with the MySQL password function to change the password of a non-root user as shown below.
mysql> UPDATE user SET password=PASSWORD('newpassword') WHERE user='ramesh';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
copied from : http://www.thegeekstuff.com/2009/07/change-reset-mysql-root-password-on-unix-linux/

How To: Change Mysql root Password


Changing Mysql password is one of the very essential & critical task which you need to do while taking care of the database. By default “root” comes up with admin privileges and no password for root. Just to be clear, this root user is different from what your Linux/Unix system root user is, so changing password for this user, won’t change password for root user for operating system.
Mysql stores the password in the “user” table in “mysql” database. To change/update a password, we need to update that table data. That can be done either at the OS level with “mysqladmin” command or either at the Mysql level with sql command.
Changing Password with mysqladmin command:


mysqladmin command is one way to interact with the information stored in user table from OS command line interface. If you have done a fresh installation of Mysql, then there is no password set for root user. To set a new password for the same, use this command:
$ mysqladmin -u root password NEWPASSWORD
This will create the password for the root user.
Also, to change the password of root user, one needs to use the command like this:
$ mysqladmin -u root -p'oldpassword' password 'NEWPASSWORD'
If you don’t provide any old password with “-p”, then it will prompt you for a pasword after executing this command.
To change the password of normal user, same procedure is followed:
$ mysqladmin -u napster -p'oldpassword' password 'NEWPASSWORD'

Changing password with Mysql sql command:

You can also update the information in the user table with the sql command. Following steps needs to be followed for the same.
Login to Mysql server
$ mysql -u root -p'password'
Go to mysql database
mysql> use mysql;
Change password for napster user
mysql> update user set password=PASSWORD("NEWPASSWORD") where user="napster";
Now reload the privileges, which will update the cache and flush the old password
mysql> flush privileges;

mysql> ctrl+D
copied from : http://www.geekride.com/howto-change-mysql-root-password/

recover mysql password

One of the very worst scenarios for a system administrator is when they forget a password for the root account. That is the same case when a Database admin does the same for the root account for Mysql Database. So to help here, these are the following steps which one can perform to recover the root password back for Mysql database.


Stop Mysql Server:

$ sudo /etc/init.d/mysql stop
Then, start the mysql server with skip-grant-tables options. –skip-grant-tables option will force the mysql process not to read the user table into memory, so that when you try to login to the Mysql server, it won’t ask for the password.
$ sudo mysqld_safe --skip-grant-tables  &
This command is very dangerous if you Mysql server is connected to the network. While you are recovering your password, someone can login to your server remotely and do whatever he/she wants. To keep that safe, start your server with “–skip-networking” option, which will not open a network port for the server
$ mysqld_safe --skip-grant-tables --skip-networking &
Now connect to mysql server using mysql client without giving any password
$ mysql -u root -p

Now setup the new password for the root user:

mysql> use mysql;

mysql> update user set password=PASSWORD("NEWPASSWORD") where user="root";

mysql> flush privileges;

mysql> Ctrl+D
Now stop the mysql server
$ sudo /etc/init.d/mysql stop
Now start the mysql server normally, so that it could read the password information.
$ sudo /etc/init.d/mysql start
duplicated from : http://www.geekride.com/recover-mysql-root-password/

Saturday, June 30, 2012

my imac cannot pair to the bluetooth keyboard, it's been hijacked ...


Attention : this maybe not the solution for most of you. This is only a specific case happen to me that i want to share. So maybe there's another user have the same case.

So today i got weird problem after power failure. When restart my imac , the keyboard cannot be connected. After replacing the keyboard with my pc -usb keyboard, i  can get into the login window and type my password. I checked the bluetooth is working properly, the keyboard can be recognized but the pairing process is never succeeded. I try to google all the solution on the net and all are not working with me. after hours struggling with the problem, i suddenly remember that this morning i turn on bluetooth on my android phone … wait , you may think, what does that phone have something to do with my mac keyboard? ( i use samsung galaxy s2).. well i remember that i install some app in my phone which has the ability to connect to my mac-keyboard. So this is soooo stupid, i didn't realize it that every time i turn on my mac , it can't get connected to my keyboard for sure coz my android phone has taken over it. So while it's connected to my phone , there's no way my imac can connect to it. And the problem is there's no clue that my keyboard is connecting to which or what device. I almost throw out my keyboard. Also i'm thinking something silly, let say i bring the keyboard to check to other mac, it will always fail if my android phone is in my pocket (there still in range for bluetooth connection distance , right ?) , if i bring to service center , they will have problem at all to connect to their mac while later when they give back my keyboard , it won't work again. So i simply turn off bluetooth on my phone then restart mac. After pairing to my keyboard , i can use my keyboard as usual :-) .

Sorry like i said , this is not a solution for most user who experiencing the keyboard connection problem, it's just for sharing my case. So..watch out your other device near you that may 'hijack' your keyboard :-)

Thanx,

Wednesday, May 9, 2012

How to reload .bash_profile without restarting


$ source .bash_profile

PEAR/PECL MAMP 2.x Error : Notice: unserialize()

When i run my pecl/pear from MAMP bin folder , i got error message : 
Notice: unserialize(): Error at offset 276 of 1133 bytes in Config.php on line 1050
ERROR: The default config file is not a valid config file or is corrupted.

to fix :
  • Remove the pear.conf in MAMP folder OR
  • Find pear.conf, edit and change the "php_dir";s:44 into "php_dir";s:43
Now pecl/pear can run without error.


source : http://forum.mamp.info/viewtopic.php?t=13815

How to add python path to import external module (tested on python 2.7 mac osx)


option #1 : using site-packages folder
The location of python 2.7 framework is in /Library , this is different with python 2.6 which is installed in /System/Library. So inside the python framework folder , find the site-packages folder :
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
you can (choose one) :

  • put any external modules here, python will look up external modules from here automatically OR
  • keep the external modules in any folder you want , then in the 'site-packages' folder above, put/create any text file and name it <name>.pth , you can use any generic name like : mypath.pth etc. Then inside this file , type your path where the modules are located

Now open python shell and type module you want to import. ex: import myModule

option #2 : sys module
in the python file, add these code :

import sys
sys.path.append(path_to_modules) #ex: sys.path.append('/data/lib')
import <myModules_name> #test calling/import module

you can insert path into the beginning of the path list, by insert to index(0) :
sys.path.insert(0, path_to_module)

option #3 : .bash_profile
add these code into .bash_profile

# add python path

PYTHONPATH='path_to_modules_folder : $PYTHONPATH'

export PYTHONPATH

or
export PYTHONPATH = "/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/"

Tuesday, May 8, 2012

Metacharacter in Linux Regular Expression

Note : * and ? in grep means repetition. It does not behave as a wildcard in regular expression syntax (as it is in UNIX or DOS patterns). The / ?  +  are part of regex metacharacter.

Metacharacter

Meaning

?0 or 1
o? matches '' or 'o' but not 'oo'
bo?k matches : bk, bok but doesn't match : book,booooook
*0 or more
a* matches '' , 'a' , 'aa' , 'aaa'
ga*z matches : gz, gaz, gaaz, gaaaz but doesn't match : goz,giz
+1 or more
u+ matches 'u', 'uuu' but not ''
mu+te matches : mute,muute but not : mte,mate
{n}Matches the preceding character, or character range, n times exactly, for example, to find a local phone number we could use [0-9]{3}-[0-9]{4} which would find any number of the form 123-4567.
Note: The - (dash) in this case, because it is outside the square brackets, is a literal*. Value is enclosed in braces (curly brackets).
{n,m}Matches the preceding character at least n times but not more than m times, for example, 'ba{2,3}b' will find 'baab' and 'baaab' but NOT 'bab' or 'baaaab'. Values are enclosed in braces (curly brackets).
*literal means normal character (not metacharacter or escape or any other special character) , so it will be interpreted as is.

source : http://www.zytrax.com/tech/web/regex.htm#more-notes

how to setup PHP remote debug using komodo IDE & xdebug in Mac OS X


Step 1 - Copy the Debugging Extension to the Web Server

Before debugging PHP scripts in Komodo, PHP must be configured to use the Xdebug extension (php_xdebug.dll or xdebug.so).
Find the appropriate extension for the version of PHP you are running and manually copy it into a directory on the server that the PHP interpreter and web server can access. The Xdebug files can be found in the php sub-directory of the Komodo installation. For example:
  • Filexdebug.so
  • Location<komodo-install-directory>/Contents/SharedSupport/lib/support/php/debugging/<PHP-version>/ 

zend_extension_ts or zend_extension
Should be set to the full path to the xdebug library on your system. Use zend_extension_ts ("thread safe") on Windows and zend_extension on other platforms.
xdebug.remote_enable
Enables remote debugging.
xdebug.remote_handler
Should be set to dbgp for use with Komodo.
xdebug.remote_mode
Set to req to have the script connect to Komodo when it starts. Set to jit to connect only on an error condition (see PHP Just-in-Time Debugging / Break on Exception).
xdebug.remote_host
Set to the hostname or IP address of the computer running Komodo or the DBGP Proxy. Use 'localhost' or '127.0.0.1' if Komodo and the web server are running on the same system.
xdebug.remote_port
Set to the same value as the debugging listener port configured in the Debugger Connection preferences (or the system assigned Host Port displayed under Debug|Listener Status)
xdebug.idekey (optional)
If you are using the DBGP Proxy, set this to the Proxy Key configured in the Debugger Connection preferences.



Starting and Stopping a PHP Remote Debugging Session

Once remote PHP debugging is configured, the PHP interpreter can contact Komodo and initiate a remote debugging session when a PHP script is executed on the web server.

To initiate remote debugging from a web browser:

  1. Ensure PHP is installed and configured properly for your web server.
  2. Ensure Komodo and PHP are configured for remote debugging (as described in "Configuring Remote PHP Debugging").
  3. Click Debug | Listen for Debugger Connections.
  4. In your browser, enter the URL of the script you want to debug. Append ?XDEBUG_SESSION_START=1 to the end of the URL (an HTTP GET with a true boolean value). For example:
    http://example.org/sample.php?XDEBUG_SESSION_START=1
    
    If you are using the DBGP Proxy, the value for the GET method should match the Proxy Key value shown in Debug|Listener Status. For example:
    http://example.org/sample.php?XDEBUG_SESSION_START=jdoe 
    It is also possible to call XDEBUG_SESSION_START by adding it in an input element of an HTML form. For example:
    <input type="hidden" name="XDEBUG_SESSION_START" value="jdoe" />
    
    Note: This is only required for the first request. After that, Xdebug tracks the debugging session with a cookie. For more information on how this works, see www.xdebug.org/docs-debugger.php#browser_session
  5. A PHP debugging session starts in Komodo. On the Debug menu, click Step In or Go/Continue to run to the first breakpoint.



mysql : how to locate mysql db files stored

from inside mysql, type:
SHOW VARIABLES LIKE 'datadir';