参考文档: cn-loongson/mysql
编译环境
- 系统: Kylin Linux Advanced Server V10 (Tercel)
- CPU 架构: loongarch64
- MySQL 版本: 8.0.17
卸载系统自带的 mariadb 数据库
1 | # 查找已安装的 mariadb 组件 |
下载 MySQL 源码
从官方地址 MySQL Product Archives 下载 MySQL 源码
1
wget -P /usr/local/src/ https://cdn.mysql.com/archives/mysql-8.0/mysql-boost-8.0.17.tar.gz
安装依赖库
执行以下命令安装依赖库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17yum -y install libaio
yum -y install gcc \
gcc-c++ \
cmake \
autoconf \
automake \
zlib \
zlib-devel \
openssl \
openssl-devel \
ncurses \
ncurses-devel \
zip \
unzip \
bison \
gd \
rpcgen注意: 如果安装时提示软件版本冲突,需要先将其他的 yum 仓库源禁用,只使用 麒麟系统自带的 yum 仓库即可正常安装.
编译 MySQL
生成 Makefile 文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25cd /usr/local/src/mysql
mkdir build && cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DINSTALL_SBINDIR=sbin \
-DMYSQL_DATADIR=/var/lib/mysql \
-DSYSCONFDIR=/etc/mysql \
-DINSTALL_PLUGINDIR=lib/mysql/plugin \
-DINSTALL_MANDIR=share/man \
-DINSTALL_SHAREDIR=share \
-DINSTALL_LIBDIR=lib/mysql \
-DINSTALL_INCLUDEDIR=include/mysql \
-DINSTALL_INFODIR=share/info \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_SSL=system \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=../boost/boost_1_69_0/ \
-DWITH_DEBUG=0说明: 取消了配置选项 “-DWITH_ZLIB=system”。如果配置此选项则表明mysql会使用系统所提供的openssl zlib库,但有些系统会存在问题(Linux version 3.10.84-22.fc21.loongson.7.mips64el,提示无法找到zlib库)。删除此选项后,mysql会对其自带的zlib_decompress进行编译使用,可以避免操作系统的影响。
编译 MySQL
1
make -j 4
安装 MySQL
1
make install
配置 MySQL
创建 MySQL 用户以及相关目录
1
2
3
4
5
6
7
8# 创建 mysql 用户
useradd -s /sbin/nologin -M mysql
# 创建 mysql 数据目录以及日志目录
mkdir -p /var/lib/mysql /var/log/mysql /data/mysql
# 修改 mysql 相关目录权限
chown -R mysql:mysql /usr/local/mysql /var/log/mysql /var/lib/mysql /data/mysql创建 mysql 配置文件 /etc/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[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysql]
prompt="MySQL [\\d]> "
no-auto-rehash
default-character-set=utf8
[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 = /var/lib/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
back_log = 300
max_connections = 2000
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 = /var/log/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初始化数据库
1
2
3
4
5
6/usr/local/mysql/sbin/mysqld \
--user=mysql \
--lower_case_table_names=1 \
--initialize-insecure \
--basedir=/usr/local/mysql \
--datadir=/data/mysql安装加密算法
1
/usr/local/mysql/bin/mysql_ssl_rsa_setup
注册数据库服务
1
2
3cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/sbin/chkconfig mysqld on启动 MySQL
1
systemctl start mysqld
设置数据库安全初始化,
默认 root 用户密码为空
1
mysql_secure_installation
测试登录数据库
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# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 23
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 [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
MySQL [(none)]>创建数据库并授权
1
2
3
4
5
6
7
8
9
10
11MySQL [(none)]> create database nacos_config character set utf8mb4 collate utf8mb4_general_ci;
Query OK, 1 row affected (0.00 sec)
MySQL [(none)]> create user 'nacos'@'%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
MySQL [(none)]> grant all privileges on nacos_config.* to 'nacos'@'%';
Query OK, 0 rows affected (0.01 sec)
MySQL [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)