• 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 server has gone away

    by alamster

    Its very rare case when I see message : “MYSQL server has gone away” , a few things to c

    Database · August 12, 2008
  • How to Enable Designer Tab on PhpMyAdmin

    by alamster

    I’m in the middle of project deadline and need to create simple erd. I ever see designer tab i

    Database · December 8, 2015
  • Startup memory difference Percona Server vs MariaDB

    by alamster

    When browsing for FreeBSD ports on database section I stumbleupon percona server and decide to see w

    Database / FreeBSD · October 11, 2014

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