1) 安装MySQL 8.0
[root@node1 ~]# yum install yum-plugin-priorities centos-release-scl-rh centos-release-scl -y
[root@node1 ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
[root@node1 ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
[root@node1 ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
[root@node1 ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
[root@node1 ~]# yum --enablerepo=centos-sclo-rh install rh-mysql80-mysql-server -y
[root@node1 ~]# vim /etc/opt/rh/rh-mysql80/my.cnf.d/mysql-server.cnf
# 于[mysqld]最尾部追加如下内容:
character-set-server=utf8mb4
[root@node1 ~]# systemctl enable --now rh-mysql80-mysqld
2) 加载Mysql 8.0的shell环境
[root@node1 ~]# scl enable rh-mysql80 bash
[root@node1 ~]# mysql -V
mysql Ver 8.0.17 for Linux on x86_64 (Source distribution)
[root@node1 ~]# vim /etc/profile.d/rh-mysql80.sh
source /opt/rh/rh-mysql80/enable
export X_SCLS="`scl enable rh-mysql80 'echo $X_SCLS'`"
3) 初始化MySQL 8.0
[root@node1 ~]# mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
# 是否启用密码验证策略
Press y|Y for Yes, any other key for No: y
# 选择密码验证策略
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
# 设置MySQL的密码
New password:
Re-enter new password:
# 验证你所输入的密码
Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
# 移除匿名账户
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
# 禁止root远程登录
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
# 移除test数据库
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
# reload privilege tables
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
4) 测试MySQL
[root@node1 ~]# mysql -u root -p
Enter password: # 输入密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.17 Source distribution
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 from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.01 sec)
# 显示数据库列表
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
# 创建一个test_database数据库
mysql> create database test_database;
Query OK, 1 row affected (0.11 sec)
# 在test_database数据库创建一个test表
mysql> create table test_database.test_table (id int, name varchar(50), address varchar(50), primary key (id));
Query OK, 0 rows affected (0.42 sec)
# 对test表插入一个数据
mysql> insert into test_database.test_table(id, name, address) values("001", "CentOS", "BeiJing");
Query OK, 1 row affected (0.04 sec)
# 查看表
mysql> select * from test_database.test_table;
+----+--------+---------+
| id | name | address |
+----+--------+---------+
| 1 | CentOS | BeiJing |
+----+--------+---------+
1 row in set (0.00 sec)
# 删除数据库
mysql> drop database test_database;
Query OK, 1 row affected (0.27 sec)
mysql> exit
Bye
[root@node1 ~]#
5) 防火墙规则设定
[root@node1 ~]# firewall-cmd --add-service=mysql --permanent
success
[root@node1 ~]# firewall-cmd --reload
success
|