本例假设将所有安装文件下载到 /usr/app/soft 目录。
export soft_dir="/usr/app/soft"
1
# 安装编译环境cmake3(centos7)
如果环境中未安装cmake3,则需要安装,推荐安装如下。
dnf install centos-release-stream
dnf install gcc-toolset-10-gcc-c++
dnf install gcc-toolset-10-gcc-libasan-devel #如果提示已安装或者没有,就跳过,上一条可能已经安装过了。
source /opt/rh/gcc-toolset-10/enable
1
2
3
4
2
3
4
# 安装 rpcsvc-proto
最新版rpcsvc-proto下载地址 (opens new window)
cd $soft_dir
xz -d rpcsvc-proto-1.4.2.tar.xz
tar xvf rpcsvc-proto-1.4.2.tar
cd rpcsvc-proto-1.4.2
./configure
make -j4 && make install
1
2
3
4
5
6
2
3
4
5
6
# 创建 mysql 用户及组
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
1
2
2
# 编译 mysql
最新版mysql下载地址 (opens new window)
本例版本下载
本例安装到 /usr/app/mysql 目录下。
cd $soft_dir
rm -rf mysql-boost-8.0.25
tar --no-same-owner -zxvf $soft_dir/mysql-boost-8.0.25.tar.gz
cd $soft_dir/mysql-8.0.25
[ -e /usr/local/lib/libtcmalloc.so ] && { je_tc_malloc=2; EXE_LINKER="-DCMAKE_EXE_LINKER_FLAGS='-ltcmalloc'"; }
[ -e /usr/local/lib/libjemalloc.so ] && { je_tc_malloc=1; EXE_LINKER="-DCMAKE_EXE_LINKER_FLAGS='-ljemalloc'"; }
echo $EXE_LINKER
cmake -DCMAKE_INSTALL_PREFIX=/usr/app/mysql \
-DSYSCONFDIR=/usr/app/mysql/etc \
-DMYSQL_DATADIR=/usr/app/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/usr/app/mysql/mysqld.sock \
-DMYSQL_USER=mysql \
-DEXTRA_CHARSETS=all \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,utf8mb4 \
-DWITH_DEBUG=0 \
-DENABLE_DEBUG_SYNC=OFF \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLE_DOWNLOADS=1 \
-DWITH_COMMENT='string' \
-DENABLED_ASSEMBLER:BOOL=ON \
-DWITH_CLIENT_LDFLAGS:STRING=all-static \
-DWITH_MYSQLD_LDFLAGS:STRING=-all-static \
-DWITH_FAST_MUTEXES:BOOL=ON \
-DWITH_BIG_TABLES:BOOL=ON \
-DMYSQL_MAINTAINER_MODE:BOOL=OFF \
-DENABLE_PROFILING=0 \
-DWITH_SSL=system \
-DWITH_SAFEMALLOC=OFF \
-DWITH_BOOST=boost \
-DDOWNLOAD_BOOST=1 \
-DWITH_READLINE=1 \
-DFORCE_INSOURCE_BUILD=1 \
$EXE_LINKER
make -j4 && make install
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
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
# 赋 mysql 权限
chown mysql:mysql -R /usr/app/mysql
1
# 创建 mysql 日志文件
touch /usr/app/mysql/mysql.log
1
# 创建 mysql 配置文件
vi /usr/app/mysql/my.cnf
1
点击查看my.cnf样例
[mysqld]
user = mysql
port = 3306
pid-file = /usr/app/mysql/mysqld.pid
socket = /usr/app/mysql/mysqld.sock
datadir = /usr/app/mysql/data
log-error = /usr/app/mysql/mysql.log
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
lower_case_table_names = 1
skip-name-resolve
skip-external-locking
# 日志相关
slow_query_log=0 #关闭记录慢查询
#long_query_time=2 #设置慢查询时间2s
#slow_query_log_file="/usr/app/mysql/log/blg-slow.log" #慢查询日志保存路径
#log_queries_not_using_indexes = on #开启记录没有使用索引查询语句
#log_throttle_queries_not_using_indexes = 10
#expire_logs_days = 90
#min_examined_row_limit = 100
#general_log=0 #关闭记录所有sql语句
# binlog设置
#master_info_repository = TABLE
#relay_log_info_repository = TABLE
log_bin = bin.log
server-id=150
# innodb 设置
default_storage_engine = InnoDB
#innodb_open_files = 300 #限制Innodb能打开的表的数据,如果库里的表特别多的情况,请增加这个。默认是300
innodb_buffer_pool_size = 2G
#innodb_write_io_threads = 4 #默认是4
innodb_read_io_threads = 8 #默认是4
innodb_flush_log_at_trx_commit = 2
#innodb_log_buffer_size = 2M
innodb_log_file_size = 64M #默认是4M
innodb_log_files_in_group = 3
#innodb_lock_wait_timeout = 20 #默认50
#innodb_io_capacity = 4000
#innodb_io_capacity_max = 8000
# 默认参数设置
#symbolic-links=0
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
default_authentication_plugin=mysql_native_password
# MySQL读入缓冲区的大小
read_buffer_size = 8M
# MySQL的随机读缓冲区大小、MySQL的顺序读缓冲区大小
read_rnd_buffer_size = 4M
sort_buffer_size = 32M
# 连接超时时间、保持时间、最大传输数据包大小
#wait_timeout=2880000
#interactive_timeout=2880000
# 连接缓存池大小、临时表大小、临时存放位置
join_buffer_size = 16M
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
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
# 初始化 mysql 数据库
/usr/app/mysql/bin/mysqld --defaults-file=/usr/app/mysql/my.cnf --initialize --user=mysql --basedir=/usr/app/mysql --datadir=/usr/app/mysql/data --lower-case-table-names=1
#密码在日志文件最后一行中,通过以下命令查看:
vi /usr/app/mysql/mysql.log
1
2
3
2
3
# 启动并设置 mysql 为自启动服务
service mysql start
cp -f support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig mysql on
systemctl enable mysql
1
2
3
4
5
6
7
2
3
4
5
6
7
# 修改 mysql 初始化密码
cd /usr/app/mysql/bin
/usr/app/mysql/bin/mysql -u root -p'密码' #密码在/usr/app/mysql/mysql.log文件最后一行中
#修改密码:
> ALTER USER "root"@"localhost" IDENTIFIED BY "xiong";
> CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'xiong';
> grant all privileges on *.* to 'root'@'127.0.0.1';
> CREATE USER 'xiongsy'@'%' IDENTIFIED BY 'xiongsy@cqupt.edu.cn';
> grant all privileges on *.* to 'xiongsy'@'%';
# 针对数据库创建该数据库的用户并设置权限
> CREATE USER 'bs-dianli'@'%' IDENTIFIED BY 'bs-dianli';
> grant all privileges on `bs\-dianli`.* to 'bs-dianli'@'%';
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
← 安装 Nginx 安装 MongoDB →