实验环境:
CentOS 6.5
mysql-5.5.44.tar.gz
环境部署:
yum -y install gcc gcc-c++ make cmake ncurses-devel bison perl lrzsz
useradd -s /sbin/nologin mysql
mkdir -p /data/sqldata
chown -R mysql. /data/sqldata
tar zxf mysql-5.5.44.tar.gz
cd mysql-5.5.44
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/sqldata \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_USER=mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
*********************************************************************************
在cmake 时,有时并不那么顺利,会出现各种报错,这里来举例几种:
1.没有安装 gcc 和 gcc-c++,执行cmake报如下错误:
==================================================
[root@ice mysql-5.5.27]# cmake .
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
.
.
.
-- Configuring incomplete, errors occurred!
==================================================
解决方法:安装gcc和gcc-c++
yum install gcc
yum install gcc-c++
#删除cache文件,不删除还会报错
rm CMakeCache.txt
cmake .
2.编译快结束时,又报如下错误:
Warning: Bison executable not found in PATH
==================================================
解决方法:安装bison
yum install bison
rm CMakeCache.txt
cmake .
#编译通过
make && make install
#执行时间比较长
3.无法登陆mysql
提示找不到mysql.sock文件
======================================================
解决方法:
/usr/local/mysql/bin/mysql -uroot -p123456 -S /tmp/mysql.sock
*************************************************************************************
make && make install ;echo $?
chown -R mysql. /usr/local/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
修改配置文件,添加以下语句
vim /etc/my.cnf
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/sqldata --basedir=/usr/local/mysql
如图,出现两个OK证明初始化成功
至此,数据库安装完成,可以通过命令启动数据库:
/etc/init.d/mysqld start
设置开机启动
chkconfig --add mysqld
chkconfig --level 35 mysqld on
如果不能登陆,请指定mysql.sock 文件
/usr/local/mysql/bin/mysql -S /data/sqldata/mysql.sock
或者
/usr/local/mysql/bin/mysqladmin -uroot password '123456'
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/sqldata/mysql.sock
可以创建mysql启动脚本,连接脚本以及关闭脚本
启动脚本:
cat mysql_start.sh
#!/bin/bash
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
连接脚本:
cat mysql_conn.sh
#!/bin/bash
/usr/local/mysql/bin/mysql -uroot -p'123456' -S /data/sqldata/mysql.sock
关闭脚本:
cat mysql_stop.sh
#!/bin/bash
/usr/local/mysql/bin/mysqladmin -uroot -p'123456' shutdown -S /data/sqldata/mysql.sock