MySQL 8.0 安装
检查系统自带的 mariadb 并卸载
1
2rpm -qa |grep mariadb
rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps从 MySQL 官网下载指定版本的 MySQL 安装包,这里下载的是
mysql-8.0.29-1.el8.aarch64.rpm-bundle.tar
.- MySQL 历史版本下载地址: MySQL Product Archives
解压安装包
1
2mkdir packages
tar xf mysql-8.0.29-1.el8.aarch64.rpm-bundle.tar -C packages/安装 MySQL,应当按照 common–>libs–>client–>server 的顺序安装,否则安装过程会提醒依赖顺序,其他的为非必须安装包。
1
2
3
4
5
6
7
8cd packages
rpm -ivh \
mysql-community-common-8.0.29-1.el8.aarch64.rpm \
mysql-community-libs-8.0.29-1.el8.aarch64.rpm \
mysql-community-client-plugins-8.0.29-1.el8.aarch64.rpm \
mysql-community-client-8.0.29-1.el8.aarch64.rpm \
mysql-community-icu-data-files-8.0.29-1.el8.aarch64.rpm \
mysql-community-server-8.0.29-1.el8.aarch64.rpm创建 MySQL 配置文件 my.cnf,内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set = utf8mb4
[mysql]
prompt="MySQL [\\d]> "
no-auto-rehash
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
default_authentication_plugin = mysql_native_password
# 设置数据库不区分大小写
lower_case_table_names = 1
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
collation-server = utf8mb4_0900_ai_ci
skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 500M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
binlog_expire_logs_seconds = 604800
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
skip-external-locking
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 500M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M创建数据库数据存放目录 /data/mysql
1
2mkdir /data/mysql -p
chown -R mysql:mysql /data/mysql初始化数据库,注意,由于这里配置文件中加入了不区分大小写的配置,所以 MySQL 初始化时需要添加
--lower_case_table_names=1
参数;1
mysqld --user=mysql --lower_case_table_names=1 --initialize-insecure --basedir=/var/lib/mysql --datadir=/data/mysql
启动 MySQL,并配置开机启动
1
systemctl enable --now mysqld
执行以下命令,对数据库进行安全性设置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67# mysql_secure_installation
mysql_secure_installation: [ERROR] unknown variable 'default-character-set=utf8mb4'.
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: 1
Please set the password for root here.
New password:
Re-enter new password:
Estimated strength of the password: 100
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.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
... skipping.
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.
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 now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
数据库用户权限配置
创建数据库,使用 utf8mb4 字符集
1
2MySQL [(none)]> create database nacos_config character set utf8mb4 collate utf8mb4_general_ci;
Query OK, 1 row affected (0.01 sec)创建用户 nacos,并授权对 nacos_config 数据库拥有所有权限
1
2
3
4
5
6
7
8MySQL [(none)]> create user 'nacos'@'%' identified by '123456'
Query OK, 0 rows affected (0.00 sec)
MySQL [(none)]> grant all privileges on nacos_config.* to 'nacos'@'%';
Query OK, 0 rows affected (0.00 sec)
MySQL [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)