毋庸置疑mysql是当今使用最多的数据库,也是当今最流行的数据库之一,当然未来mysql的发展方向估计也是根据oracle公司惯常用的手法进行中,前景并不乐观,不过作为最经典的数据库关系系统,学好它对于理解其他数据库系统是个很好的基础。现在我演示下至今为止官网发布的最新版5.6.25 的源码安装方式。
安装系统:Centos6.5 64位
安装版本:mysql 5.6.25
安装环境: 安装cmake
gcc-c++ bison git make
ncurses ncurses-devel libaio
cmake的重要特性之一是其独立于源码(out-of-source)的编译功能,即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译的影响,因此在同一个源码树上可以进行多次不同的编译,如针对于不同平台编译。
cmake指定编译选项的方式不同于make,其实现方式对比如下:
./configure cmake .
./configure --help cmake . -LH or ccmake .
指定安装文件的安装路径时常用的选项:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/usr/local/mysql/data
-DSYSCONFDIR=/etc
默认编译的存储引擎包括:csv、myisam、myisammrg和heap。若要安装其它存储引擎,可以使用类似如下编译选项:
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
若要明确指定不编译某存储引擎,可以使用类似如下的选项:
-DWITHOUT_<ENGINE>_STORAGE_ENGINE=1
比如:
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1
-DWITHOUT_PARTITION_STORAGE_ENGINE=1
如若要编译进其它功能,如SSL等,则可使用类似如下选项来实现编译时使用某库或不使用某库:
-DWITH_READLINE=1
-DWITH_SSL=system
-DWITH_ZLIB=system
-DWITH_LIBWRAP=0
其它常用的选项:
-DMYSQL_TCP_PORT=3306
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DENABLED_LOCAL_INFILE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_DEBUG=0
-DENABLE_PROFILING=1
如果想清理此前的编译所生成的文件,则需要使用如下命令:
make clean
rm CMakeCache.txt
首先去下载mysql源码包,
下载完解压
进入目录开始编译
使用默认模式直接编译 cmake ./
如果要自定义安装,通过cmake . -LH or ccmake . 查看相关配置
然后再
编译完成(编译需要一段时间)
创建mysql用户和组
-
groupadd mysql
-
useradd -r -g mysql mysql
修改用户组和用户名
chown -R mysql:mysql /usr/local/mysql
增加环境变量
vim /etc/profile 最后一行加入export PATH=$PATH:/usr/local/mysql/bin
开始安装数据库
进入script ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
Installing MySQL system tables...2015-06-29 14:07:05 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-06-29 14:07:05 1628 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-06-29 14:07:05 1628 [Note] InnoDB: The InnoDB memory heap is disabled
2015-06-29 14:07:05 1628 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-06-29 14:07:05 1628 [Note] InnoDB: Memory barrier is not used
2015-06-29 14:07:05 1628 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-06-29 14:07:05 1628 [Note] InnoDB: Using CPU crc32 instructions
2015-06-29 14:07:05 1628 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-06-29 14:07:05 1628 [Note] InnoDB: Completed initialization of buffer pool
2015-06-29 14:07:05 1628 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2015-06-29 14:07:05 1628 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2015-06-29 14:07:05 1628 [Note] InnoDB: Database physically writes the file full: wait...
2015-06-29 14:07:05 1628 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2015-06-29 14:07:06 1628 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2015-06-29 14:07:06 1628 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2015-06-29 14:07:06 1628 [Warning] InnoDB: New log files created, LSN=45781
2015-06-29 14:07:06 1628 [Note] InnoDB: Doublewrite buffer not found: creating new
2015-06-29 14:07:06 1628 [Note] InnoDB: Doublewrite buffer created
2015-06-29 14:07:06 1628 [Note] InnoDB: 128 rollback segment(s) are active.
2015-06-29 14:07:06 1628 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-06-29 14:07:06 1628 [Note] InnoDB: Foreign key constraint system tables created
2015-06-29 14:07:06 1628 [Note] InnoDB: Creating tablespace and datafile system tables.
2015-06-29 14:07:06 1628 [Note] InnoDB: Tablespace and datafile system tables created.
2015-06-29 14:07:06 1628 [Note] InnoDB: Waiting for purge to start
2015-06-29 14:07:06 1628 [Note] InnoDB: 5.6.21 started; log sequence number 0
2015-06-29 14:07:07 1628 [Note] Binlog end
2015-06-29 14:07:07 1628 [Note] InnoDB: FTS optimize thread exiting.
2015-06-29 14:07:07 1628 [Note] InnoDB: Starting shutdown...
2015-06-29 14:07:07 1628 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2015-06-29 14:07:07 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-06-29 14:07:07 1651 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-06-29 14:07:07 1651 [Note] InnoDB: The InnoDB memory heap is disabled
2015-06-29 14:07:07 1651 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-06-29 14:07:07 1651 [Note] InnoDB: Memory barrier is not used
2015-06-29 14:07:07 1651 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-06-29 14:07:07 1651 [Note] InnoDB: Using CPU crc32 instructions
2015-06-29 14:07:07 1651 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-06-29 14:07:07 1651 [Note] InnoDB: Completed initialization of buffer pool
2015-06-29 14:07:07 1651 [Note] InnoDB: Highest supported file format is Barracuda.
2015-06-29 14:07:08 1651 [Note] InnoDB: 128 rollback segment(s) are active.
2015-06-29 14:07:08 1651 [Note] InnoDB: Waiting for purge to start
2015-06-29 14:07:08 1651 [Note] InnoDB: 5.6.21 started; log sequence number 1625977
2015-06-29 14:07:08 1651 [Note] Binlog end
2015-06-29 14:07:08 1651 [Note] InnoDB: FTS optimize thread exiting.
2015-06-29 14:07:08 1651 [Note] InnoDB: Starting shutdown...
2015-06-29 14:07:09 1651 [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:
/usr/local/mysql//bin/mysqladmin -u root password 'new-password'
/usr/local/mysql//bin/mysqladmin -u root -h test3 password 'new-password'
Alternatively you can run:
/usr/local/mysql//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 . ; /usr/local/mysql//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 />
The latest information about MySQL is available on the web at
http://
Support MySQL by buying support/licenses at />
New default config file was created as /usr/local/mysql//my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
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
数据库初始化完毕!!!
复制数据库启动脚本 cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
复制配置文件 cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf 如果原来就有配置文件就覆盖
编辑配置文件my.cnf指定文件路径和端口
basedir = /usr/local/mysql
datadir =/usr/local/mysql/data
port = 3306
启动服务
[root@test3 ~]# service mysqld start
Starting MySQL................ SUCCESS!
为root设置密码
mysqladmin -u root password "root"
设置成功
进入数据库
mysql -uroot -proot
[root@test3 ~]# mysql -uroot -proot
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.21 Source distribution
Copyright (c) 2000, 2014, 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> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql>
至此安装成功。