我的机器:CentOS 6.7 64位(minimal安装)
安装的MySQL: MySQL 5.6
安装过程充满坎坷……(缺少实践)
下载
使用免编译二进制包
[[email protected] ~]# cd /usr/local/src
[[email protected] src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz
这里的链接可能会失效,可以去http://mirrors.sohu.com/mysql/找所需的版本,看清MySQL的版本,选择合适的包下载
可能出现的报错信息
-bash: wget: command not found
解决方案
[[email protected] src]# yum -y install wget
[[email protected] src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz
初始化
[roo[email protected] src]# tar zxvf mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz
[[email protected] src]# useradd -s /sbin/nologin -M mysql
[[email protected] src]# mv mysql-5.6.29-linux-glibc2.5-x86_64 /usr/local/mysql
[[email protected] src]# cd /usr/local/mysql
[[email protected] mysql]# mkdir -p /data/mysql
[[email protected] mysql]# chown -R mysql /data/mysql
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=data/mysql
–user 定义数据库的所属主, –datadir 定义数据库安装路径
这里的最后一步有点问题,导致我启动MySQL时报错,后面会给出解决方法
如果遇到错误,请检查下载的包是否合适,此处不说明
可能出现的错误
-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: 没有那个文件或目录
除了下载的包不合适的原因外,还可能是其他原因
解决方案
[[email protected] mysql]# yum -y install perl perl-devel
[[email protected] mysql]# yum -y install libaio
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=data/mysql
[[email protected] mysql]# echo $?
echo $?用于检查上条命令是否执行成功,为0表示正常(记得C语言的return 0么)
配置
[[email protected] mysql]# cd support-files/
[[email protected] support-files]# ls
binary-configure my-default.cnf mysql-log-rotate
magic mysqld_multi.server mysql.server
[[email protected] support-files]# cp my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[[email protected] support-files]# cp mysql.server /etc/init.d/mysqld
[[email protected] support-files]# vim !$
可能出现的错误
vim /etc/init.d/mysqld
-bash: vim: command not found
解决方案
[[email protected] support-files]# yum -y install vim*
[[email protected] support-files]# vim /etc/init.d/mysqld
在/etc/init.d/mysqld文件中修改如下内容
basedir=/usr/local/mysql
datadir=/data/mysql
basedir: MySQL的安装路径
datadir:MySQL的数据库文件安装路径
启动
[[email protected] support-files]# chkconfig --add mysqld
[[email protected] support-files]# chkconfig mysqld on
[[email protected] support-files]# /etc/init.d/mysqld start
如果启动不了,我就卡在这好长时间,尝试了各种解决方案……
报错信息
Starting MySQL... ERROR! The server quit without updating PID file (/data/mysql/bogon.pid).
解决方案
[[email protected] support-files]# cd /data/mysql
[[email protected] mysql]# ls
auto.cnf bogon.err ibdata1 ib_logfile0 ib_logfile1
[[email protected] mysql]# vi bogon.err
到/data/mysql下查看错误日志
后来了解到:
在CentOS操作系统的最小安装(其他安装方式应该也是这样)完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字或者删除,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
那我把my.cnf删除,再重新复制一份my-default.cnf
[[email protected] mysql]# cd /etc/
[[email protected] etc]# ls
[[email protected] etc]# rm my.cnf
rm:是否删除普通文件 "my.cnf"?y
[[email protected] etc]# cd /usr/local/mysql/
[[email protected] mysql]# cd support-files/
[[email protected] support-files]# ls
binary-configure my-default.cnf mysql-log-rotate
magic mysqld_multi.server mysql.server
[[email protected] support-files]# cp my-default.cnf /etc/my.cnf
[[email protected] support-files]# cd /usr/local/mysql/
执行命令
./scripts/mysql_install_db --user=mysql --datadir=data/mysql --basedir=usr/local/mysql
再次报错
FATAL ERROR: Could not find my-default.cnf
命令敲错了……
执行命令
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql/
看出这条和上条的不同了没
貌似还得编辑一下配置文件,我的/etc/my.cnf里除注释外什么都没有…..
[[email protected] mysql]# vi /etc/my.cnf
把该注释掉的注释掉,该填的内容填上
接着重新来一遍吧
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
[[email protected] mysql]# service mysqld start
Starting MySQL.. SUCCESS!
[[email protected] mysql]# ps aux|grep mysql
root 3900 0.0 0.1 11304 1500 pts/2 S 06:03 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/bogon.pid
mysql 4127 0.1 44.8 1011200 454300 pts/2 Sl 06:03 0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/bogon.err --pid-file=/data/mysql/bogon.pid --socket=/tmp/mysql.sock --port=3306
root 4153 0.0 0.0 103316 896 pts/2 S+ 06:19 0:00 grep mysql