一、安装环境
Linux CentOS 6.8
二、编译安装所需编译环境 cmake
tar –axf cmake-2.8.4.tar.gz
cd cmake-2.8.4
./configure
make
make install
三、开始安装mysql
创建mysql用户和用户组
groupadd mysql
useradd –r –g mysql mysql
编译mysql
tar –axf mysql-5.6.15.tar.gz
cd mysql-5.6.15
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data/
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
编译并安装mysql
make && make install
安装mysql过程中可能出现的错误:
没有安装gcc和gcc-c++ 环境
-- 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 setCMAKE_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 orname.
解决方法:yum install –y gcc gcc-c++
没有安装bison
Warning: Bison executable not found in PATH
解决方法:安装bison
yum install bison
rm CMakeCache.txt
注:重新编译要删除CMakeCache.txt文件,否则还会报错
没有安装ncurses
removeCMakeCache.txt
and rerun cmake.On Debian/Ubuntu, package name islibncurses5-dev, on
Redhat and derivates it is ncurses-devel.
解决方法:yum install –y ncurses-devel
四、配置mysql数据库
给安装目录数据目录赋予权限:
chown -R mysql:mysql /usr/local/mysql/
chown -R mysql:mysql /usr/local/data/
初始化数据库:
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --defaults-file=/etc/my.cnf
添加开机自启动:
#复制启动项文件
cp /usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 123456 mysqld on
配置调用环境路径:(非必需)
设置PATH,要不不能直接调用mysql
修改/etc/profile文件,在文件末尾添加如下两行
PATH=/usr/local/mysql/bin:$PATH
export PATH
关闭并保存文件,运行如下命令,配置立即生效
source /etc/profile
启动mysql时可能出现的错误一:
service mysqld start
Starting MySQL.... ERROR! Theserver quit without updating PID file (/var/lib/mysql/nginx.server.com.pid).
解决方法:查看mysql的log(mysql 的log文件具体放在哪个地方可以看my.cnf文件,my.cnf一般在/etc/下or在安装MySQL的目录下)
/var/log/mysqld.log的错误信息:[ERROR]Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn'texist
查看my.cnf文件时发现datadir的路径和编译时不一样,改为datadir= 编译时配置的数据路径
可能出现的错误二:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/local/mysql/mysql.sock' (2)
解决方法:
修改my.cnf 配置文件
在配置文件中添加下面一行:
socket = /usr/local/mysql/mysql.sock (根据自己配置的路径做调整)
启动mysql成功
service mysqld start
Starting MySQL SUCCESS!
查看mysql端口:
netstat-ntlp |grep mysqld
tcp
0 0 :::3306 :::*
LISTEN 35119/mysqld #
最后给数据库的root账户设置密码:
方式一:
bin/mysqladmin-u root
passwd '123456'
方式二:
mysql -uroot
mysql> SET PASSWORD = PASSWORD('123456');
到此mysql源码编译安装就大功告成。