etsuxのブログ

自分がハマったことなどを記録しています。

TermuxからMariaDBインストール、ERROR 1698 (28000): Access denied for user 'root'@'localhost'エラー(解決)

Railsに続いて以前書いた記事を参考にMariaDB(MySQL)のインストール。

TermuxでMariaDB(MySQL)をインストール/セットアップ - etsuxのブログ

なんとなく様子が違う。

$ pkg install mariadb
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  mariadb
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 17.2 MB of archives.
After this operation, 179 MB of additional disk space will be used.
Get:1 https://dl.bintray.com/termux/termux-packages-24 stable/main aarch64 mariadb aarch64 1:10.4.6-2 [17.2 MB]
Fetched 17.2 MB in 5s (3328 kB/s)
Selecting previously unselected package mariadb.
(Reading database ... 12072 files and directories currently installed.)
Preparing to unpack .../mariadb_1%3a10.4.6-2_aarch64.deb ...
Unpacking mariadb (1:10.4.6-2) ...
Setting up mariadb (1:10.4.6-2) ...
Initializing mysql data directory...
Installing MariaDB/MySQL system tables in '/data/data/com.termux/files/usr/var/lib/mysql' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is u0_a104@localhost, it has no password either, but
you need to be the system 'u0_a104' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/data/data/com.termux/files/usr' ; /data/data/com.termux/files/usr/bin/mysqld_safe --datadir='/data/data/com.termux/files/usr/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/data/data/com.termux/files/usr/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

 

このまま続けて、初期化、rootログインをしてみる。

$ mysql_install_db
mysql.user table already exists!
Run mysql_upgrade, not mysql_install_db
$ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost

 

初期化ができないのは、インストール中に初期化されているため(青いところ)。

rootでログインできないのはsudoが必要なため(紫のところ)。

さらにOSのログインユーザが作成済(緑のところ)。

ERROR 1698はMariaDBUnix_Socketが採用されたことによるもの。

MariaDB 10.4.1〜のユーザー認証がカオスな話(Unix_Socket) | GIZMELER

 

mysql_install_dbはインストール時に終わっているので不要。

sudoによるrootログインでなくてもOSにログインしているu0_a104ユーザが追加されているので、OSユーザでログインすればいいだけ。OSユーザでログインするときは、-uオプションは不要。Rails用のユーザを作っておいた。

$ mysql
MariaDB [(none)]> 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
MariaDB [(none)]> select user();
+-------------------+
| user()            |
+-------------------+
| u0_a104@localhost |
+-------------------+
1 row in set (0.001 sec)
MariaDB [mysql]> create user 'rails-user'@'localhost' identified by 'rails-passwd';
Query OK, 0 rows affected (0.007 sec)

MariaDB [mysql]> grant all on *.* to 'rails-user'@'localhost';
Query OK, 0 rows affected (0.006 sec)

MariaDB [mysql]> \q
Bye