MySQL: Recover root password

 

 

 

 

# mysql -u root
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
 
# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

 

 

1 Stop MySQL server:

# service mysql start

 

2. Add –skip-grant-tables to your mysql start script

# nano /etc/rc3.d/S20mysql

 

——————-

 

case "${1:-''}" in
  'start')
        sanity_checks;
        # Start daemon
        log_daemon_msg "Starting MySQL database server" "mysqld"
        if mysqld_status check_alive nowarn; then
           log_progress_msg "already running"
           log_end_msg 0
        else
            # Could be removed during boot
            test -e /var/run/mysqld || install -m 755 -o mysql -g root -d /var/run/mysqld
 
            # Start MySQL!
            /usr/bin/mysqld_safe –skip-grant-tables > /dev/null 2>&1 &
 
            # 6s was reported in #352070 to be too few when using ndbcluster
            for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
———————
 

 

3. Start your server again

 

# service -mysql start

 

4. Log in using mysql root user without entering a password:

# mysql -u root mysql

 

And let's do the actual reset:

 

——-

 

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 5.1.49-3 (Debian)
 
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> update user set password=Password('1234') where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit
Bye
 
——————
 
5. Stop the server one more time
 
# service mysql stop
 
6. Remove –skip-grant-table from your mysql startup command
 
# nano /etc/rc3.d/S20mysql
 
 
7. Start your mysqlserver
 
# service mysql start
 
 
8. Enjoy your server:
 
 
———————-
root@debian:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 5.1.49-3 (Debian)
 
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql>
————————-
 

 

Intranet: setup DJBDNS to respond for *.local to help development

 

0. Follow instructions to setup a DNS Cache

 

1. Create an alias for eth0:

# nano /etc/network/interfaces

auto eth0:0
iface eth0:0 inet static
       address 10.0.0.251
       netmask 255.255.255.0
       network 10.0.0.0
       broadcast 10.0.0.255
       gateway 10.0.0.254

2 . restart networking

# /etc/init.d/networking restart

 

3. Use tinydns-conf to setup djbdns 

# tinydns-conf dnscache dnslog /etc/tinydns 10.0.0.251

 

# ln -svf /etc/tinydns /etc/service

# cd /etc/service/tinydns/root/

 

 

4. Setup the "local" domain name:

# ./add-ns local 10.0.0.251

#./add-host a.ns.local 10.0.0.251

 

5. Create the data file for tinydns

# cd /etc/service/tinydns/root/

# nano data

 

.local:10.0.0.251:a:259200
=a.ns.local:10.0.0.251:86400
+*.local:10.0.0.250:86400

 
In the sample file above:
– 10.0.0.251 is the IP address of the DNS server, so it is the one responsibe for domain name responses
– 10.0.0.250 is the IP address of your future Web server
 
Save and update data/cdb
# make
 
 
 
6. Edit /etc/resolv.conf
search portnumber53.local
nameserver 10.0.0.251

 

 

7. Let dnscache know about your *.local domain names:

# cd /etc/service/dnscache

# echo 10.0.0.251 > root/servers/local

# chmod 644 root/servers/local

 

8. Restart dnscache

# svc -t .

 

 

 

Intranet: Setup a DNSCACHE for your network using DJBDNS

On this tutorial you will learn how to using DJBDNS to setup a DNS cache to help speed up queries for your local network.

 

I like using Debian, so that is the distribution I'll be using for most of my tutorials. Current version as of this, is Squeeze.

 

0.Install build-essential and daemontools and ucspi-tcp so we can get started:

# apt-get install build-essential ucspi-tcp daemontools daemontools-run

 

