• About

Learning On Demand

Learning anything from anywhere

HomeDatabaseReset MySQL password in FreeBSD

Reset MySQL password in FreeBSD

Published in Database by alamster - on Jun 2, 2008 - Comment Off

Just another post for my archive 🙂

One our sandbox accidently delete root account with host ‘localhost’. We need to recover the account by grant new root account back into system.

The steps are :

1. Turn off mysql service

sandbox# /usr/local/etc/rc.d/mysql-server stop

2. Run mysql with skip grant table mode

sandbox# mysqld_safe –skip-grant-tables &
[1] 5187
sandbox# Starting mysqld daemon with databases from /var/db/mysql

sandbox#

3. Login as user root with empty password

sandbox# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.51a FreeBSD port: mysql-server-5.0.51a

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

mysql>

4. Change root password with something

mysql> update user set password=password(’xxxxyyyy’) where user=’root’;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

5. Turn off mysql

sandbox# /usr/local/etc/rc.d/mysql-server stop

6. Turn on mysql service

sandbox# /usr/local/etc/rc.d/mysql-server start

Finish

P.S :

Just special note for login into mysql database, these methods are different :

This method use ‘127.0.0.1’ as host.

sandbox# mysql -uroot -p -h 127.0.0.1

This method use ‘localhost’ as host
sandbox# mysql -uroot -p

sandbox# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.0.51a FreeBSD port: mysql-server-5.0.51a

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

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,host from user;
+——-+———–+
| user | host |
+——-+———–+
| root | 127.0.0.1 |
| fikri | localhost |
| hanz | localhost |
| root | localhost |
+——-+———–+
4 rows in set (0.11 sec)

root can use ‘127.0.0.1’ and ‘localhost’ as host information.

Tags: change root mysql db login to 127.0.0.1 in mysql db reset mysql password

  • Twitter
  • Facebook
  • Google+
  • Pin It
  • LinkedIn
  • Email

you might also like

  • mysql error : Can’t create/write to file ‘/tmp/#sql_1581_0.MYI’ (Errcode: 13)

    by alamster

    Recent PHP downgrade to 5.2.10 also bring another problem with phpmyadmin. When I try to browse data

    Database · December 12, 2010
  • Export picture from mysql database to file

    by alamster

    [amazonify]032152599X:left[/amazonify] As our data getting mobile and copying picture is annoying fo

    Database / PHP · December 11, 2007
  • Insert data when empty and update it when data exist

    by alamster

    With so many function provided in mysql plus lazy, It seem like finding gem for replace my old appro

    Database · June 1, 2007

Recent Posts

  • Upgrade Phalcon with PECL
  • Quick fix PHP Cli version
  • memcache vs mecached and php.ini
  • Fix PHP version (7.3 to 7.4) for Phalcon on Mac Monterey
  • Centminmod, letsencrypt and Cloudflare DNS API
  • Install restic on Centos 7
  • Switch paid ssl back to letsencrypt in centminmod
  • Upload cover fails on OJS 3 and Centminmod
  • Collection of useful command in centminmod
  • Install New Phalcon PHP (v 4) in Windows 10 64 bit and Laragon
  • Compile Phalcon Extension on Centminmod
  • UpCloud review : another FreeBSD supported VPS
  • Install Ted on Centos 7.4
  • Free $20 for DevOps Class – openbsd, freebsd, dragonflybsd and netbsd vps
  • Install Laravel Valet on macOS Sierra
Top

© 2025 Learning On Demand. Free WordPress theme by Templatic