1. 程式人生 > >centos上mysql5.6 原始碼包安裝

centos上mysql5.6 原始碼包安裝

mysql 原始碼包安裝步驟:
1.需要有如下工具
CMake, which is used as the build framework on all platforms
make  make 3.75 or newer
C++ compiler. GCC 4.2.1 or later
Perl is needed if you intend to run test scripts. Most Unix-like systems include 
[[email protected] ~]# rpm -qa make
make-3.81-20.el6.x86_64
安裝cmake
[[email protected]
~]# yum -y install cmake
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
[[email protected] ~]# rpm -qa cmake
cmake-2.8.12.2-4.el6.x86_64
[[email protected] ~]# rpm -qa gcc
gcc-4.4.7-16.el6.x86_64
[[email protected] ~]# 
2.新增使用者
groupadd mysql
useradd -r -g mysql mysql
[
[email protected]
mysql-5.6.28]# groupadd mysql
[[email protected] mysql-5.6.28]# useradd -r -g mysql mysql
[[email protected] mysql-5.6.28]# id mysql
uid=496(mysql) gid=500(mysql) groups=500(mysql)
3.編譯安裝:
cmake .
make && make install
編譯過程中報了很多錯誤,有很多包沒有安裝導致的
gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake
如果沒有需要安裝
yum -y install
如下:
(1)
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
(2) make
(3) make install
解釋:
-DCMAKE_INSTALL_PREFIX=dir_name
The installation base directory
 -DMYSQL_DATADIR=dir_name
