1、准备编译环境。
1. yum groupinstall "Server Platform Development" "Development tools" -y
2. yum install cmake -y
2、准备mysql数据存放目录。
1. # mkdir /mnt/data
2. # groupadd -r mysql
3. # useradd -r -g mysql -s /sbin/nologin mysql
4. # id mysql
uid=497(mysql) gid=498(mysql) groups=498(mysql)
3、更改数据目录属主属组。
# chown -R mysql:mysql /mnt/data
4、解压编译在MySQL官网下载的稳定版源码包,这里使用的是5.6.23版本
# tar xvf mysql-5.6.23.tar.gz -C /usr/local/src
# cd /usr/local/src/mysql-5.6.23
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.23 \
-DMYSQL_USER=mysql \
-DMYSQL_DATADIR=/data/mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
#####-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6.23/run/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
# make && make install
5、修改安装目录的属组为mysql。
# chown -R mysql:mysql /usr/local/mysql/
6、初始化数据库。
[root@java4 mysql-5.6.23]# /usr/local/mysql-5.6.23/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql-5.6.23/
7、配置my.cnf [未开启binlog]
[root@java4 ~]# cat /etc/my.cnf
[mysqld]
socket=/data/mysql/mysql.sock
pid-file=/data/mysql/mysqld.pid
datadir=/data/mysql
basedir=/usr/local/mysql-5.6.23/
default-storage-engine = innodb
innodb_file_per_table
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'
innodb_log_file_size = 512M
max_allowed_packet = 1024M
log-error = /var/log/mysql/mysql.err
slow_query_log
long_query_time = 2
slow_query_log_file = /var/log/mysql/slow.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_connections=1000
[client]
socket=/data/mysql/mysql.sock
8、配置环境变量
[root@java4 ~]# echo "export PATH=$PATH:/usr/local/mysql-5.6.23/bin/" > /etc/profile.d/mysql.sh
[root@java4 ~]# source /etc/profile.d/mysql.sh
9、配置开机自启并启动
[root@java4 ~]# echo "/usr/bin/nohup /bin/sh /usr/local/mysql-5.6.23/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql-5.6.23/ --socket=/data/mysql/mysql.sock >> /var/log/mysql.nohup 2>&1 &" >> /etc/rc.local
[root@java4 ~]# /usr/bin/nohup /bin/sh /usr/local/mysql-5.6.23/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql-5.6.23/ --socket=/data/mysql/mysql.sock >> /var/log/mysql.nohup 2>&1 &
9.设置MySQL安全
CREATE DATABASE `xx` DEFAULT CHARACTER SET utf8 ;
mysql> grant all privileges on xx.* to 'xx'@'172.18.xx.%' identified by 'xxx';
mysql> update user set password=password('xxx') where user=root and host=localhost;
mysql> delete user from user where password='';
mysql> flush privileges;
10、导入数据
略。。。
===============
mysql的yum 安装
- [参考链接]:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
1.下载rpm 仓库包
2.yum repolist all | grep mysql
sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --enable mysql56-community
4.yum repolist enabled | grep mysql
5.sudo yum install mysql-community-server