linux下MySQL 5.6源码安装

linux下MySQL 5.6源码安装

1、下载:当前mysql版本到了5.6.20

http://dev.mysql.com/downloads/mysql

选择Source Code

2、必要软件包

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

3、编译安装

添加用户

groupadd mysql
useradd -r -g mysql mysql

编译安装

tar -zxvf mysql-5.6..tar.gz
cd mysql-5.6. #默认情况下是安装在/usr/local/mysql
cmake .
make && make install

编译参数

cmake  \
-DCMAKE_INSTALL_PREFIX=/alidata/server/mysql-5.6. \
-DMYSQL_DATADIR=/alidata/server/mysql-5.6./data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE= \
-DWITH_INNOBASE_STORAGE_ENGINE= \
-DWITH_MEMORY_STORAGE_ENGINE= \
-DWITH_READLINE= \
-DMYSQL_UNIX_ADDR=/alidata/server/mysql-5.6./mysql.sock \
-DMYSQL_TCP_PORT= \
-DENABLED_LOCAL_INFILE= \
-DWITH_PARTITION_STORAGE_ENGINE= \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci ;

编译的参数可以参考http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

有时候会出现类似的问题。

-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl
-- Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS= to automatically download and build required components from source.
-- If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80
-- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl
-- Configuring done
-- Generating done
  • 使用参数-DENABLE_DOWNLOADS=1 自动下载。
  • 有网络限制,设置http代理export http_proxy=http://example.com:80。环境变量http_proxy 也为 curl 等其他工具所用。尽管 yum 可以识别大写或小写的 http_proxy,但curl 要求环境变量的名称是小写。

  

  如果这个cmake这个步骤有出现问题,解决后重新再cmake一次。如果输出类似这样,那么就好了。

-- Running cmake version 2.6.
-- MySQL 5.6.
-- Packaging as: mysql-5.6.-Linux-x86_64
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- Using cmake version 2.6.
-- Not building NDB
-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl
-- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl
-- Configuring done
-- Generating done
-- Build files have been written to: /root/tools/mysql-5.6.

接着编译源码

make && make install

改变目录所有者

chown  mysql:mysql /alidata/server/mysql-5.6./

4、初始化数据库

cd /alidata/server/mysql-5.6./scripts
./mysql_install_db --user=mysql --basedir=/alidata/server/mysql-5.6. --datadir=/alidata/server/mysql-5.6./data

5、注册为服务

cd /alidata/server/mysql-5.6./support-files

#注册服务
cp mysql.server /etc/rc.d/init.d/mysql #使用默认配置文件
cp ../my.cnf /etc/my.cnf #修改配置文件
basedir=/alidata/server/mysql-5.6.
datadir=/alidata/server/mysql-5.6./data #让chkconfig管理mysql服务
chkconfig --add mysql #开机启动
chkconfig mysql on

6、启动MySQL服务

service mysql start

7、改变编码,防止乱码

SHOW VARIABLES LIKE 'character%'

  

修改mysql的my.cnf文件

[client]
default-character-set=utf8 [mysqld]
character-set-server=utf8 [mysql]
default-character-set=utf8

8、将mysql的bin加入到path中

cd ~
#我把path添加到当前用户目录的bashrc中,如果需要全局设定,请修改`/etc/profile`
vi .bashrc #加入以下内容
PATH=/alidata/server/mysql-5.6./bin:$PATH
export PATH

9、配置用户密码和远程访问权限

mysql -uroot
SET PASSWORD = PASSWORD(''); GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;

部分步骤debug 如下:

 ./mysql_install_db --user=mysql --basedir=/alidata/server/mysql-5.6.20 --datadir=/alidata/server/mysql-5.6.20/data
[root@iZ23lt92evyZ scripts]# ./mysql_install_db --user=mysql --basedir=/alidata/server/mysql-5.6. --datadir=/alidata/server/mysql-5.6./data
Installing MySQL system tables...-- :: [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
-- :: [Note] InnoDB: Using atomics to ref count buffer pool pages
-- :: [Note] InnoDB: The InnoDB memory heap is disabled
-- :: [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
-- :: [Note] InnoDB: Memory barrier is not used
-- :: [Note] InnoDB: Compressed tables use zlib 1.2.
-- :: [Note] InnoDB: Using CPU crc32 instructions
-- :: [Note] InnoDB: Initializing buffer pool, size = 128.0M
-- :: [Note] InnoDB: Completed initialization of buffer pool
-- :: [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
-- :: [Note] InnoDB: Setting file ./ibdata1 size to MB
-- :: [Note] InnoDB: Database physically writes the file full: wait...
-- :: [Note] InnoDB: Setting log file ./ib_logfile101 size to MB
-- :: [Note] InnoDB: Setting log file ./ib_logfile1 size to MB
-- :: [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
-- :: [Warning] InnoDB: New log files created, LSN=
-- :: [Note] InnoDB: Doublewrite buffer not found: creating new
-- :: [Note] InnoDB: Doublewrite buffer created
-- :: [Note] InnoDB: rollback segment(s) are active.
-- :: [Warning] InnoDB: Creating foreign key constraint system tables.
-- :: [Note] InnoDB: Foreign key constraint system tables created
-- :: [Note] InnoDB: Creating tablespace and datafile system tables.
-- :: [Note] InnoDB: Tablespace and datafile system tables created.
-- :: [Note] InnoDB: Waiting for purge to start
-- :: [Note] InnoDB: 5.6. started; log sequence number
-- :: [Note] Binlog end
-- :: [Note] InnoDB: FTS optimize thread exiting.
-- :: [Note] InnoDB: Starting shutdown...
-- :: [Note] InnoDB: Shutdown completed; log sequence number
OK Filling help tables...-- :: [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
-- :: [Note] InnoDB: Using atomics to ref count buffer pool pages
-- :: [Note] InnoDB: The InnoDB memory heap is disabled
-- :: [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
-- :: [Note] InnoDB: Memory barrier is not used
-- :: [Note] InnoDB: Compressed tables use zlib 1.2.
-- :: [Note] InnoDB: Using CPU crc32 instructions
-- :: [Note] InnoDB: Initializing buffer pool, size = 128.0M
-- :: [Note] InnoDB: Completed initialization of buffer pool
-- :: [Note] InnoDB: Highest supported file format is Barracuda.
-- :: [Note] InnoDB: rollback segment(s) are active.
-- :: [Note] InnoDB: Waiting for purge to start
-- :: [Note] InnoDB: 5.6. started; log sequence number
-- :: [Note] Binlog end
-- :: [Note] InnoDB: FTS optimize thread exiting.
-- :: [Note] InnoDB: Starting shutdown...
-- :: [Note] InnoDB: Shutdown completed; log sequence number
OK To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands: /alidata/server/mysql-5.6./bin/mysqladmin -u root password 'new-password'
/alidata/server/mysql-5.6./bin/mysqladmin -u root -h iZ23lt92evyZ password 'new-password' Alternatively you can run: /alidata/server/mysql-5.6./bin/mysql_secure_installation which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd . ; /alidata/server/mysql-5.6./bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as /alidata/server/mysql-5.6./my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

参考: 
http://blog.163.com/liyinhui20080527@126/blog/static/815232582013885310900/ 
http://www.cnblogs.com/xiongpq/p/3384681.html

转自:  http://my.oschina.net/looly/blog/297980#OSC_h2_1

上一篇:Linux中源码安装编译Vim


下一篇:搭建LNAMP环境(七)- PHP7源码安装Memcached和Memcache拓展