Mysql 5.6 源码编译安装 centos 7.5
删除原有到数据库
[[email protected] ~]#yum -y remove `rpm -qa | grep mariadb`
安装依赖包
[[email protected] ~]# yum -y install autoconf automake cmake gcc-c++ libgcrypt libtool libxml2 ncurses-devel zlib openssl openssl-devel
[[email protected] ~]#yum -y install perl-Data-Dumper python-devel zlib-devel cmake ncurses bison bison-devel
创建用户
[[email protected] ~]#useradd -M -s /sbin/nologin mysql
下载安装包
[[email protected] ~]#yum -y install wget && wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.48.tar.gz
解压到指定目录
[[email protected] ~]# tar -xf mysql-5.6.48.tar.gz
[[email protected] ~]# cd mysql-5.6.48
[[email protected] mysql-5.6.48]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_PARTITION_STORAGE_ENGINE=1
注释:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #安装路径
-DMYSQL_DATADIR=/data/mysql/data \ #数据文件存放位置
-DSYSCONFDIR=/etc \ #my.cnf路径
-DWITH_MYISAM_STORAGE_ENGINE=1 \ #支持MyIASM引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #支持InnoDB引擎
-DWITH_MEMORY_STORAGE_ENGINE=1 \ #支持Memory引擎
-DWITH_READLINE=1 \ #快捷键功能(我没用过)
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysqld.sock \ #连接数据库socket路径
-DMYSQL_TCP_PORT=3306 \ #端口
-DENABLED_LOCAL_INFILE=1 \ #允许从本地导入数据
-DWITH_PARTITION_STORAGE_ENGINE=1 \ #安装支持数据库分区
-DEXTRA_CHARSETS=all \ #安装所有的字符集
-DDEFAULT_CHARSET=utf8 \ #默认字符
-DDEFAULT_COLLATION=utf8_general_ci
[[email protected] mysql-5.6.48]# make -j `grep processor /proc/cpuinfo | wc -l` && make install
创建文件夹
[[email protected] mysql-5.6.48]# mkdir -p /data/mysql/{log,log-bin,tmp,data}
[[email protected] mysql-5.6.48]#mkdir /var/lib/mysql
[[email protected] mysql]# vim /etc/profile
插入最后
export PATH=/usr/local/mysql/bin:$PATH
[[email protected] mysql]# source /etc/profile
创建所需文件
[[email protected] mysql-5.6.48]#touch /data/mysql/log/mysql.err
改变属主和属组
[[email protected] mysql-5.6.48]#chown -R mysql:mysql /data/mysql
[[email protected] mysql-5.6.48]#chown -R mysql:mysql /var/lib/mysql
[[email protected] mysql-5.6.48]#chown -R mysql:mysql /usr/local/mysql
mysql配置
配置文件
[[email protected] mysql]# vim /etc/my.cnf
[mysqld_safe]
log-error=/data/mysql/log/mysql.err
[mysqld]
datadir=/data/mysql/data
tmpdir=/data/mysql/tmp
socket=/var/lib/mysql/mysql.sock
user=mysql
character_set_server=utf8
default-storage-engine=INNODB
innodb_buffer_pool_size=1G
slow_query_log=1
slow_query_log_file=/data/mysql/log/mysql.slow
long_query_time=2
server_id=1
log-bin=/data/mysql/log-bin/log-bin
binlog_format=row
max_connections=1000
[client]
socket=/var/lib/mysql/mysql.sock
初始化数据库
[[email protected] mysql]#cd /usr/local/mysql
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/data
制作启动脚本
[[email protected] mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql]# sed -i '46s|basedir=|basedir=/usr/local/mysql|g' /etc/init.d/mysqld
[[email protected] mysql]# sed -i '47s|datadir=|datadir=/usr/local/mysql/data|g' /etc/init.d/mysqld
将mysqld添加到服务
[[email protected] mysql]# chkconfig --add mysqld
开机自启
[[email protected] mysql]# chkconfig mysqld on
启动
[[email protected] mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
运行安全配置向导
[[email protected] mysql]#ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
[[email protected] mysql]#mysql_secure_installation
Enter current password for root (enter for none):
新安装mysql无root密码,按Enter即可
New password: 设置密码
Re-enter new password:
Password updated successfully!
Reloading privilege tables…
… Success!
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? [Y/n] 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? [Y/n] Y
… Success!
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? [Y/n] 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? [Y/n] Y
… Success!
All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up…
搭建完成
上一篇: DNS服务器搭建(基础篇)
下一篇: java之面向对象
推荐阅读
-
centos下编译安装mysql报错解决方案
-
MySQL 5.7.13 源码编译安装配置方法图文教程
-
Centos7.5安装mysql5.7.24二进制包方式部署
-
CentOS 7.x编译安装Nginx1.10.3+MySQL5.7.16+PHP5.2 5.3 5.4 5.5 5.6 7.0 7.1多版本全能环境
-
Mac系统下源码编译安装MySQL 5.7.17的教程
-
64位CentOs7源码安装mysql-5.6.35过程分享
-
CentOS 源码安装MySQL5.7
-
centos编译安装mysql 5.6及安装多个mysql实例详解
-
详解Lamp环境搭建Linux CentOS6.5编译安装mysql5.6
-
CentOS Yum编译安装MySQL 5.6