MySQL数据库编译安装
2021-08-10 本文已影响0人
Joening
1.卸载系统环境
[root@localhost ~]# rpm -qa |grep mariadb | xargs rpm -e --nodeps
2. 安装依赖包
[root@localhost ~]# yum install -y ncurses-devel libaio-devel cmake autoconf openssl-devel
3.创建MySQL数据库管理用户
[root@localhost ~]# useradd -M -s /sbin/nologin mysql
4. 解压安装包
[root@localhost ~]# tar xf mysql-5.6.40.tar.gz
[root@localhost ~]# cd mysql-5.6.40/
5. 预配置 编译 编译安装
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.40 \
-DMYSQL_DATADIR=/usr/local/mysql-5.6.40/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6.40/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
[root@localhost ~]# make && make install
6.制作软连接
[root@localhost ~]# ln -s /usr/local/mysql-5.6.40/ /usr/local/mysql
7. 复制MySQL配置文件到/etc/目录中
[root@localhost ~]# \cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
8. 初始化数据库信息
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql
9. 创建数据库临时目录, 存放mysql.sock
[root@localhost ~]# mkdir /usr/local/mysql/tmp
10. 授权目录
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
11. 拷贝MySQL启动脚本
[root@localhost ~]# cp support-files/mysql.server /etc/init.d/mysql
12. 添加执行权限
[root@localhost ~]# chmod +x /etc/init.d/mysqld
13. 设置环境变量
[root@localhost ~]# echo 'PATH=/usr/local/mysql/bin/:$PATH' >>/etc/profile
[root@localhost ~]# tail -1 /etc/profile
[root@localhost ~]# source /etc/profile
14. 启动MySQL
[root@localhost ~]# /etc/init.d/mysqld start
15. 登录MySQL
[root@localhost tmp]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.40 Source distribution
Copyright (c) 2000, 2018, 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>
mysql>
mysql>