debian 源码编译安装MySQL 5.6.22

mysql5.6.16的安装和之前的5.5、5.1有些不同,编译的时候不再使用./configure来进行了,使用了cmake命令来进行编译项目。

下载MySQL

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


cd /opt
tar -zxvf mysql-5.6.22.tar.gz
cd mysql-5.6.22

编译源码

接下来组织项目


cmake \
-DCMAKE_INSTALL_PREFIX=/opt/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql/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
注意,这个cmake是替代以前的./configure 步骤。如果你需要更多的参数,请参考 http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html


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

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
  • 使用参数-DENABLE_DOWNLOADS=1 自动下载。
  • 或 将文件手动下载 存放到 source_downloads 文件夹下(主要是看错误提示)

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


-- Running cmake version 2.6.4
-- MySQL 5.6.16
-- Packaging as: mysql-5.6.16-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
-- GMOCK_SOURCE_DIR:/root/mysql-5.6.16/source_downloads/gmock-1.6.0
-- GTEST_LIBRARIES:gmock;gtest
-- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl
-- Configuring done
-- Generating done
-- Build files have been written to: /root/mysql-5.6.16
接着编译源码



make && make install
编译时间缓慢,等待中…



修改文件权限,生成数据库

shell> cd /opt/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql \
         --basedir=/opt/mysql \
         --datadir=/data/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
shell> /etc/init.d/mysql start (或者 service mysql start)


mysql的官方安装方法参考: http://dev.mysql.com/doc/refman/5.6/en/installing-source-distribution.html

mysql-install-db 此命令是导入默认的数据库的 具体参数参考: http://dev.mysql.com/doc/refman/5.6/en/installing-source-distribution.html

注:

bin/mysqld_safe --user=mysql &  启动后注意记录 日志的存放位置 和 ***.pid  在后面的配置 my.cnf 中的[mysqld_safe]会用到
注:需先启动
bin/mysqld_safe --user=mysql 后 再执行 
/etc/init.d/mysql start

如果执行出现 Starting MySQL. ERROR! The server quit without updating PID file (/data/mysql/data/VM_208.pid).
可能就是 bin/mysqld_safe --user=mysql 没有执行


设置配置文件


my.cnf的配置文件的默认读取顺序为
File Name(上面的优先) Purpose
/etc/my.cnf Global options
/etc/mysql/my.cnf Global options
SYSCONFDIR/my.cnf Global options
$MYSQL_HOME/my.cnf Server-specific options
defaults-extra-file The file specified with --defaults-extra-file=path, if any
~/.my.cnf User-specific options
~/.mylogin.cnf Login path options



在 /etc/my.cnf 创建 内容(根据实际情况配置):

[client]
port=3306
socket=/tmp/mysql/mysql.sock
default-character-set = utf8

[mysqld]
port=3306
bind-address=127.0.0.1 #如果绑定了地址 就只有此地址可以访问数据库
basedir=/opt/mysql
datadir=/data/mysql
socket=/tmp/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

############# default settings  ################
# time zone
default-time-zone = system
character-set-server = utf8
default-storage-engine = InnoDB

[mysqld_safe]
log-error=/data/mysql/debian.err 
pid-file=/data/mysql/debian.pid



我的这个配置比较简单,声明一下常用的变量,如果你需要对性能优化,那么你需要细细研读一下配置文件。可以参考

启动MySQL,开机自动启动设置

手动启动MySQL。



cp /opt/mysql/support-files/mysql.server /etc/init.d/mysql
/etc/init.d/mysql start
##或者
service mysql start


在上面的步骤后,开机自动启动设置

chkconfig --add mysql
##有的系统需要下面的
chkconfig --level 345 mysql on
可以参考: http://dev.mysql.com/doc/refman/5.6/en/automatic-start.html



修改root密码

默认的密码是空的,很危险,需要修改一下。

在此之前,为方便调用mysql,我们先生成一个mysql的软链。

ln -s /opt/mysql/bin/mysql /usr/bin/

然后修改密码


mysql -uroot  -h127.0.0.1 -p
mysql> SET PASSWORD = PASSWORD('123456');



将来如果你忘记了root密码,可以参考重置MySQL密码

通过上面的步骤,就可以使用MySQL数据库了,另外可以为mysql安装phpmyadmin作为前端的管理界面。

参考资料


mysql 设置

可以参考  http://my.oschina.net/haopeng/blog/268518

转载于:https://my.oschina.net/haopeng/blog/362563

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值