Mysql安装汇总

回复 收藏
本帖最后由 清茶一杯 于 2016-4-8 17:00 编辑

一、Mysql安装
资料下载链接: http://mirrors.sohu.com/mysql/ (请注意区分源码.tar.gz和二进制包glibc23.tar.gz的区别)
1.RPM安装方式
■RPM安装最为简单,但受诸多限制,不建议
___________________________________________________________  
[root@lab-1-C6 ~]#  yum install -y mysql




2.二进制安装方式
■进制免安装比较简单方便,适合5.0-5.1和5.5-5.6系列,推荐
___________________________________________________________   
[root@lab-1-C6 src]# tar zxvf mysql-5.1.72-linux-i686-glibc23.tar.gz
[root@lab-1-C6 src]# mv mysql-5.1.72-linux-i686-glibc23 /usr/local/mysql
[root@lab-1-C6 src]# cd ../
[root@lab-1-C6 local]# useradd -s /sbin/nologin -M mysql
[root@lab-1-C6 local]# mkdir -p /data/mysql
[root@lab-1-C6 local]# chown -R mysql:mysql /data/mysql
[root@lab-1-C6 local]# cd mysql/
[root@lab-1-C6 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql    #初始化数据
[root@lab-1-C6 src]#cp /etc/my.cnf /etc/my.cnf.bak                         #备份配置文件
[root@lab-1-C6 src]#cp support-files/my-large.cnf /etc/my.cnf            #复制配置模板到
vim /etc/my.cnf           编译MySql配置文件
#log-bin=mysql-bin            #记录查询、删除、更新数据时记录日志,配置MySql主从时需要,这里暂时不需要,先注释
#binlog_format=mixed
#server-id      = 1
[root@lab-1-C6 ~]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld    #复制启动脚本到init.d目录下
[root@lab-1-C6 ~]# vim /etc/init.d/mysqld               #编辑启动配置文件,指定数据目录
basedir=/usr/local/mysql
datadir=/data/mysql
[root@lab-1-C6 ~]#vim /etc/profile.d/path.sh         #将mysql添加进PATH路径
#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin/
[root@lab-1-C6 ~]#source !$    #更新PATH路径
[root@lab-1-C6 ~]#echo $PATH    #查看是否生效
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin/
[root@lab-1-C6 ~]#chkconfig --add mysqld             #开机启动
[root@lab-1-C6 ~]#chkconfig mysqld on
[root@lab-1-C6 ~]#/etc/init.d/mysqld start              #启动服务
Starting MySQL... SUCCESS!
[root@lab-1-C6 ~]#netstat -tnplu | grep mysql
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      1282/mysqld  
如果启动不了,请到 /data/mysql/ 下查看错误日志,这个日志通常是主机名.err.
错误1:
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决方法:
yum install  libaio-devel –y
错误2:
./bin/my_print_defaults: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
解决方法:
下载64位数据库
错误3:
Starting MySQL.Manager of pid-file quit without updating fi[FAILED]
解决方法:
vim /etc/init.d/mysqld               #编辑启动配置文件,指定数据目录
basedir=/usr/local/mysql
datadir=/data/mysql




3.常规编译安装方式
■5.0-5.1系列大多采用常规编译方式
___________________________________________________________  
[root@lab-1-C6 ~]# yum install -y gcc gcc-c++  ncurses-devel bison
[root@lab-1-C6 ~]#groupadd mysql
[root@lab-1-C6 ~]# useradd  -g mysql  -s /sbin/nologin -M mysql
[root@lab-1-C6 ~]# cd /usr/local/src/
[root@lab-1-C6 src]# tar xf mysql-5.1.72.tar.gz
[root@lab-1-C6 src]# cd mysql-5.1.72
[root@lab-1-C6 mysql-5.1.72]# ./configure --prefix=/usr/local/mysql  --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --localstatedir=/usr/local/mysql/data --enable-assembler --enable-thread-safe-client --with-mysqld-user=mysql --with-big-tables --without-debug --with-pthread --enable-assembler --with-extra-charsets=complex --with-readline
[root@lab-1-C6 mysql-5.1.72]#make && make install
[root@lab-1-C6 mysql-5.1.72]# cp support-files/my-small.cnf /etc/my.cnf
[root@lab-1-C6 mysql-5.1.72]# cd /usr/local/mysql/
[root@lab-1-C6 mysql]# chown -R mysql data
[root@lab-1-C6 mysql]# chown -R mysql:mysql /usr/local/mysql/
[root@lab-1-C6 mysql]# ./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --user=mysql
[root@lab-1-C6 mysql-5.1.72]# cp /etc/my.cnf /etc/my.cnf.bak  
[root@lab-1-C6 mysql-5.1.72]# cp support-files/my-large.cnf /etc/my.cnf
[root@lab-1-C6 mysql-5.1.72]# cp support-files/mysql.server /etc/init.d/mysqld
[root@lab-1-C6 mysql-5.1.72]# vim  /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
[root@lab-1-C6 mysql-5.1.72]# echo "export PATH=$PATH:/usr/local/mysql/bin/" >  /etc/profile.d/path.sh   
[root@lab-1-C6 mysql-5.1.72]# source /etc/profile.d/path.sh
[root@lab-1-C6 mysql-5.1.72]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
[root@lab-1-C6 mysql-5.1.72]# chkconfig --add mysqld         
[root@lab-1-C6 mysql-5.1.72]# chkconfig mysqld on
[root@lab-1-C6 mysql-5.1.72]# /etc/init.d/mysqld  start
Starting MySQL. SUCCESS!


错误1:checking for termcap functions library... configure: error: No curses/termcap library found
解决:yum –y install ncurses-devel
错误2:../include/my_global.h:1110: 错误:对 C++ 内建类型‘bool’的重声明
make[1]: *** [my_new.o] 错误 1
make[1]: Leaving directory `/usr/local/src/mysql-5.1.72/mysys'
make: *** [all-recursive] 错误 1
解决:cd .. ; rm -rf mysql-5.1.72 #删除重新编译


4.cmake编译安装方式
■5.5-5.6系列大多采用cmake编译方式
___________________________________________________________
[root@lab-2-C6 ~]# yum install gcc gcc-c++  ncurses-devel bison
[root@lab-2-C6 ~]# cd /usr/local/src/
[root@lab-2-C6 src]# tar xf cmake-2.8.8.tar.gz
[root@lab-2-C6 src]# cd cmake-2.8.8
[root@lab-2-C6 cmake-2.8.8]# ./configure
[root@lab-2-C6 cmake-2.8.8]#gmake && gmake install
[root@lab-2-C6 cmake-2.8.8]# groupadd mysql
[root@lab-2-C6 cmake-2.8.8]# useradd -g mysql -M -s /sbin/nologin mysql
[root@lab-2-C6 cmake-2.8.8]# cd /usr/local/src/
[root@lab-2-C6 src]# tar xf  mysql-5.6.28.tar.gz
[root@lab-2-C6 src]# cd mysql-5.6.28
[root@lab-2-C6 mysql-5.6.28]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii -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_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0
[root@lab-2-C6 mysql-5.6.28]#make && make install
[root@lab-2-C6 mysql-5.6.28]# chown -R mysql:mysql /usr/local/mysql   
[root@lab-2-C6 mysql-5.6.28]# chown -R mysql:mysql /usr/local/mysql/data
[root@lab-2-C6 mysql-5.6.28]# /usr/local/mysql/scripts/mysql_install_db  --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --user=mysql
[root@lab-2-C6 mysql]# cp support-files/my-default.cnf /etc/my.cnf
[root@lab-2-C6 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@lab-2-C6 mysql]#  vim  /etc/init.d/mysqld
[root@lab-2-C6 mysql]#  echo "export PATH=$PATH:/usr/local/mysql/bin/" >  /etc/profile.d/path.sh   
[root@lab-2-C6 mysql]#  source /etc/profile.d/path.sh
[root@lab-2-C6 mysql]#  echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin/
[root@lab-2-C6 mysql]#  chkconfig --add mysqld  
[root@lab-2-C6 mysql]#  chkconfig mysqld on
[root@lab-2-C6 mysql]#  /etc/init.d/mysqld  start
Starting MySQL.. SUCCESS!


错误1:remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:118 (FIND_CURSES)
  cmake/readline.cmake:214 (MYSQL_USE_BUNDLED_READLINE)
  CMakeLists.txt:269 (MYSQL_CHECK_READLINE)
解决: rm -f CMakeCache.txt ; yum install -y ncurses-devel bison
错误2:/usr/local/src/mysql-5.6.28/sql/sql_partition_admin.cc:822: undefined reference to `ha_partition::truncate_partition(Alter_info*, bool*)'
collect2: ld 返回 1
make[2]: *** [storage/perfschema/unittest/pfs_connect_attr-t] 错误 1
make[1]: *** [storage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/all] 错误 2
make: *** [all] 错误 2
解决:去掉编译参数中的-DWITHOUT_PARTITION_STORAGE_ENGINE=1,重新编译
2016-04-08 16:55 举报
已邀请:

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: