MySql 5.6.27源码编译安装

1 准备工作

1.1下载mysql

1.1.1源码版(通用)

# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.27.tar.gz

1.1.2二进制版(通用)

# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.27-linux-glibc2.5-i686.tar.gz

1.1.3 其他版本

http://dev.mysql.com/downloads/  //自行下载相应的安装包

 

2 安装mysql(源码安装)

2.1新建用户与目录

# groupadd mysql
# useradd -r -g mysql mysql   //-r参数表明创建的是系统用户,不会创建家目录
# mkdir -p /usr/local/mysql
# mkdir -p /data/mysql
# chown -R mysql:mysql /data/mysql
# chown -R mysql:mysql /usr/local/mysql

或者

# useradd -s /sbin/nologin -M mysql // -s 不允许登陆,-M不创建家目录
# chown -R mysql:mysql  //mysql到mysql组中去

2.2安装与配置

注:从mysql5.5后以cmake取代了configure

2.2.1安装cmake

下载地址:http://www.cmake.org/

tar zxvf cmake-2.8.4.tar.gz
cd cmake-2.8.4
./configure
make
make install

或者

# yum -y install cmake  //适用于 centos redhat系统

详情请参考:

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

http://waynerqiu.com/7/153.html

2.3编译安装

# tar -zxvf mysql-5.6.27.tar.gz
# cd mysql-5.6.27/
#cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

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

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_DATADIR=/db/mysql/data\

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306

如果报错,需安装相应的库,使用yum安装,重新cmake需执行make clean

the C compiler identification is unknown

the CXX compiler identification is unknown

— Could NOT find Threads (missing: Threads_FOUND)

— Could NOT find Threads (missing: Threads_FOUND)

# yum -y install gcc
# yum -y install gcc-c++
# yum install -y ncurses-devel
# yum -y install bison

或者执行:

# yum -y install  gcc gcc-c++ gcc-g77 bison autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake

 

继续安装

# rm -f CMakeCache.txt

# make
# make install

2.4配置
# cp support-files/my-default.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/init.d/mysqld

#chmod a+x /etc/init.d/mysqld

# vim /etc/my.cnf
修改
basedir=/usr/local/mysql
datadir=/data/mysql
#/usr/local/mysql/scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/data/mysql

2.5启动mysql服务

# /etc/init.d/mysqld start

 

2.5.1查看是否启动正常

# ps aux |grep mysql //查看是否有mysql进程
# netstat -lnp |grep 3306 //查看是否监听mysql的3306端口

 

2.5.2添加mysql路径

# vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin/
# source /etc/profile
# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.27 Source distribution

Copyright (c) 2000, 2015, 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>

如果报错

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

执行

# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

2.6让chkconfig管理mysql服务

# chkconfig –add mysqld
# chkconfig mysqld on //设置自启动,可选
# service mysqld start|restart|stop

 

2.7root添加密码

# mysqladmin -uroot password

再次登录

#mysql -hlocalhost -uroot -p

2.8设置远程登录

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.27 Source distribution

Copyright (c) 2000, 2015, 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> GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;

发表评论

电子邮件地址不会被公开。 必填项已用*标注