• 一、源码安装mysql5.6-单实例

1、  安装前检查系统环境

1.1 操作系统版本及内核版本

[root@mysql ~]# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 6.5 (Santiago)

[root@mysql ~]# uname –r

2.6.32-431.el6.x86_64

1.2 selinux是否处于关闭状态

[root@mysql ~]# getenforce

Enforcing

[root@mysql ~]# vim /etc/sysconfig/selinux

SELINUX=disabled

[root@mysql ~]# reboot

1.3 检查防火墙

[root@mysql ~]# iptables -L

1.4 检查IP地址

[root@mysql ~]# ip a 或者

[root@mysql ~]# ifconfig

1.5 检查主机名

[root@mysql ~]# hostname

[root@mysql ~]# cat /etc/sysconfig/network

1.6  检查hosts

[root@mysql ~]# cat /etc/hosts

[root@mysql ~]# vim /etc/hosts

192.168.128.2 mysql

[root@mysql ~]# ping localhost 解析成127.0.0.1

[root@mysql ~]# ping mysql 解析成网卡的IP地址

1.7 检查yum源配置

[root@mysql yum.repos.d]# cat dvd.repo

[base]

name=base

baseurl=file:///media

enable=1

gpgcheck=0

[root@mysql yum.repos.d]#

[root@mysql ~]# yum repolist

 

2、  准备上传软件包

[root@mysql ~]# mkdir /disk

使用xftp上传cmakemysql软件包

[root@mysql disk]# ls

cmake-3.0.1.tar.gz  mysql-5.6.16.tar.gz

 

3、  安装cmake软件

3.1 安装编译软件环境

[root@mysql ~]# yum -y install gcc-c++ ncurses-devel makeperl bison ncurses

3.2 解压软件包

[root@mysql disk]# tar zxf cmake-3.0.1.tar.gz

3.3 编译安装

[root@mysql disk]# cd cmake-3.0.1

[root@mysql cmake-3.0.1]# ./bootstrap

[root@mysql cmake-3.0.1]# gmake

[root@mysql cmake-3.0.1]# make install

3.4 校验安装是否成功

[root@mysql ~]# cmake --version


4、  安装mysql

4.1 创建mysql用户、用户组

[root@mysql~]# useradd -r mysql -s '/sbin/nologin' –M  //-r创建系统用户,-M不创建home目录

4.2 创建mysql安装目录

[root@mysql ~]# mkdir /usr/local/mysql

4.3 创建mysql数据目录

[root@mysql ~]# mkdir -p /home/mysql/data

4.4 改变mysql安装目录及数据目录属主为mysql

[root@mysql ~]# chown -R mysql.mysql /usr/local/mysql/

[root@mysql ~]# chown -R mysql.mysql /home/mysql/data/

[root@mysql ~]# ls -ld /home/mysql/data/

drwxr-xr-x 2 mysql mysql 4096 Nov  5 18:10 /home/mysql/data/

[root@mysql ~]# ls -ld /usr/local/mysql/

drwxr-xr-x 2 mysql mysql 4096 Nov  5 18:08 /usr/local/mysql/

4.5 解压编译mysql

[root@mysql ~]# cd /disk/

[root@mysql disk]# tar -zxf mysql-5.6.16.tar.gz

[root@mysql disk]# cd mysql-5.6.16

[root@mysql mysql-5.6.16]# cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/home/mysql/data \

-DSYSCONFDIR=/etc \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysqld.sock \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \


\换行符

# /*  以下为配置参数注解   */ 

# /*  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql\   # 指定mysql安装位置 

# /*  -DMYSQL_DATADIR=/home/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=/usr/local/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 \    # 指定服务器默认的校对规则,默认latin1_general_ci 

# /*  -DWITH_xxx_STORAGE_ENGINE \            # 指定静态编译到mysql的存储引擎,MyISAMMERGEMEMORY以及CSV四种引擎默认即被编译至服务器,不需要特别指定[1.代表编译

# /*  -DWITHOUT_xxx_STORAGE_ENGINE      # 指定不编译的存储引擎