You can do everything as root, to make your life easier…. or just do the make commands (if you're paranoid):

 

1. Download and untar DjbDNS

# wget -q http://cr.yp.to/djbdns/djbdns-1.05.tar.gz
# tar -zxvvf djbdns-1.05.tar.gz

 

2. Add users for DjbDNS to /etc/passwd

# echo 'dnscache:*:54321:54321:dnscache:/dev/null:/dev/null' >> /etc/passwd
# echo 'dnslog:*:54322:54322:dnslog:/dev/null:/dev/null' >> /etc/passwd

 

3. Compile DjbDNS nameserver

# cd djbdns-1.05
# echo gcc -O2 -include /usr/include/errno.h > conf-cc

 

4. Compile it

# make

 

5. Install the binaries

# make setup check

 

 

6. Copy the list of IP addresses of the global DNS root servers in /etc/

# cp -rpf dnsroots.global /etc/

 

7.  Configure dnscache:

# ./dnscache-conf dnscache dnslog /etc/dnscache <IP address of this box>

 

8. Allow your network to use the DNS cache

# cd /etc/dnscache/root/ip
# touch 10.0.0

* This assumes you're using a network class A, like 10.0.0.0/24

 

9. Start the daemon

# ln -sf /etc/dnscache /etc/service/dnscache
# ps ax|grep -i readproc
 1071 ?        S      0:00 readproctitle service errors: ................................................................................................................................................................................................................................................................................................................................................................................................................
 1206 pts/1    S+     0:00 grep -i readproc
You can later check it's running using:
 
svstat /etc/service/dnscache
 
10. As root, add:
 
nameserver <IP address of this box>

 

to /etc/resolv.conf

 
 
11. Do a quick test:
(
If you're using ArchLinux, use:
pacman -Syu dnsutils
to install "host"
)
# host portnumber53.com <eth0 IP address>
Using domain server:
Name: localhost
Address: 127.0.0.1#53
Aliases:

portnumber53.com has address 205.186.185.42
portnumber53.com mail is handled by 20 ALT2.ASPMX.L.GOOGLE.com.
portnumber53.com mail is handled by 30 ASPMX2.GOOGLEMAIL.com.
portnumber53.com mail is handled by 20 ALT1.ASPMX.L.GOOGLE.com.
portnumber53.com mail is handled by 30 ASPMX3.GOOGLEMAIL.com.
portnumber53.com mail is handled by 30 ASPMX4.GOOGLEMAIL.com.
portnumber53.com mail is handled by 30 ASPMX5.GOOGLEMAIL.com.
portnumber53.com mail is handled by 10 ASPMX.L.GOOGLE.com.
 
 
12. Report success:
# ( echo 'First M. Last'; cat `cat SYSDEPS` ) \
# | mail [email protected]

 

 

 

 

 

 

Don't forget to replace First M. Last with your full name.
 
 

Later on you can monitor what's going under the hood by using:

# tail -f /etc/service/dnscache/log/main/current

 

If you installed following ArchLinux AUR packages, this may work better:

 

#tail -f /etc/dnscache/log/main/current

 

 

Git: Prepare your repository – step 1

 

Here I’ll explain how you can create a new repository for your projects and use GIT for your version control needs.
 
 
For this, I’ll assume everything is already installed (git and stuff). This also assumes you’re using an Operating System and not the Vermont thing.
 
Replace “example.com” with your own domain.
 
1. Create a base repository
 
$ mkdir example.com && cd example.com

$ git init
 
 
2. Create a standard .gitignore file
 
$ nano .gitignore
 
—————————-
cgi-bin/*

upload/

.idea/*

# Compiled source #

###################

*.com

*.class

*.dll

*.exe

*.o

*.so

# Packages #

############

# it's better to unpack these files and commit the raw source

# git has its own built in compression methods

*.7z

*.dmg

*.gz

*.iso

*.jar

*.rar

*.tar

*.zip

# Logs and databases #

######################

*.log

*.sql

*.sqlite

# OS generated files #

######################

.DS_Store*

ehthumbs.db

Icon?

Thumbs.db
—————————-
 
3. Add and commit the file to your local repository.
$ git add .gitignore

$ git commit -m "Added standard gitignore file"
 
4. Prepare your local repository for transportation:
$ cd ..

$ git clone --bare example.com example.com.git

$ touch example.com.git/git-daemon-export-ok
 
5. Copy it to your server
$ scp -r example.com.git SERVER:~/PATH_ON_THE_SERVER/example.com.git
 
6. Finish preparing your repository on the server:
 
$ ssh SERVER

$ cd ~/PATH_ON_THE_SERVER/example.com.git

$ git --bare update-server-info

$ cd hooks

$ mv post-update.sample post-update

$ chmod a+x post-update
 
From this point on, you should be able to clone your repository and start working.
 
Drop me a line if this does not work for you, and I'll be glad to try and help.
 

 

PHP Killer: Do not do this on your code

Unless you want/need to kill some time… do not do the following on your PHP code, or you will be banging your head against the wall:

 

1. Use trim() inside empty():

 

sample:

if (!empty(trim($item))) {

}

 

work around:

$item = trim($item);

if (!empty($item)) {

}

 

 

2. Typecast a parameter that is sent by reference to a function:

$random = shuffle((array) $items);

 

workround:

$items = (array) $items;

$random = shuffle($items);

 

 

 

Kohana 3.2.6: Change Default Route

Let’s define a redirect module that will handle all requests that were not handled by any other controller. It will also be a good place to include a 404 page.

modules/application/bootstrap.php

Kohana::modules(array(
.
.
'redirect' => MODPATH . 'redirect', //Redirect module
.
.
));

Route::set('default', '(<request>)',
 array(
 'request' => '(.*)',
 ))
 ->defaults(array(
 'controller' => 'redirect',
 'action' => 'index',
 ));

 

And then define the controller itself:

modules/redirect/classes/controller/redirect.php

<?php defined('SYSPATH') or die('No direct script access.');
/**
 * Handles all the redirecions that may happen
 *
 * @package......Redirect
 * @category.....SEO
 * @author.......Mauricio Otta
 * @copyright....PortNumber53.com
 */

class Controller_Redirect extends Controller {

  static public function action_index() {
    echo "Controller_Redirect::action_index();<br />";
    echo Request::current()->param('request');
  }

}

 

 

 

Code:: css-message-box

I just started a Google Code hosted project since I’m always in need of pretty message boxes for my HTML things.

Let me know if you want/can contribute to it. It’s currently licensed under GPL 2.0

Here’s the address:

http://code.google.com/p/css-message-box/

 

Why:

 

Installing DropBox on Slackware 13.1 64-bit

Before you start, let's make sure you have gnome docutils installed:

Get the package:

http://www.linuxfromscratch.org/blfs/view/cvs/gnome/gnome-doc-utils.html

Install GNOME Doc Utils (this part is borrowed from LinuxFromScratch book)

./configure --prefix=$(pkg-config --variable=prefix ORBit-2.0) --mandir=$(pkg-config --variable=prefix ORBit-2.0)/share/man make 

Test it

make check

and then install as root:

make install

switch to Dropbox installation folder

cd /nautilus-dropbox-0.6.3

./configure

Kohana 3: Default Template [step 3]

Create the view for the default template:

/modules/common/views/template/default/default.php

 

<!DOCTYPE html>

<head>
 <title>Default template</title>

</head>

<body>
 <?php echo $content; ?>
</body>

</html>

 

 

 

Kohana 3.1.x: Common controller [step 2]

Define parent controller:

 

 

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Common_Content extends Controller_Template {

 public $template                = '';
 public $template_name           = 'default';
 public $layout                  = 'default';

 public $save_auto_render        = null;

 public $content                 = '{Do something to generate content}';

 public function __construct(Request $request, Response $response) {
 parent::__construct($request, $response);

 $this->session = Session::instance();

 }

 public function before() {

 $this->save_auto_render = $this->auto_render;
 $this->auto_render = false;
 parent::before();
 $this->auto_render = $this->save_auto_render;

 if ($this->auto_render) {
 $this->template = View::factory('template/' . $this->template_name . '/' . $this->layout)
 ->bind('content', $this->content);

 }

 }

 public function action_view_html() {
 $path = $this->request->param('path');

 echo "PATH: $path";
 }

 public function after() {
 parent::after();

 if ($this->auto_render) {
 } else {
 $this->response->headers('content-type', 'application/json');
 echo json_encode($this->content);
 }

 }

}