Resetting MariaDB “root” Password on Termux

I just started learning Laravel framework for my self-interest and wanted to play with it on my Galaxy Note 8 since I already had Termux installed on it. A tutorial I found from Google search uses mySQL so I installed MariaDB with the following command:$ pkg install mariadb

The installation was successful, but when I tried to log in as root with no password, it failed with ERROR 1698 (28000): Access denied for user 'root'@'localhost'. I tried various passwords but none was successful. So, I searched for a solution.

Disclaimer: The information described here is from Termux Wiki. This information below is solely used for my purpose and may not be suitable for others.

Post Installation Tasks:

After the first login attempt, I realized that it was not connecting to mysql server because of the following error message:$ mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/data/com.termux/files/usr/tmp/mysqld.sock' (2)

Was mysql server not running...? $ ps -aux | grep mysql xxx 8451 0.2 1.4 560836 79496 ? S

It looks to me, it's running fine. Is mysqld.sock file missing from the directory?:$ ls ../usr/tmp/ $

Ok, the directory was empty. So, I manually started mysql daemon with the following command:$ mysqld_safe -u root & [1] 8379 191029 20:48:14 mysqld_safe Logging to '/data/data/com.termux/files/usr/var/lib/mysql/localhost.err'. 191029 20:48:14 mysqld_safe Starting mysqld daemon with databases from /data/data/com.termux/files/usr/var/lib/mysql

After this, mysqld.sock was created.$ ls ../usr/tmp mysqld.sock $

Resetting root Password:

According to the wiki, the mariadb installation initializes the database with 2 all-privilege accounts, root and my Termux local user. With this local user, I can reset the root password. (But is there a point of resetting the root password at this point since my local user also has all privileges?)$ mysql -u $(whoami) Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 10.4.6-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> use mysql; MariaDB [(mysql)]> set password for 'root'@'localhost' = password('YOUR_ROOT_PASSWORD_HERE'); MariaDB [(mysql)]> flush privileges; MariaDB [(mysql)]> quit;

Now, I can log in as root.$ mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 10.4.6-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>

That's all!
-gibb

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>