この記事では、mysql8をredhat8システム(192.168.100.100)にインストールし、UbuntuKylinのNavicatを介してリモートで正常にアクセスします。
インストールコマンド:yum install mysql-server
1つは、mysqlファイルのパスです。
redhat8がyumを介してmysql8をインストールした後、構成ファイルは/etc/my.cnf
と呼ばれる/etc/my.cnf.d/
ディレクトリになり、mysql-server.cnf
メインの構成ファイルmysql-default-authentication-plugin.cnf
は認証ファイルになります。
mysql-server.cnf
初期パラメータ:
[root@hollowman ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
datadir=/var/lib/mysql #数据目录
socket=/var/lib/mysql/mysql.sock #socket
log-error=/var/log/mysql/mysqld.log #日志文件
pid-file=/run/mysqld/mysqld.pid #PID文件
2、mysqlの初期化
mysql8の初期インストールにはパスワードがありません。
[root@hollowman ~]# cat /var/log/mysql/mysqld.log | grep password
2021-01-24T15:42:44.955519Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
初期化を保護し、rootパスワードを設定し、セキュリティ設定を実行します
[root@hollowman ~]#mysql_secure_installation
Enter current password for root (enter for none): #输入当前 root 用户密码,安装完后默认为空,可直接回车,除非已经设置过密码。
Set root password? [Y/n] y > > #是否设置root密码?
Remove anonymous users? [Y/n] y #是否要移除掉匿名用户?
Disallow root login remotely? [Y/n] y #是否禁止root远程登陆?
Remove test database and access to it? [Y/n] y #是否删除test数据库?
Reload privilege tables now? [Y/n] y #是否重新加载权限?
空のパスワードを入力した後、パスワードを直接変更することもできます。
alter user 'root'@'localhost' identified with mysql_native_password by '密码`;
[root@hollowman mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.13 Source distribution
Copyright (c) 2000, 2018, 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> alter user 'root'@'localhost' identified with mysql_native_password by 'redhat';
Query OK, 0 rows affected (0.10 sec)
3、Navicatからアクセスできるユーザーを追加します
mysql> 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
mysql> create user 'admin'@'%' identified by 'redhat';
Query OK, 0 rows affected (0.10 sec)
mysql> grant all on *.* to 'admin'@'%';
Query OK, 0 rows affected (0.04 sec)
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | admin | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | mysql_native_password |
+-----------+------------------+-----------------------+
5 rows in set (0.01 sec)
第四に、Navicatリモート接続のエラープロンプトの解決策
Navicatはデータベースに接続し、次のエラーメッセージを表示します
。2003-「192.168.100.100」のmysql_serverに接続できません(113「ホストへのルートが見つかりませんでした」)
問題の判断:
Redhatファイアウォールが悪戯をしている。2つのredhatファイアウォール、iptables(redhat8より前のバージョン)、firewalld(redhat7以降のバージョン)があります。
iptablesはファイアウォールルールを無効にします(redhat8はデフォルトでiptablesをインストールしません):
iptables -F #因为redhat8未装iptables,此处可成功,但无意义
service iptables save #因为redhat8未安装iptables,所以此处失败,只是体验一下关闭防火墙的过程,无关紧要
ファイアウォールで保護された構成方法:
最初の方法:ファイアウォールを直接オフにします
[root@hollowman ~]# systemctl stop firewalld
[root@hollowman ~]# systemctl disabled firewalld
2番目の方法:ファイアウォールでmysqlサービスを禁止する必要があるかどうかを判断するには、mysqlサービスを追加するだけです。
[root@hollowman ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens160
sources:
services: cockpit dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@hollowman ~]# firewall-cmd --add-service=mysql --permanent --zone=public
success
[root@hollowman ~]# firewall-cmd --reload
success
[root@hollowman ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens160
sources:
services: cockpit dhcpv6-client mysql ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
Navicat接続テストのスクリーンショット: