centos 下编译安装mysql5.1与mysql5.5

mysql5.1.60编译安装
1、tar -zxvf mysql*
2、./configure 之前要make clean
./configure --prefix=/home/shk/mysql-5.1.60 \
--enable-local-infile \
--with-unix-socket-path=/home/shk/mysql-5.1.60/var/mysql.sock \
--with-tcp-port=5506 \
--enable-thread-safe-client \
--with-mysqld-user=root \
--with-extra-charsets=gb2312,big5,gbk,binary,ascii,latin1 \
--with-charset=utf8 \
--with-federated-storage-engine \
--with-partition

注释:在执行“make clean” 失败时,提示错误checking for termcap functions library... configure: error: Nocurses/termcap library found 。
则在执行./configure命令,执行命令代码为:
./configure--prefix=/usr/share/mysql/ -with-charset=utf8 -with-extra-charsets=all –with-named-curses-libs=/usr/lib/libncursesw.so.5(最后一段命令可以省略)

出现错误:No curses/termcap library found 或者seethe install manual chapter in the reference
yum –y install gcc yum install ncurses-devel
在安装gcc时,出错libstdc++-devel*安装不上,则手动下一个libstdc++-devel*.rpm包装上,
在用rpm安装libstdc++-devel*.rpm时报错:error: Failed dependencies,
则用命令:rpm -ivh libstdc++*.rpm --nodeps --force
3、make
如果报错,则减少configure的项
4、make install
5、建立MYSQL的启动文件
#chown -R root:mysql /usr/local/mysql
#chown -R mysql:mysql /usr/local/mysql/data
#chown -R mysql:mysql /usr/local/mysql/lib

#cd /usr/local/mysql/bin/
#./mysql_install_db --user=mysql
#cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
#cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
6、启动MySQL
#/usr/local/mysql/share/mysql/mysql.server start
7、下载编译安装的mysql
在源码文件中执行:make uninstall
mysql5.5.31编译安装
1、下载安装编译MySQL源码需要的库
sudo apt-get install build-essential libncurses5-dev cmake
2、添加mysql用户组和用户
groupadd mysql
useradd -g mysql mysql
3、创建MySQL软件安装目录和数据存放目录
mkdir -p /opt/mysql #MySQL安装目录
chown -R mysql:mysql /opt/mysql
mkdir -p /data/mysql #MySQL数据存放目录
mkdir -p /data/mysql/data #存放数据
mkdir -p /data/mysql/log #存放日志
mkdir -p /data/mysql/tmp #存放临时文件
chown -R mysql:mysql /data/mysql

4、cmake编译安装MySQL
tar -zxvf mysql-5.6.13.tar.gz
cd mysql-5.6.13
cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/opt/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
make
make install
参数说明:
-DCMAKE_INSTALL_PREFIX=/opt/mysql //指定安装目录
-DINSTALL_DATADIR=/data/mysql //指定数据存放目录
-DSYSCONFDIR=/opt/mysql //指定配置文件目录(本例的配置文件为/opt/mysql/my.cnf)
-DDEFAULT_CHARSET=utf8 //指定字符集
-DDEFAULT_COLLATION=utf8_general_ci //指定校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
上述步骤执行成功后,MySQL软件已成功安装至/opt/mysql目录下。

5、编辑配置文件my.cnf
[client]
port = 3306
socket = /opt/mysql/run/mysql.sock

[mysql]

[mysqld_safe]
pid-file = /opt/mysql/run/mysqld.pid
socket = /opt/mysql/run/mysql.sock
nice = 0

[mysqld]

#### Baes dir ####
basedir = /opt/mysql
datadir = /data/mysql/data
tmpdir = /data/mysql/tmp
socket = /opt/mysql/run/mysql.sock
user=mysql
#### Base configure info ####
port = 3306

skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
log-error = /data/mysql/log/alert.log
slow_query_log_file= /data/mysql/log/slow.log
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes

#### Binary log && Relay log ####
#binlog_format=‘MIXED‘
log-bin = /data/mysql/log/mysql-bin
log-slave-updates = 1
relay-log = /data/mysql/log/mysqld-relay-bin
relay-log-index = /data/mysql/log/mysqld-relay-bin.index
master-info-file = /data/mysql/log/master.info
relay-log-info-file = /data/mysql/log/relay-log.info
max_binlog_size = 100M

[mysqldump]
quick
quote-names
max_allowed_packet = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
key_buffer = 16M
6、创建数据库
/opt/mysql/scripts/mysql_install_db --user=mysql
上述建库语句将根据my.cnf里设置的数据文件目录和日志文件目录,生成相应的数据文件和日志文件,并创建系统数据库(如mysql,test,information_schema,performance_schema)
7、启动MySQL
/opt/mysql/support-files/mysql.server start
启动成功后,就可以以root用户登录(默认的root用户没有密码)
/opt/mysql/bin/mysql -u root
查看是否可以登录
8、设置root密码
mysqladmin -u root password ‘123456a?‘
mysql -uroot -p
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456a?‘ WITH GRANT OPTION;

9、最后,把MySQL加入系统启动项和开机启动
在/etc/profile 文件中增加
export PATH=$PATH:/opt/mysql/bin
cp ./support-files/mysql.server /etc/init.d/mysqld #把Mysql加入系统启动
chmod 755 /etc/init.d/mysqld #增加执行权限
update-rc.d -f mysqld defaults #加入开机启动

错误与解决:
1、错误信息:The server quit without updating PID file
解决:配置信息可能太多,适当的删除参数
2、注意文件权限问题

centos 下编译安装mysql5.1与mysql5.5,布布扣,bubuko.com

centos 下编译安装mysql5.1与mysql5.5

上一篇:热部署Jrebel 搭建服务激活


下一篇:[转] oracle 监听