termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.16k stars 3.02k forks source link

[Bug]: Access denied for 'root'@'localhost' #19154

Closed iwantlogic closed 8 months ago

iwantlogic commented 8 months ago

Problem description

So i installed the db and started the daemon normally

mysql_install_db
mysqld_safe -u root

And then i logged in as $(whoami)

mysql -u $(whoami)

I did show databases and then there is no mysql!

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.019 sec)

And i tried logging in as root and this happened

mysql -u root -p
mysql: Deprecated program name. It will be removed in a future release, use '/data/data/com.termux/files/usr/bin/mariadb' instead
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

What steps will reproduce the bug?

install mariadb Start the daemon Login as root in mysql

What is the expected behavior?

It'll login as root and show mysql

System information

termux-info:

Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=16202
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
TERMUX__USER_ID=0
Packages CPU architecture:
arm
Subscribed repositories:
# sources.list
deb https://packages.termux.org/apt/termux-main/ stable main
# root-repo (sources.list.d/root.list)
deb https://packages-cf.termux.dev/apt/termux-root/ root stable
# x11-repo (sources.list.d/x11.list)
deb https://packages-cf.termux.dev/apt/termux-x11/ x11 main
# tur-repo (sources.list.d/tur.list)
deb https://tur.kcubeterm.com tur-packages tur tur-on-device tur-continuous
Updatable packages:
command-not-found/stable 2.4.0-10 arm [upgradable from: 2.4.0-9]
curl/stable 8.6.0 arm [upgradable from: 8.5.0]
eza/stable 0.18.0 arm [upgradable from: 0.17.3]
gh/stable 2.43.1 arm [upgradable from: 2.42.1]
libcurl/stable 8.6.0 arm [upgradable from: 8.5.0]
libusb/stable 1.0.27 arm [upgradable from: 1.0.26-1]
python-pip/stable 24.0-1 all [upgradable from: 23.3.2]
termux-tools version:
1.40.5
Android version:
7.1.1
Kernel build information:
Linux localhost 3.10.9-12108554 #1 SMP PREEMPT Wed Jun 13 13:31:20 KST 2018 armv7l Android
Device manufacturer:
samsung
Device model:
SM-T377V
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api
com.termux.termuxam
com.termux.window
sylirre commented 8 months ago

You normally not required to run mysql_install_db. But if you decide to do so, make sure you use correct options.

Bare minimum:

mysql_install_db --user=root --auth-root-authentication-method=normal --datadir=${PREFIX}/var/lib/mysql --basedir=${PREFIX}

Ensure that var/lib/mysql is empty before running this command.

Don't specify -p while running mysql client if never configured root password.

Screenshot_20240204-111727_Termux

iwantlogic commented 8 months ago

You normally not required to run mysql_install_db. But if you decide to do so, make sure you use correct options.

Bare minimum:

mysql_install_db --user=root --auth-root-authentication-method=normal --datadir=${PREFIX}/var/lib/mysql --basedir=${PREFIX}

Ensure that var/lib/mysql is empty before running this command.

Don't specify -p while running mysql client if never configured root password.

Screenshot_20240204-111727_Termux

Same error Edit: Saw that the mysql daemon was still running even when i exited

sylirre commented 8 months ago

You are not explaining all steps you did.

Read my previous message.

You may not run mysql_install_db unless manually erased $PREFIX/var/lib/mysql. The latter mentioned directory must be empty before you start initializing the new database.

When using mysql_install_db you should pay attention to used flags. Don't use defaults. They will never work for Termux.

To reinitialize the database directory, run these two commands:

rm -rf $PREFIX/var/lib/mysql
mysql_install_db --user=root --auth-root-authentication-method=normal --datadir=${PREFIX}/var/lib/mysql --basedir=${PREFIX}

The flag --auth-root-authentication-method=normal is important. Without it authentication will become broken.

To connect as root, use mysql -u root. Don't specify password requesting flag -p, there is no password set by default. Use flag -p only after setting user password.

Everything above is not just recommendations. This is only way how you can set up mariadb in Termux.

ricardojlrufino commented 4 months ago

This works for me

killall mariadbd
rm -rf $PREFIX/var/lib/mysql/*
mysql_install_db --user=root --auth-root-authentication-method=normal --datadir=${PREFIX}/var/lib/mysql
mysqld_safe -u root &

Change password

mysql -u root
use mysql;
set password for 'root'@'localhost' = password('YOUR_ROOT_PASSWORD_HERE');
flush privileges;
quit;

Allow remote access

CREATE USER 'root'@'%' IDENTIFIED BY 'password'; 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;