Pehea e hoʻohana ai i ka MySQL me ka ʻole o ka ʻōlelo huna (a me nā pilikia palekana)

Pehea e hoʻohana ai i ka MySQL me ka ʻole o ka ʻōlelo huna (a me nā pilikia palekana)

'Ōlelo lākou ʻo ka ʻōlelo huna maikaʻi ʻaʻole pono ʻoe e hoʻomanaʻo. I ka hihia o MySQL hiki ke mahalo i ka plugin auth_socket a me kāna mana no MariaDB - unix_socket.

ʻAʻole hou kēia mau plugins ʻelua; nui nā mea i ʻōlelo ʻia e pili ana iā lākou ma kēia blog like, no ka laʻana ma ka ʻatikala e pili ana pehea e hoʻololi ai i nā ʻōlelo huna ma MySQL 5.7 me ka hoʻohana ʻana i ka plugin auth_socket. Eia nō naʻe, i ka nānā ʻana i nā mea hou ma MariaDB 10.4, ʻike wau ua hoʻokomo ʻia ka unix_socket ma ka paʻamau a ʻo ia kekahi o nā ala hōʻoia ("kekahi o", no ka mea ma MariaDB 10.4 ʻoi aku ka nui o hoʻokahi plugin i loaʻa i hoʻokahi mea hoʻohana no ka hōʻoia ʻana, ʻo ia ka mea. ua wehewehe ʻia ma ka palapala "Ka hōʻoia" mai MariaDB 10.04).

E like me kaʻu i ʻōlelo ai, ʻaʻole kēia he nūhou, a i ka wā e hoʻokomo ai i ka MySQL me ka hoʻohana ʻana i nā pūʻulu .deb i kākoʻo ʻia e ka hui Debian, ua hana ʻia kahi mea hoʻohana kumu no ka hōʻoia socket. He ʻoiaʻiʻo kēia no MySQL a me MariaDB.

root@app:~# apt-cache show mysql-server-5.7 | grep -i maintainers
Original-Maintainer: Debian MySQL Maintainers <[email protected]>
Original-Maintainer: Debian MySQL Maintainers <<a href="mailto:[email protected]">[email protected]</a>>

Me nā pūʻolo Debian no MySQL, ua hōʻoia ʻia ka mea hoʻohana kumu penei:

root@app:~# whoami
root=
root@app:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.27-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> select user, host, plugin, authentication_string from mysql.user where user = 'root';
+------+-----------+-------------+-----------------------+
| user | host      | plugin | authentication_string |
+------+-----------+-------------+-----------------------+
| root | localhost | auth_socket |                       |
+------+-----------+-------------+-----------------------+
1 row in set (0.01 sec)

Pela ka hihia me ka .deb package no MariaDB:

10.0.38-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

MariaDB [(none)]> show grants;
+------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                      |
+------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED VIA unix_socket WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION                                  |
+------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

Hoʻonohonoho pū nā pūʻolo .deb mai ka waihona kūhelu Percona i ka hōʻoia ʻana o ka mea hoʻohana ma lalo o ka auth-socket a no Percona Server. E hāʻawi kākou i laʻana me Server Percona no MySQL 8.0.16-7 a me ka Ubuntu 16.04:

root@app:~# whoami
root
root@app:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 9
Server version: 8.0.16-7 Percona Server (GPL), Release '7', Revision '613e312'

Copyright (c) 2009-2019 Percona LLC and/or its affiliates
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> select user, host, plugin, authentication_string from mysql.user where user ='root';
+------+-----------+-------------+-----------------------+
| user | host      | plugin | authentication_string |
+------+-----------+-------------+-----------------------+
| root | localhost | auth_socket |                       |
+------+-----------+-------------+-----------------------+
1 row in set (0.00 sec)

No laila he aha ke kilokilo? Hoʻopili ka plugin i ka hoʻohana ʻana o ka mea hoʻohana Linux i ka mea hoʻohana MySQL me ka hoʻohana ʻana i ke koho socket SO_PEERCRED e hōʻiliʻili i ka ʻike e pili ana i ka mea hoʻohana e holo ana i ka papahana mea kūʻai aku. No laila, hiki ke hoʻohana wale ʻia ka plugin ma nā ʻōnaehana e kākoʻo ana i ke koho SO_PEERCRED, e like me Linux. ʻO ka koho SO_PEERCRED socket hiki iā ʻoe ke ʻike i ka uid o ke kaʻina hana e pili ana i ke kumu. A laila ua loaʻa iā ia ka inoa inoa e pili ana i kēia uid.