# /*  -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk  

关于参数的解释可以参考

http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

最后编译安装

[root@mysql mysql-5.6.16]# make && make install


5、  初始配置数据库

[root@mysql ~]# vim /etc/my.cnf

[client] 

socket = /usr/local/mysql/mysqld.sock 

port = 3306 

 

[mysqld] 

basedir =/usr/local/mysql 

datadir =/home/mysql/data 

socket = /usr/local/mysql/mysqld.sock 

port =3306 

server_id =100 

user = mysql 

join_buffer_size = 128M 

sort_buffer_size = 2M 

read_rnd_buffer_size = 2M 

default_storage_engine = InnoDB

join_buffer_size = 128M 

max_allowed_packet= 1M 

net_buffer_length= 8K 

  

skip-external-locking 

skip-host-cache 

skip-name-resolve 

 

# InnoDB 

innodb_buffer_pool_size = 128M 

innodb_log_file_size = 48M 

innodb_file_per_table = 1 

innodb_flush_method = O_DIRECT 

       

# MyISAM 

key_buffer_size = 48M 

character-set-server=utf8 

collation-server=utf8_general_ci 

         

# LOG 

log_error =/home/mysql/data/mysql-error.log 

long_query_time = 1 

slow-query-log 

slow_query_log_file =/home/mysql/data/mysql-slow.log 

                

# Others 

explicit_defaults_for_timestamp=true 

max_connections = 500 

open_files_limit = 65535 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

6、  配置环境变量

[root@mysql ~]# echo $PATH

/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[root@mysql~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile

[root@mysql~]# tail -1 /etc/profile

exportPATH=/usr/local/mysql/bin:$PATH

[root@mysql~]# source /etc/profile

[root@mysql~]# echo $PATH

 

7、  初始化数据库

[root@mysql ~]# cd/usr/local/mysql/scripts/

[root@mysql scripts]# pwd

/usr/local/mysql/scripts

[root@mysql scripts]# ./mysql_install_db--basedir=/usr/local/mysql --datadir=/home/mysql/data --user=mysql

 

8、  设置启动脚本并启动数据库

[root@mysql scripts]# cd/usr/local/mysql/support-files/

[root@mysql support-files]# cp mysql.server/etc/init.d/mysqld

[root@mysql support-files]# ll/etc/init.d/mysqld

-rwxr-xr-x 1 root root 10875 Nov  5 22:36 /etc/init.d/mysqld

[root@mysql support-files]# /etc/init.d/mysqldstart

Starting MySQL...                                        [  OK  ]

[root@mysql support-files]#

 

9、检查mysql进程及端口监听

[root@mysql support-files]# ps -ef|grep mysql|grep –v grep

[root@mysqlsupport-files]# netstat -tunlp|grep 330

[root@mysqlsupport-files]# ss -tunlp|grep 330

 

 

10、登录mysql,查看mysql版本

[root@mysql ~]# mysql

mysql> status;

或者

[root@mysql ~]# mysql --help | grep Distrib

mysql Ver 14.14 Distrib 5.6.16, for Linux (x86_64) using  EditLine wrapper

 

11、root@local用户设置密码

[root@mysql ~]# mysqladmin -u root password '123456'

 

12、删除空密码的用户

[root@mysql ~]# mysql -u root –p

mysql> use mysql;

mysql> select user,host,password from user;

mysql> delete from user wherepassword='';

mysql> select user,host,password from user;

+------+-----------+-------------------------------------------+

| user | host      | password                                  |

+------+-----------+-------------------------------------------+

| root | localhost |*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

+------+-----------+-------------------------------------------+

 

mysql> flush privileges;

 

13、设置mysql开机自启动

[root@mysql ~]# chkconfig --list mysqld

[root@mysql ~]# chkconfig --add mysqld

[root@mysql ~]# chkconfig --list mysqld

如果3,4,5off

[root@mysql ~]# chkconfig mysqld on


14、停止数据库

[root@mysql ~]# mysqladmin shutdown -u root-p

Enter password: