Centos 7 MySQL 5.7 编译安装
一、前言
没什么干货只是记录下给开发同学学习安装mysql
1.1、下载地址
- 不同版本安装有少许小差别
# mysql 5.5下载地址
http://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.5/mysql-5.5.62.tar.gz
# mysql 5.6下载地址
http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.50.tar.gz
# mysql 5.7下载地址
http://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.33.tar.gz
1.2、安装依赖包
yum install -y gcc gcc-c++ cmake ncurses ncurses-devel bison wget openssl-devel net-tools vim
二、安装 MySQL 5.7
2.1、下载 Mysql 源码与 Boost 库并解压
# mysql 5.7下载地址
wget http://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.33.tar.gz
# 解压并进入到解压目录
tar xvf mysql-5.7.33.tar.gz && cd mysql-5.7.33
# 下载 Boost 库
wget http://mirrors.linuxeye.com/oneinstack/src/boost_1_59_0.tar.gz
# 解压
tar xvf boost_1_59_0.tar.gz
2.2、编译安装
- 从MySQL 5.7.5 开始 Boost 库是必需的
名称 | 值 | 描述 |
---|---|---|
-DCMAKE_INSTALL_PREFIX | /usr/local/mysql | 安装路径 |
-DMYSQL_DATADIR | /mysql/data | Mysql 数据目录 |
-DDOWNLOAD_BOOST | 1 | |
-DWITH_BOOST | boost_1_59_0 | 写刚刚下载并解压的 boost 库目录路径 |
-DSYSCONFDIR= | /etc | my.cnf 系统配置目录 |
-DWITH_INNOBASE_STORAGE_ENGINE | 1 | 安装 innodb 存储引擎 |
-DWITH_PARTITION_STORAGE_ENGINE | 1 | 安装数据库分区 |
-DWITH_FEDERATED_STORAGE_ENGINE | 1 | |
-DWITH_BLACKHOLE_STORAGE_ENGINE | 1 | 安装 blackhole 存储引擎 |
-DWITH_MYISAM_STORAGE_ENGINE | 1 | 安装 myisam 存储引擎 |
-DWITH_EMBEDDED_SERVER | 1 | |
-DENABLE_DTRACE | 0 | |
-DENABLED_LOCAL_INFILE | 1 | 允许从本地导入数据 |
-DDEFAULT_CHARSET | utf8 | 使用 utf8 字符 |
-DDEFAULT_COLLATION | utf8_general_ci | 校验字符 |
-DEXTRA_CHARSETS | all | 安装所有扩展字符集 |
# 获取当前机器处理器核心数量,然后编译时候更具核心数量编译增加编译速度
THREAD=`cat /proc/cpuinfo| grep "processor"| wc -l`
# 这里是在 Mysql 目录中执行
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=boost_1_59_0 \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DTRACE=0 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all
# 编译并安装
make -j ${THREAD} && make install
2.3、创建配置文件
# 下面内容复制黏贴即可
cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt="MySQL [\\d]> "
no-auto-rehash
[mysqld]
port = 3306
socket = /tmp/mysql.sock
# 跳过mysql密码
skip-grant-tables
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8'
character-set-server = utf8
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
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 7
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
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
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
EOF
2.4、设置 MySQL 安装目录权限
# 创建 MySQL 专用用户
useradd -M -s /sbin/nologin mysql
# 创建数据目录
mkdir -p /data/mysql
# 赋予 MySQL 安装目录权限
chown -R mysql:mysql /usr/local/mysql
# 赋予 MySQL 数据目录权限
chown -R mysql:mysql /data/mysql
# 赋予 my.cnf 权限
chmod 600 /etc/my.cnf
# 复制启动脚本,这里是在mysql解压目录中执行
cp support-files/mysql.server /etc/init.d/mysqld
# 赋予启动脚本权限
chmod +x /etc/init.d/mysqld
2.5、拷贝启动脚本
# 复制启动脚本,这里是在mysql解压目录中执行
cp support-files/mysql.server /etc/init.d/mysqld
# 赋予启动脚本权限
chmod +x /etc/init.d/mysqld
# 配置启动脚本 basedir 指向安装目录
sed -i s#basedir=#basedir=/usr/local/mysql#g /etc/init.d/mysqld
# 配置启动脚本 datadir 指向数据目录
sed -i s#datadir=#datadir=/data/mysql#g /etc/init.d/mysqld
2.6、添加系统环境变量
# 增加 mysql 系统变量
echo "export PATH=${mysql_install_dir}/bin:\$PATH" >> /etc/profile
# 刷新系统变量
source /etc/profile
2.7、初始化数据库
# 执行这一步必须确保 /data/mysql 目录是空的
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
# 上面执行成功后 /data/mysql 就有了初始化数据
[root@aka ~]# ls -l /data/mysql/
total 110676
-rw-r-----. 1 mysql mysql 56 Mar 20 15:36 auto.cnf
-rw-------. 1 mysql mysql 1680 Mar 20 15:36 ca-key.pem
-rw-r--r--. 1 mysql mysql 1112 Mar 20 15:36 ca.pem
-rw-r--r--. 1 mysql mysql 1112 Mar 20 15:36 client-cert.pem
-rw-------. 1 mysql mysql 1676 Mar 20 15:36 client-key.pem
-rw-r-----. 1 mysql mysql 436 Mar 20 15:36 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 Mar 20 15:36 ibdata1
-rw-r-----. 1 mysql mysql 33554432 Mar 20 15:36 ib_logfile0
-rw-r-----. 1 mysql mysql 33554432 Mar 20 15:36 ib_logfile1
-rw-r-----. 1 mysql mysql 33554432 Mar 20 15:36 ib_logfile2
drwxr-x---. 2 mysql mysql 4096 Mar 20 15:36 mysql
-rw-r-----. 1 mysql mysql 177 Mar 20 15:36 mysql-bin.000001
-rw-r-----. 1 mysql mysql 19 Mar 20 15:36 mysql-bin.index
-rw-r-----. 1 mysql mysql 741 Mar 20 15:36 mysql-error.log
-rw-r-----. 1 mysql mysql 154 Mar 20 15:36 mysql-slow.log
drwxr-x---. 2 mysql mysql 8192 Mar 20 15:36 performance_schema
-rw-------. 1 mysql mysql 1676 Mar 20 15:36 private_key.pem
-rw-r--r--. 1 mysql mysql 452 Mar 20 15:36 public_key.pem
-rw-r--r--. 1 mysql mysql 1112 Mar 20 15:36 server-cert.pem
-rw-------. 1 mysql mysql 1676 Mar 20 15:36 server-key.pem
drwxr-x---. 2 mysql mysql 8192 Mar 20 15:36 sys
2.9、启动数据库并设置开机启动
# 启动数据库
service mysqld start
# 设置开机启动
systemctl enable mysqld
2.10、查看数据临时密码
# 临时密码为 : <cjq6V3KCuk/
[root@aka]# cat /data/mysql/mysql-error.log | grep "root@localhost:"
2021-03-20T08:15:55.354087Z 1 [Note] A temporary password is generated for root@localhost: <cjq6V3KCuk/
2.11、登录数据库
- 输入刚才获取到的临时密码 <cjq6V3KCuk/
[root@aka ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.33-log
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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)]>
2.12、修改Root密码
- 输入刚才获取到的临时密码 <cjq6V3KCuk/
# 这里必须是进入 mysql 命令交互才可以操作
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
# 刷新授权表
flush privileges;
版权声明:
作者:Akiraka
链接:https://www.akiraka.net/linux/1062.html
来源:Akiraka
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
海报
Centos 7 MySQL 5.7 编译安装
一、前言
没什么干货只是记录下给开发同学学习安装mysql
1.1、下载地址
不同版本安装有少许小差别
# mysql 5.5下载地址
http://mirrors.tuna.tsinghua.edu.……
文章目录
关闭
共有 0 条评论