MySQL-源码编译安装_MySQL
软件环境
MySQL版本:5.6.19 下载地址:http://dev.mysql.com/downloads/mysql/5.6.html
Linux版本:CentOS-5.10-x86_64 下载地址:http://mirrors.163.com/centos/5.10/isos/x86_64/CentOS-5.10-x86_64-bin-DVD-1of2.iso
安装前准备
linux采用Server Base版本安装、并定制对应的软件包administrator tools、system tools等开发依赖包,所缺依赖包可以安装完系统采用yum安装。
挂在CentOS-5.10-x86_64-bin-DVD-1of2.iso
创建挂在目录:mkdir -p /media/cdrom
挂在ISO:mount -o loop /dev/cdrom /media/cdrom采用ssh连接工具登录到Linux终端,安装所需工具
设置yum源本地安装,查看配置参数/etc/yum.repos.d/CentOS-Media.repo
大概在line:12行“yum --disablerepo=/* --enablerepo=c5-media [command]”
增加yum安装快速命令vi /root/.baserc,追加 “alias yumq='yum --disablerepo=/* --enablerepo=c5-media'”
对/root/.baserc配置生效source /etc/.baserc
安装cmake,gcc等工具
yumq install -y gcc cmake lrzsz
安装其他的依赖包可以采用yumq-
创建专用帐户:
groupadd mysqluseradd -r -g mysql mysql
说明:${version}为下载的版本号
采用lrzsz命令上传mysql.${version}.tar.gz包到/tmp目录
ssh登录终端执行命令:cd /tmp
上传tar包:rz ,根据提示原则mysql.${version}.tar.gz
解压mysql.${version}.tar.gz,执行命令:tar -xzvf mysql.${version}.tar.gz使用cmake编译MySQL
ssh登录终端执行命令:cd /tmp/mysql.${version}
创建MySQL数据文件存储目录:mkdir -p /data/mysqldata/3306
采用utf-8编码编译,执行命令:cmake . -LH查看mysql编译的选项。
一些常用参数如下:
CMAKE_INSTALL_PREFIX:指定MySQL程序的安装目录,默认/usr/local/mysql
DEFAULT_CHARSET:指定服务器默认字符集,默认latin1
DEFAULT_COLLATION:指定服务器默认的校对规则,默认latin1_general_ci
ENABLED_LOCAL_INFILE:指定是否允许本地执行LOAD DATA INFILE,默认OFF
WITH_COMMENT:指定编译备注信息
WITH_xxx_STORAGE_ENGINE:指定静态编译到mysql的存储引擎,MyISAM,MERGE,MEMBER以及CSV四种引擎默认即被编译至服务器,不需要特别指定。
WITHOUT_xxx_STORAGE_ENGINE:指定不编译的存储引擎
SYSCONFDIR:初始化参数文件目录
MYSQL_DATADIR:数据文件目录
MYSQL_TCP_PORT:服务端口号,默认3306
MYSQL_UNIX_ADDR:socket文件路径,默认/tmp/mysql.sock-
执行编译命令如下:
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql /
-DDEFAULT_CHARSET=utf8 /
-DDEFAULT_COLLATION=utf8_unicode_ci /
-DENABLED_LOCAL_INFILE=ON /
-DWITH_INNOBASE_STORAGE_ENGINE=1 /
-DWITH_FEDERATED_STORAGE_ENGINE=1 /
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 /
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 /
-DWITH_COMMENT="jss edition" /
-DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock /
-DSYSCONFDIR=/data/mysqldata/3306编译:cd /tmp/mysql.${version} , 执行:make
安装:make install
配置: 配置mysql环境变量:
将 /usr/local/mysql/bin 添加到path目录。如下:
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH:.
并配置生效source /etc/profile设置权限:
cd /usr/local, 授权:chown -R mysql:mysql ./mysql设置数据库文件:
cd /data/mysqldata/3306/,增加所需文件夹:mkdir data binlog tmp innodb_ts innodb_log,并设置文件夹所有权限 chown -R mysql:mysql /data-
执行mysql_install_db命令创建数据库:
cd /usr/local/mysql,执行:./scripts/mysql_install_db --user=mysql --datadir=/data/mysqldata/3306/data。必须进入/usr/local/mysql因为执行安装数据库脚本需要使用相对目录bin下的程序。
执行结果如下:Installing MySQL system tables...2014-06-02 22:02:39 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2014-06-02 22:02:39 28746 [Note] InnoDB: Using atomics to ref count buffer pool pages2014-06-02 22:02:39 28746 [Note] InnoDB: The InnoDB memory heap is disabled2014-06-02 22:02:39 28746 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2014-06-02 22:02:39 28746 [Note] InnoDB: Compressed tables use zlib 1.2.32014-06-02 22:02:39 28746 [Note] InnoDB: Using CPU crc32 instructions2014-06-02 22:02:39 28746 [Note] InnoDB: Initializing buffer pool, size = 128.0M2014-06-02 22:02:39 28746 [Note] InnoDB: Completed initialization of buffer pool2014-06-02 22:02:39 28746 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!2014-06-02 22:02:39 28746 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB2014-06-02 22:02:39 28746 [Note] InnoDB: Database physically writes the file full: wait...2014-06-02 22:02:39 28746 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB2014-06-02 22:02:40 28746 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB2014-06-02 22:02:40 28746 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile02014-06-02 22:02:40 28746 [Warning] InnoDB: New log files created, LSN=457812014-06-02 22:02:40 28746 [Note] InnoDB: Doublewrite buffer not found: creating new2014-06-02 22:02:40 28746 [Note] InnoDB: Doublewrite buffer created2014-06-02 22:02:40 28746 [Note] InnoDB: 128 rollback segment(s) are active.2014-06-02 22:02:40 28746 [Warning] InnoDB: Creating foreign key constraint system tables.2014-06-02 22:02:40 28746 [Note] InnoDB: Foreign key constraint system tables created2014-06-02 22:02:40 28746 [Note] InnoDB: Creating tablespace and datafile system tables.2014-06-02 22:02:40 28746 [Note] InnoDB: Tablespace and datafile system tables created.2014-06-02 22:02:40 28746 [Note] InnoDB: Waiting for purge to start2014-06-02 22:02:40 28746 [Note] InnoDB: 5.6.19 started; log sequence number 02014-06-02 22:02:40 28746 [Note] Binlog end2014-06-02 22:02:40 28746 [Note] InnoDB: FTS optimize thread exiting.2014-06-02 22:02:40 28746 [Note] InnoDB: Starting shutdown...2014-06-02 22:02:41 28746 [Note] InnoDB: Shutdown completed; log sequence number 1625977OKFilling help tables...2014-06-02 22:02:41 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2014-06-02 22:02:41 28769 [Note] InnoDB: Using atomics to ref count buffer pool pages2014-06-02 22:02:41 28769 [Note] InnoDB: The InnoDB memory heap is disabled2014-06-02 22:02:41 28769 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2014-06-02 22:02:41 28769 [Note] InnoDB: Compressed tables use zlib 1.2.32014-06-02 22:02:41 28769 [Note] InnoDB: Using CPU crc32 instructions2014-06-02 22:02:41 28769 [Note] InnoDB: Initializing buffer pool, size = 128.0M2014-06-02 22:02:41 28769 [Note] InnoDB: Completed initialization of buffer pool2014-06-02 22:02:41 28769 [Note] InnoDB: Highest supported file format is Barracuda.2014-06-02 22:02:41 28769 [Note] InnoDB: 128 rollback segment(s) are active.2014-06-02 22:02:41 28769 [Note] InnoDB: Waiting for purge to start2014-06-02 22:02:42 28769 [Note] InnoDB: 5.6.19 started; log sequence number 16259772014-06-02 22:02:42 28769 [Note] Binlog end2014-06-02 22:02:42 28769 [Note] InnoDB: FTS optimize thread exiting.2014-06-02 22:02:42 28769 [Note] InnoDB: Starting shutdown...2014-06-02 22:02:43 28769 [Note] InnoDB: Shutdown completed; log sequence number 1625987OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE 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 mysql.master.clibing.org password 'new-password'Alternatively you can run: ./bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly 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.plPlease report any problems at http://bugs.mysql.com/The latest information about MySQL is available on the web at http://www.mysql.comSupport MySQL by buying support/licenses at http://shop.mysql.comNew default config file was created as ./my.cnf andwill be used by default by the server when you start it.You may edit this file to change server settingsWARNING: Default config file /etc/my.cnf exists on the systemThis file will be read by default by the MySQL serverIf you do not want to use this, either remove it, or use the--defaults-file argument to mysqld_safe when starting the server
-
复制初始化参数文件到适当的路径下,前面编译配置时已经指定了初始化参数文件默认路径为/data/mysqldata/3306,因此这里要将参数文件复制至该路径下,注意不要复制错了地方:
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf,并修改配置参数,追加如下内容datadir=/data/mysqldata/3306/datatmpdir=/data/mysqldata/3306/tmp
运行并测试是否正常
-
以安全模式启动:/usr/local/mysql/bin/mysqld_safe &
[1] 29479[root@mysql mysql]# 140602 22:34:30 mysqld_safe Logging to '/data/mysqldata/3306/data/mysql.master.clibing.org.err'.140602 22:34:30 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data
检测:ps -aef|grep mysqld
设置root的密码:/usr/local/mysql/bin/mysqladmin -uroot password '123456' -S /data/mysqldata/3306/mysql.sock -
配置启动脚本,拷贝cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
编辑脚本basedir与datadir路径如下basedir=/usr/local/mysqldatadir=/data/mysqldata/3306/data
设置可执行权限 chmod a+x /etc/init.d/mysqld
关闭msyql服务器:service mysqld stopStarting MySQL.[ OK ]
启动msyql服务器:service mysqld start
Shutting down MySQL.[ OK ]
-
登录查看:mysql -uroot -p,输入用户密码123456,出现如下信息:
Welcome to the MySQL monitor. Commands end with ; or /g.Your MySQL connection id is 2Server version: 5.6.19 Source distributionCopyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement./** 执行当前系统中的数据库 */mysql> show databases; +--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+4 rows in set (0.00 sec)
关闭mysql服务器:service mysqld stop。
常见问题
-
错误:
/tmp/mysql-5.6.19/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*)':/tmp/mysql-5.6.19/sql/sql_partition_admin.cc:822: undefined reference to `ha_partition::truncate_partition(Alter_info*, bool*)'collect2: ld returned 1 exit statusmake[2]: *** [storage/perfschema/unittest/pfs_connect_attr-t] Error 1make[1]: *** [storage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/all] Error 2make: *** [all] Error 2
解决:去除-DWITHOUT_PARTITION_STORAGE_ENGINE=1 /
-
配置mysql快速登录。
vi ~/.my.cnf[client]user=rootport=3306host=localhostpassword=123456
保存并退出,执行mysql即可实现登录。
上一篇: js计算阶乘和新打开一个窗口
下一篇: BugFree2.0安装教程汇总
推荐阅读
-
Linux下编译安装MySQL-Python教程
-
CentOS 7.x编译安装Nginx1.10.3+MySQL5.7.16+PHP5.2 5.3 5.4 5.5 5.6 7.0 7.1多版本全能环境
-
Mac系统下源码编译安装MySQL 5.7.17的教程
-
mysql源码安装脚本分享
-
64位CentOs7源码安装mysql-5.6.35过程分享
-
CentOS 源码安装MySQL5.7
-
centos编译安装mysql 5.6及安装多个mysql实例详解
-
详解Lamp环境搭建Linux CentOS6.5编译安装mysql5.6
-
Ubuntu 17.04系统下源码编译安装opencv的步骤详解
-
CentOS Yum编译安装MySQL 5.6