注意,在做实验室统一关闭防火墙做的,在生产环境需要做防火墙规则的,大家要注意,做的时候尽量都是模仿生产环境的,比如服务一般都在/data/soft下面,尽量避免在/usr/local/下面。
安装编译mysql所需要的软件
[root@localhost soft]# yum -y install gcc gcc-c++ ncurses-devel perl
[root@localhost soft]# wget https://cmake.org/files/v3.11/cmake-3.11.1.tar.gz
[root@localhost soft]# tar -xvf cmake-3.11.1.tar.gz
[root@localhost soft]# cd cmake-3.11.1/
[root@localhost cmake-3.11.1]# ./bootstrap && make && make install
创建mysql用户,安装目录和数据目录
[root@localhost soft]# groupadd mysql
[root@localhost soft]# useradd -r -g mysql mysql
[root@localhost soft]# mkdir /data/soft/mysql
[root@localhost soft]# mkdir /data/mysqldb
下载mysql5.6的源码,注意有些版本下过来编译会出现不兼容的情况,需要选择cmake能够兼容的mysql版本。
[root@localhost soft]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16.tar.gz
[root@localhost soft]# tar -xvf mysql-5.6.16.tar.gz
[root@localhost soft]# cd mysql-5.6.16/
编译安装
[root@localhost mysql-5.6.16]# cmake -DCMAKE_INSTALL_PREFIX=/data/soft/mysql -DMYSQL_UNIX_ADDR=/data/soft/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1
[root@localhost mysql-5.6.16]# rm -rf CMakeCache.txt
[root@localhost mysql-5.6.16]# make && make install
修改mysql目录所有者和组
[root@localhost soft]# chown -R mysql:mysql /data/mysqldb/
[root@localhost soft]# chown -R mysql:mysql /data/soft/mysql/
初始化数据目录
[root@localhost mysql-5.6.16]# cd /data/soft/mysql
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb
注意:此处出现问题了
# scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb
Can't locate Data/Dumper.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at scripts/mysql_install_db line 42.
BEGIN failed--compilation aborted at scripts/mysql_install_db line 42.
解决办法为
yum -y install 'perl(Data::Dumper)'
修改mysql配置文件
[root@localhost mysql]# cp /data/soft/mysql/support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
文件修改如下
[root@localhost mysql]# vim /etc/my.cnf 修改下面四行内容
basedir = /data/soft/mysql
datadir = /data/mysqldb
port = 3306
server_id = 1
加入path路径
[root@localhost mysql]# vim /etc/profile
PATH=/data/soft/mysql/bin:/data/soft/mysql/lib:$PATH
export PATH
执行变量,让设置的路径生效
[root@localhost mysql]# source /etc/profile
加入系统服务中
[root@localhost mysql]# chkconfig mysqld on
启动数据库
[root@localhost mysql]# systemctl start mysqld
查看是否启动完成
[root@localhost mysql]# ps -ef |grep mysqld
root 49740 1 0 19:58 ? 00:00:00 /bin/sh /data/soft/mysql/bin/mysqld_safe --datadir=/data/mysqldb --pid-file=/data/mysqldb/localhost.localdomain.pid
mysql 49908 49740 15 19:59 ? 00:00:01 /data/soft/mysql/bin/mysqld --basedir=/data/soft/mysql --datadir=/data/mysqldb --plugin-dir=/data/soft/mysql/lib/plugin --user=mysql --log-error=/data/mysqldb/localhost.localdomain.err --pid-file=/data/mysqldb/localhost.localdomain.pid --port=3306
root 49936 4132 0 19:59 pts/1 00:00:00 grep --color=auto mysqld
登录mysql并修改初次登陆密码
[root@localhost mysql]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.16 Source distribution
Copyright (c) 2000, 2014, 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> set password = password('m2i3sc');
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
授权远程主机能够登陆mysql
mysql> create user nsh identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'nsh'@'%' identified by '123456' with grant option;
Query OK, 0 rows affected (0.07 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
在本地用navicat测试连接情况,说明授权登陆成功。
好了,这是简单安装mysql5.6的版本,做出来比较简化,我看网上很多都是yum直接搞定,但是在生产环境我不建议这样做,后期维护非常麻烦,大量的数据在/(根)下,生产环境是直接挂在一块容量很大的硬盘上,所有数据都在这上面,这样减轻了服务器的压力,同时也方便维护,希望大家能够理解。