The location of the MySQL data directory.
-DSYSCONFDIR=dir_name
The default my.cnf option file directory.
The MyISAM, MERGE, MEMORY, and CSV engines are mandatory (always compiled into the server) and
need not be installed explicitly.
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
-DMYSQL_UNIX_ADDR=file_name
The Unix socket file path on which the server listens for socket connections. This must be an
absolute path name. The default is /tmp/mysql.sock.
-DMYSQL_TCP_PORT=port_num
The port number on which the server listens for TCP/IP connections. The default is 3306.
-DENABLED_LOCAL_INFILE=bool
Whether to enable LOCAL capability in the client library for LOAD DATA INFILE.
-DDEFAULT_CHARSET=charset_name
The server character set. By default, MySQL uses the latin1 (cp1252 West European) character set.
-DDEFAULT_COLLATION=collation_name
The server collation. By default, MySQL uses latin1_swedish_ci. Use the SHOW COLLATION
statement to determine which collations are available for each character set.
一開始編譯加上了-DWITHOUT_PARTITION_STORAGE_ENGINE=1
報錯,去掉就可以了
../../../sql/libsql.a(handler.cc.o): In function `get_ha_partition(partition_info*)':
/root/mysql-5.6.13/sql/handler.cc:460: undefined reference to `ha_partition::ha_partition(handlerton*, partition_info*)'
/root/mysql-5.6.13/sql/handler.cc:462: undefined reference to `ha_partition::initialize_partition(st_mem_root*)'
../../../sql/libsql.a(sql_partition_admin.cc.o): In function `Sql_cmd_alter_table_truncate_partition::execute(THD*)':
/root/mysql-5.6.13/sql/sql_partition_admin.cc:822: undefined reference to `ha_partition::truncate_partition(Alter_info*, bool*)'
collect2: ld returned 1 exit status
make[2]: *** [storage/perfschema/unittest/pfs_connect_attr-t] Error 1
make[1]: *** [storage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/all] Error 2
make: *** [all] Error 2
4.建立資料目錄
[
[email protected]
mysql]# mkdir data
[[email protected] mysql]# chown -R mysql:mysql data/
[[email protected] mysql]# chown -R mysql .
[[email protected] mysql]# chgrp -R mysql .
5.初始化:
[[email protected] mysql]# scripts/mysql_install_db --user=mysql
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "zh_cn.GB2312"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Installing MySQL system tables...2016-01-15 11:08:14 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-01-15 11:08:14 0 [Note] ./bin/mysqld (mysqld 5.6.28) starting as process 24794 ...
2016-01-15 11:08:14 24794 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-01-15 11:08:14 24794 [Note] InnoDB: The InnoDB memory heap is disabled
2016-01-15 11:08:14 24794 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-01-15 11:08:14 24794 [Note] InnoDB: Memory barrier is not used
2016-01-15 11:08:14 24794 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-01-15 11:08:15 24794 [Note] InnoDB: Not using CPU crc32 instructions
2016-01-15 11:08:15 24794 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-01-15 11:08:15 24794 [Note] InnoDB: Completed initialization of buffer pool
2016-01-15 11:08:15 24794 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2016-01-15 11:08:15 24794 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2016-01-15 11:08:15 24794 [Note] InnoDB: Database physically writes the file full: wait...
2016-01-15 11:08:15 24794 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2016-01-15 11:08:15 24794 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2016-01-15 11:08:16 24794 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2016-01-15 11:08:16 24794 [Warning] InnoDB: New log files created, LSN=45781
2016-01-15 11:08:16 24794 [Note] InnoDB: Doublewrite buffer not found: creating new
2016-01-15 11:08:16 24794 [Note] InnoDB: Doublewrite buffer created
2016-01-15 11:08:16 24794 [Note] InnoDB: 128 rollback segment(s) are active.
2016-01-15 11:08:16 24794 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-01-15 11:08:16 24794 [Note] InnoDB: Foreign key constraint system tables created
2016-01-15 11:08:16 24794 [Note] InnoDB: Creating tablespace and datafile system tables.
2016-01-15 11:08:16 24794 [Note] InnoDB: Tablespace and datafile system tables created.
2016-01-15 11:08:16 24794 [Note] InnoDB: Waiting for purge to start
2016-01-15 11:08:16 24794 [Note] InnoDB: 5.6.28 started; log sequence number 0
2016-01-15 11:08:16 24794 [Note] Binlog end
2016-01-15 11:08:16 24794 [Note] InnoDB: FTS optimize thread exiting.
2016-01-15 11:08:16 24794 [Note] InnoDB: Starting shutdown...
2016-01-15 11:08:17 24794 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2016-01-15 11:08:17 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-01-15 11:08:17 0 [Note] ./bin/mysqld (mysqld 5.6.28) starting as process 24816 ...
2016-01-15 11:08:17 24816 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-01-15 11:08:17 24816 [Note] InnoDB: The InnoDB memory heap is disabled
2016-01-15 11:08:17 24816 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-01-15 11:08:17 24816 [Note] InnoDB: Memory barrier is not used
2016-01-15 11:08:17 24816 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-01-15 11:08:17 24816 [Note] InnoDB: Not using CPU crc32 instructions
2016-01-15 11:08:17 24816 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-01-15 11:08:17 24816 [Note] InnoDB: Completed initialization of buffer pool
2016-01-15 11:08:17 24816 [Note] InnoDB: Highest supported file format is Barracuda.
2016-01-15 11:08:17 24816 [Note] InnoDB: 128 rollback segment(s) are active.
2016-01-15 11:08:17 24816 [Note] InnoDB: Waiting for purge to start
2016-01-15 11:08:17 24816 [Note] InnoDB: 5.6.28 started; log sequence number 1625977
2016-01-15 11:08:18 24816 [Note] Binlog end
2016-01-15 11:08:18 24816 [Note] InnoDB: FTS optimize thread exiting.
2016-01-15 11:08:18 24816 [Note] InnoDB: Starting shutdown...
2016-01-15 11:08:19 24816 [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:
  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h repl2 password 'new-password'
Alternatively you can run:
  ./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 . ; ./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
WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as ./my-new.cnf,
please compare it with your file and take the changes you need.
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
[[email protected] mysql]# chown -R root .
[[email protected] mysql]# ls -al
total 188
drwxr-xr-x. 13 root mysql   4096 Jan 15 11:08 .
drwxr-xr-x. 17 root root    4096 Jan 15 10:00 ..
-rw-r--r--.  1 root mysql  17987 Nov 16 17:38 COPYING
-rw-r--r--.  1 root mysql 105684 Nov 16 18:45 INSTALL-BINARY
-rw-r--r--.  1 root mysql   2496 Nov 16 17:38 README
drwxr-xr-x.  2 root mysql   4096 Jan 15 10:56 bin
drwxr-xr-x.  5 root mysql   4096 Jan 15 11:08 data
drwxr-xr-x.  2 root mysql   4096 Jan 15 10:56 docs
drwxr-xr-x.  3 root mysql   4096 Jan 15 10:56 include
drwxr-xr-x.  3 root mysql   4096 Jan 15 10:56 lib
drwxr-xr-x.  4 root mysql   4096 Jan 15 10:56 man
-rw-r--r--.  1 root root     943 Jan 15 11:08 my-new.cnf
-rw-r--r--.  1 root root     943 Jan 15 11:06 my.cnf
drwxr-xr-x. 10 root mysql   4096 Jan 15 10:57 mysql-test
drwxr-xr-x.  2 root mysql   4096 Jan 15 10:56 scripts
drwxr-xr-x. 28 root mysql   4096 Jan 15 10:57 share
drwxr-xr-x.  4 root mysql   4096 Jan 15 10:57 sql-bench
drwxr-xr-x.  2 root mysql   4096 Jan 15 10:57 support-files
6.啟動
啟動報許可權錯誤:
修改許可權再次啟動
[[email protected] local]# chown mysql:mysql -R mysql
[[email protected] mysql]# ./bin/mysqld_safe --user=mysql &
[1] 25164
[[email protected] mysql]# 160115 11:14:53 mysqld_safe Logging to '/usr/local/mysql/data/repl2.err'.
160115 11:14:53 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[[email protected] mysql]# ps -ef |grep mysql
root     25164  9442  0 11:14 pts/2    00:00:00 /bin/sh ./bin/mysqld_safe --user=mysql
mysql    25288 25164  1 11:14 pts/2    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/repl2.err --pid-file=/usr/local/mysql/data/repl2.pid
root     25313  9442  0 11:15 pts/2    00:00:00 grep mysql
[[email protected] mysql]# 
[[email protected] bin]# ./mysql 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28 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> 
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
|      | localhost |
| root | localhost |
|      | repl2     |
| root | repl2     |
+------+-----------+
6 rows in set (0.00 sec)
mysql> 
7.修改root密碼:
[[email protected] mysql]# ./bin/mysqladmin -u root password '123456';
Warning: Using a password on the command line interface can be insecure.
[[email protected] mysql]# 
啟動停止登入都需要指定mysql全目錄
把mysql的bin目錄新增環境變數中/etc/profile
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile 環境變數生效
8.把mysql啟動設定為服務
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql]# ls /etc/init.d/mysqld 
/etc/init.d/mysqld
[[email protected] mysql]# 
[[email protected] mysql]# chmod 755 /etc/rc.d/init.d/mysqld
[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig --list mysqld
mysqld          0:off   1:off 2:on 3:on 4:on    5:on    6:off
[[email protected] bin]# service mysqld stop
Shutting down MySQL.                                       [紜甝
[[email protected] bin]# ps -ef |grep mysql
root     25411 24744  0 11:28 pts/3    00:00:00 grep mysql
[[email protected] bin]# service mysqld start
[[email protected] bin]# ps -ef |grep mysql
root     25425     1  0 11:29 pts/3    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/repl2.pid
mysql    25562 25425  6 11:29 pts/3    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/repl2.err --pid-file=/usr/local/mysql/data/repl2.pid
root     25592 24744  0 11:29 pts/3    00:00:00 grep mysql

官方的原始碼安裝:
# Preconfiguration setup
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
# Beginning of source-build specific instructions
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> cmake .
shell> make
shell> make install
# End of source-build specific instructions
# Postinstallation setup
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server