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.20.tar.gz
cd mysql-5.6.20
 
#默认情况下是安装在/usr/local/mysql
cmake .
make && make install

编译参数

cmake  
-DCMAKE_INSTALL_PREFIX=/alidata/server/mysql-5.6.20 
-DMYSQL_DATADIR=/alidata/server/mysql-5.6.20/data 
-DSYSCONFDIR=/etc 
-DWITH_MYISAM_STORAGE_ENGINE=1 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_MEMORY_STORAGE_ENGINE=1 
-DWITH_READLINE=1 
-DMYSQL_UNIX_ADDR=/alidata/server/mysql-5.6.20/mysql.sock 
-DMYSQL_TCP_PORT=3306 
-DENABLED_LOCAL_INFILE=1 
-DWITH_PARTITION_STORAGE_ENGINE=1 
-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=1 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.4
-- MySQL 5.6.20
-- Packaging as: mysql-5.6.20-Linux-x86_64
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- Using cmake version 2.6.4
-- 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.20

接着编译源码

make && make install

改变目录所有者

chown  mysql:mysql /alidata/server/mysql-5.6.20/

4、初始化数据库

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

5、注册为服务

cd /alidata/server/mysql-5.6.20/support-files
 
#注册服务
cp mysql.server /etc/rc.d/init.d/mysql
 
#使用默认配置文件
cp ../my.cnf /etc/my.cnf

#修改配置文件
basedir=/alidata/server/mysql-5.6.20
datadir=/alidata/server/mysql-5.6.20/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.20/bin:$PATH
export PATH

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

mysql -uroot  
SET PASSWORD = PASSWORD('123456');
 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' 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.20 --datadir=/alidata/server/mysql-5.6.20/data
Installing MySQL system tables...2014-09-30 20:42:53 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-09-30 20:42:53 19761 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-09-30 20:42:53 19761 [Note] InnoDB: The InnoDB memory heap is disabled
2014-09-30 20:42:53 19761 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-09-30 20:42:53 19761 [Note] InnoDB: Memory barrier is not used
2014-09-30 20:42:53 19761 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-09-30 20:42:53 19761 [Note] InnoDB: Using CPU crc32 instructions
2014-09-30 20:42:53 19761 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-09-30 20:42:53 19761 [Note] InnoDB: Completed initialization of buffer pool
2014-09-30 20:42:53 19761 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2014-09-30 20:42:53 19761 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2014-09-30 20:42:53 19761 [Note] InnoDB: Database physically writes the file full: wait...
2014-09-30 20:42:53 19761 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2014-09-30 20:42:54 19761 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2014-09-30 20:42:55 19761 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2014-09-30 20:42:55 19761 [Warning] InnoDB: New log files created, LSN=45781
2014-09-30 20:42:55 19761 [Note] InnoDB: Doublewrite buffer not found: creating new
2014-09-30 20:42:55 19761 [Note] InnoDB: Doublewrite buffer created
2014-09-30 20:42:55 19761 [Note] InnoDB: 128 rollback segment(s) are active.
2014-09-30 20:42:55 19761 [Warning] InnoDB: Creating foreign key constraint system tables.
2014-09-30 20:42:55 19761 [Note] InnoDB: Foreign key constraint system tables created
2014-09-30 20:42:55 19761 [Note] InnoDB: Creating tablespace and datafile system tables.
2014-09-30 20:42:55 19761 [Note] InnoDB: Tablespace and datafile system tables created.
2014-09-30 20:42:55 19761 [Note] InnoDB: Waiting for purge to start
2014-09-30 20:42:55 19761 [Note] InnoDB: 5.6.20 started; log sequence number 0
2014-09-30 20:42:56 19761 [Note] Binlog end
2014-09-30 20:42:56 19761 [Note] InnoDB: FTS optimize thread exiting.
2014-09-30 20:42:56 19761 [Note] InnoDB: Starting shutdown...
2014-09-30 20:42:57 19761 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2014-09-30 20:42:57 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-09-30 20:42:57 19783 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-09-30 20:42:57 19783 [Note] InnoDB: The InnoDB memory heap is disabled
2014-09-30 20:42:57 19783 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-09-30 20:42:57 19783 [Note] InnoDB: Memory barrier is not used
2014-09-30 20:42:57 19783 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-09-30 20:42:57 19783 [Note] InnoDB: Using CPU crc32 instructions
2014-09-30 20:42:57 19783 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-09-30 20:42:57 19783 [Note] InnoDB: Completed initialization of buffer pool
2014-09-30 20:42:57 19783 [Note] InnoDB: Highest supported file format is Barracuda.
2014-09-30 20:42:57 19783 [Note] InnoDB: 128 rollback segment(s) are active.
2014-09-30 20:42:57 19783 [Note] InnoDB: Waiting for purge to start
2014-09-30 20:42:57 19783 [Note] InnoDB: 5.6.20 started; log sequence number 1625977
2014-09-30 20:42:57 19783 [Note] Binlog end
2014-09-30 20:42:57 19783 [Note] InnoDB: FTS optimize thread exiting.
2014-09-30 20:42:57 19783 [Note] InnoDB: Starting shutdown...
2014-09-30 20:42:58 19783 [Note] InnoDB: Shutdown completed; log sequence number 1625987
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.20/bin/mysqladmin -u root password 'new-password'
  /alidata/server/mysql-5.6.20/bin/mysqladmin -u root -h iZ23lt92evyZ password 'new-password'

Alternatively you can run:

  /alidata/server/mysql-5.6.20/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.20/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.20/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

原文地址:https://www.cnblogs.com/mjorcen/p/4002671.html