企业版本的MySQL不一样于社区版本的MySQL。多了许多恶心人的安全机制。固然也更安全。node
首先密码只能用强密码。弱密码是不被容许的。python
其次若是默认使用3306端口只能本机登录,想远程登录必须修改端口。mysql
第三会默认使用SELinux的安全标签机制。不被容许的文件和目录是不能被数据库接受的。sql
首先安装:安装只有进度条,也不知道文件都丢哪去了,反正散落在系统的各个妥善的地方。彷佛安装Linux的文件规则就应该这样。按照配置文件应该能够找到所有文件。主要我对MySQL也不熟。没细找。数据库
[infa@infatest infa_install]$ ll安全
-rwxrw-rw-. 1 infa oracle12 45128772 Feb 4 18:24 mysql-commercial-client-5.7.28-1.1.el7.x86_64.rpmsession
-rwxrw-rw-. 1 infa oracle12 324248 Feb 4 18:22 mysql-commercial-common-5.7.28-1.1.el7.x86_64.rpmoracle
-rwxrw-rw-. 1 infa oracle12 4380008 Feb 4 18:24 mysql-commercial-libs-5.7.28-1.1.el7.x86_64.rpmtcp
-rwxrw-rw-. 1 infa oracle12 245478672 Feb 4 18:27 mysql-commercial-server-5.7.28-1.1.el7.x86_64.rpmide
上传这四个文件。其他不知道作什么的。
卸载低版本的mariadb-libs
[root@mysql infa_install]# rpm -e mariadb-libs-* --nodeps
开始依次按照:注意!按顺序!!!注意!按顺序!!!注意!按顺序!!!
[root@infatest infa_install]# rpm -ivh mysql-commercial-common-5.7.28-1.1.el7.x86_64.rpm
warning: mysql-commercial-common-5.7.28-1.1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-commercial-common-5.7.28-1.################################# [100%]
[root@infatest infa_install]# rpm -ivh mysql-commercial-libs-5.7.28-1.1.el7.x86_64.rpm
warning: mysql-commercial-libs-5.7.28-1.1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-commercial-libs-5.7.28-1.1.################################# [100%]
[root@infatest infa_install]# rpm -ivh mysql-commercial-client-5.7.28-1.1.el7.x86_64.rpm
warning: mysql-commercial-client-5.7.28-1.1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-commercial-client-5.7.28-1.################################# [100%]
[root@infatest infa_install]# rpm -ivh mysql-commercial-server-5.7.28-1.1.el7.x86_64.rpm
warning: mysql-commercial-server-5.7.28-1.1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-commercial-server-5.7.28-1.################################# [100%]
中间报缺什么本身yum吧。我是没报。系统是:CentOS Linux release 7.5.1804 (Core)
重启系统(我估计这步不必。直接执行那个初始化命令而后启动服务就行。可是我没试反正是本地虚拟机,重启就重启了)
社区版的初始化命令【mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data】须要制定两个目录。在 /etc/my.cnf 配置文件里有这俩目录。没有就只能本身找了。哈哈……
[root@mysql infa]# netstat -antp|grep 33
tcp6 0 0 :::3306 :::* LISTEN 1902/mysqld
MySQL端口已经启动
[root@mysql infa]# grep 'password' /var/log/mysqld.log
2020-02-05T03:03:06.785067Z 1 [Note] A temporary password is generated for root@localhost: SlPxe%guv5fA
找到初始密码
而后启动MySQL
[root@mysql infa]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28-enterprise-commercial-advanced
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> alter user 'root'@'localhost' identified by '一个强密码';
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> select user,host from mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
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> update user set host='%' where user='root' limit 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
设置ROOT能够远程登录,这步可选。
mysql> select user,host from mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
mysql> exit
Bye
[root@infatest infa]#
完成安装
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
创建存放binlog的文件夹。而后受权。
MySQL5.7版本中(5.6如下不须要),my.cnf 的位置通常在/etc/my.cnf,要在my.cnf中添加server-id:
[mysqld]
server-id = [序列号]
log-bin =[路径] [文件名前缀]
例子1:
[mysqld]
log-bin=/mysqlbin-log/mysqlbinlog
server-id=11
例子2:
log-bin=mysqlbinlog
server-id=11
[root@mysql /]#mkdir /mysqlbin-log
[root@mysql /]#chown -R mysql:mysql /mysqlbin-log
[root@mysql /]# chmod -R 775 /mysqlbin-log
按理说编辑完/etc/my.cnf。启动就OK了。
可是我遇到了SELinux权限错误。
刚开始我看了启动日志。
[root@mysql log]# cat mysqld.log
关键行:
mysqld: File '/mysqlbin-log/mysql-bin.index' not found (Errcode: 13 - Permission denied)
什么鬼没权限我去。
[root@mysql mysqlbin-log]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
仍是先看启动错误提示的俩东西吧。
[root@mysql mysqlbin-log]# systemctl status mysqld.service
关键行:
Feb 24 13:55:24 mysql.cdc.test systemd[1]: mysqld.service failed.
这里没啥玩意。看不出什么问题。
[root@mysql mysqlbin-log]# journalctl -xe
关键行:
Feb 24 12:58:54 mysql.cdc.test python[12374]: SELinux is preventing /usr/sbin/mysqld from write access on the directory mysqlbin-log.
***** Plugin catchall_labels (83.8 confidence) suggests *******************
If you want to allow mysqld to have write access on the mysqlbin-log directory
Then you need to change the label on mysqlbin-log
Do
# semanage fcontext -a -t FILE_TYPE 'mysqlbin-log'
where FILE_TYPE is one of the following: faillog_t, krb5_host_rcache_t, mysqld_db_t, mysqld_log_t, mysqld_tmp_t, mysqld_var_run_t, tm
Then execute:
restorecon -v 'mysqlbin-log'
***** Plugin catchall (17.1 confidence) suggests **************************
If you believe that mysqld should be allowed write access on the mysqlbin-log directory by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'mysqld' --raw | audit2allow -M my-mysqld
# semodule -i my-mysqld.pp
提示还挺舒适呢。内含完整的解决方案。
查询了semanage命令
SELinux semanage命令
semanage命令是用来查询与修改SELinux默认目录的安全上下文。SELinux的策略与规则管理相关命令:seinfo命令、sesearch命令、getsebool命令、setsebool命令、semanage命令。
semanage {login|user|port|interface|fcontext|translation} -l
semanage fcontext -{a|d|m} [-frst] file_spec
选项
-l:查询。
fcontext:主要用在安全上下文方面。
-a:增长,你能够增长一些目录的默认安全上下文类型设置。
-m:修改。
-d:删除。
[root@mysql mysqlbin-log]# semanage fcontext -l|grep mysql
关键行:
/var/log/mariadb(/.*)? all files system_u:object_r:mysqld_log_t:s0
模仿这个写一个试试吧。
[root@mysql mysqlbin-log]# semanage fcontext -a -t mysqld_log_t "/mysqlbin-log(/.*)?"
[root@mysql mysqlbin-log]# restorecon -v 'mysqlbin-log'
[root@mysql mysqlbin-log]# semanage fcontext -l|grep mysql
关键行:
/mysqlbin-log(/.*)? all files system_u:object_r:mysqld_log_t:s0
设置好后重启MySQL
[root@ mysql mysqlbin-log]# service mysqld restart
或启动MySQL
[root@ mysql mysqlbin-log]# service mysqld start
[root@ mysql mysqlbin-log]# netstat -antp|grep 3306
tcp6 0 0 :::33060 :::* LISTEN 17868/mysqld
[root@mysql /]# ll -Z
关键行:
drwxrwxr-x. mysql mysql unconfined_u:object_r:mysqld_log_t:s0 mysqlbin-log
[root@mysql mysqlbin-log]# ll
-rw-r-----. 1 mysql mysql 177 Feb 24 13:49 mysqlbinlog.000001
-rw-r-----. 1 mysql mysql 66 Feb 24 14:12 mysqlbinlog.index
文件也被创建了。
[root@mysql mysqlbinlog]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial)
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> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | ON |
+---------------+-------+
1 row in set (0.01 sec)
Log-bin开启完成!