Me pehea te whakamahi i te MySQL me te kore he Kupuhipa (me nga raruraru Haumarutanga)

Me pehea te whakamahi i te MySQL me te kore he Kupuhipa (me nga raruraru Haumarutanga)

E ai ki a ratou ko te kupuhipa pai rawa atu ko te mea kaore koe e mahara. I roto i te take o MySQL ka taea tenei whakawhetai ki te mono mana_tupapa me tana putanga mo MariaDB - unix_kawe.

Ko enei mono e rua ehara i te mea hou; he maha nga korero mo ratou i roto i tenei blog kotahi, hei tauira i roto i te tuhinga mo me pehea te huri i nga kupuhipa i MySQL 5.7 ma te whakamahi i te mono auth_socket. Heoi, i a au e titiro ana ki nga mea hou i roto i te MariaDB 10.4, i kitea e au ko te unix_socket kua whakauruhia inaianei ma te taunoa me tetahi o nga tikanga motuhēhēnga (“tetahi o”, no te mea kei roto i te MariaDB 10.4 neke atu i te kotahi mono kei te waatea ki te kaiwhakamahi kotahi mo te whakamotuhēhēnga, e kua whakamaramatia i roto i te tuhinga "Motuhēhēnga" mai i te MariaDB 10.04).

Ka rite ki taku korero, ehara tenei i te korero, a, i te wa e whakauru ana i a MySQL ma te whakamahi i nga kohinga .deb e tautokohia ana e te roopu Debian, ka hangaia he kaiwhakamahi pakiaka mo te motuhēhēnga turanga. He pono tenei mo MySQL 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>>

Ma nga kohinga Debian mo MySQL, ka whakamanahia te kaiwhakamahi pakiaka e whai ake nei:

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)

He pera ano te keehi mo te kete .deb mo 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)

Ko nga kohinga .deb mai i te putunga mana o Percona ka whirihora ano i te motuhēhēnga kaiwhakamahi pakiaka i raro i te turanga-motuhake me te Percona Server. Kia hoatu he tauira ki Tūmau Percona mo MySQL 8.0.16-7 me te 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)

Na he aha te makutu? Ka tirohia e te mono kei te taurite te kaiwhakamahi Linux ki te kaiwhakamahi MySQL ma te whakamahi i te whiringa turanga SO_PEERCRED hei kohikohi korero mo te kaiwhakamahi e whakahaere ana i te kaupapa kiritaki. No reira, ka taea anake te whakamahi i te mono ki nga punaha e tautoko ana i te whiringa SO_PEERCRED, penei i a Linux. Ko te kōwhiringa turanga SO_PEERCRED ka taea e koe te kimi i te uid o te tukanga e pa ana ki te turanga. Na ka whiwhi ia i te ingoa kaiwhakamahi e hono ana ki tenei uid.

Anei tetahi tauira me te kaiwhakamahi "vagrant":

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

I te mea karekau he "kaiwhakamahi" i MySQL, karekau matou e uru. Me hanga he kaiwhakamahi penei ka ngana ano:

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)

Kua tupu!

Ae, me pehea te tohatoha kore-Debian kaore i te whakaratohia ma te taunoa? Me whakamatau te Percona Server mo MySQL 8 i whakauruhia ki 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

Karekau. He aha te mea i ngaro? Kaore i utaina te mono:

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

Me taapiri he mono ki te tukanga:

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)

Inaianei kei a matou nga mea katoa e hiahia ana matou. Kia ngana ano tatou:

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)

Ka taea e koe te takiuru ma te whakamahi i te ingoa ingoa "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)

Na ka mahi ano!

Patai: ka taea te whakauru ki te punaha i raro i te urunga percona kotahi, engari he kaiwhakamahi rereke?

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

Kao, kare e mahi.

mutunga

He tino ngawari a MySQL i roto i nga waahanga maha, ko tetahi ko te tikanga motuhēhēnga. Ka taea e koe te kite mai i tenei pou, ka taea te uru me te kore kupuhipa, i runga i nga kaiwhakamahi OS. Ka whai hua tenei ki etahi ahuatanga, a ko tetahi o enei ko te heke mai i te RDS/Aurora ki te whakamahi i a MySQL. Motuhēhēnga pātengi raraunga IAMkia whai waahi tonu, engari kaore he kupuhipa.

Source: will.com

Tāpiri i te kōrero