Eia kekahi laʻana me ka mea hoʻohana "vagrant":

vagrant@mysql1:~$ whoami
vagrant
vagrant@mysql1:~$ mysql
ERROR 1698 (28000): Access denied for user 'vagrant'@'localhost'

No ka mea ʻaʻohe mea hoʻohana "vagrant" i MySQL, ʻaʻole ʻia mākou e komo. E hana kāua i mea hoʻohana a hoʻāʻo hou:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'vagrant'@'localhost' IDENTIFIED VIA unix_socket;
Query OK, 0 rows affected (0.00 sec)

vagrant@mysql1:~$ mysql
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 45
Server version: 10.0.38-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04
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)]> show grants;
+---------------------------------------------------------------------------------+
| Grants for vagrant@localhost                                                    |
+---------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'vagrant'@'localhost' IDENTIFIED VIA unix_socket |
+---------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Ua hiki mai!

ʻAe, pehea e pili ana i kahi hāʻawi ʻole ʻo Debian kahi i hāʻawi ʻole ʻia e ka paʻamau? E hoʻāʻo kāua Percona Server no MySQL 8 i hoʻokomo ʻia ma CentOS 7:

mysql> show variables like '%version%comment';
+-----------------+---------------------------------------------------+
| Variable_name   | Value                                   |
+-----------------+---------------------------------------------------+
| version_comment | Percona Server (GPL), Release 7, Revision 613e312 |
+-----------------+---------------------------------------------------+
1 row in set (0.01 sec)

mysql> CREATE USER 'percona'@'localhost' IDENTIFIED WITH auth_socket;
ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded

Bummer. He aha ka mea i nalowale? ʻAʻole i hoʻouka ʻia ka plugin:

mysql> pager grep socket
PAGER set to 'grep socket'
mysql> show plugins;
47 rows in set (0.00 sec)

E hoʻohui i kahi plugin i ke kaʻina hana:

mysql> nopager
PAGER set to stdout
mysql> INSTALL PLUGIN auth_socket SONAME 'auth_socket.so';
Query OK, 0 rows affected (0.00 sec)

mysql> pager grep socket; show plugins;
PAGER set to 'grep socket'
| auth_socket                     | ACTIVE | AUTHENTICATION | auth_socket.so | GPL     |
48 rows in set (0.00 sec)

I kēia manawa ua loaʻa iā mākou nā mea a pau e pono ai. E hoao hou kakou:

mysql> CREATE USER 'percona'@'localhost' IDENTIFIED WITH auth_socket;
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'percona'@'localhost';
Query OK, 0 rows affected (0.01 sec)

Hiki iā ʻoe ke komo i kēia manawa me ka hoʻohana ʻana i ka inoa inoa "percona".

[percona@ip-192-168-1-111 ~]$ whoami
percona
[percona@ip-192-168-1-111 ~]$ mysql -upercona
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 19
Server version: 8.0.16-7 Percona Server (GPL), Release 7, Revision 613e312

Copyright (c) 2009-2019 Percona LLC and/or its affiliates
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> select user, host, plugin, authentication_string from mysql.user where user ='percona';
+---------+-----------+-------------+-----------------------+
| user    | host   | plugin   | authentication_string |
+---------+-----------+-------------+-----------------------+
| percona | localhost | auth_socket |                       |
+---------+-----------+-------------+-----------------------+
1 row in set (0.00 sec)

A ua hana hou!

Nīnau: hiki anei ke komo i loko o ka ʻōnaehana ma lalo o ka log percona like, akā ma ke ʻano he mea hoʻohana ʻē aʻe?

[percona@ip-192-168-1-111 ~]$ logout
[root@ip-192-168-1-111 ~]# mysql -upercona
ERROR 1698 (28000): Access denied for user 'percona'@'localhost'

ʻAʻole, ʻaʻole holo pono ia.

hopena

He maʻalahi loa ka MySQL ma nā ʻano he nui, ʻo kekahi o ia ke ʻano hōʻoia. E like me kāu e ʻike ai mai kēia pou, hiki ke loaʻa ke komo me ka ʻole o nā huaʻōlelo, e pili ana i nā mea hoʻohana OS. Hiki ke hoʻohana ʻia kēia i kekahi mau hiʻohiʻona, a ʻo kekahi o lākou ke neʻe nei mai RDS/Aurora i MySQL maʻamau e hoʻohana ana. IAM waihona hōʻoiano ka loaʻa ʻana, akā me ka ʻole o ka ʻōlelo huna.

Source: www.habr.com

Pākuʻi i ka manaʻo hoʻopuka