Linux下编译安装MySQL
下面是在 CentOS 6.5 下编译安装 MySQL 5.6.20 。
1. 首先卸载系统自带的 mysql# yum remove mysql 2.安装cmake 下载cmake源码# wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz# tar xzfv cmake-2.8.5.tar.gz# cd cmake-2.8.5# ./configure( 如果提示没安装C++编译器就先安装C++编译器:# yum -y install gcc-c++ )# make # make install查看 cmake 版本# cmake -version3.安装 ncurses 和 bison# yum -y install ncurses-devel# yum -y install bison4. 创建mysql组和用户# groupadd mysql# useradd -g mysql mysql 5. 创建数据库目录及分配访问权限# mkdir -p /u01/app/mysql# chown -R root:mysql /u01/app/mysql# chown -R mysql:mysql /u01/app/mysql/data6. 编译安装mysql下载mysql源码# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz# tar xzfv mysql-5.6.20.tar.gz# cd mysql-5.6.20# cmake . -DCMAKE_INSTALL_PREFIX=/u01/app/mysql -DMYSQL_DATADIR=/u01/app/mysql/data -DSYSCONFDIR=/etc参数说明:-DCMAKE_INSTALL_PREFIX //安装根目录-DINSTALL_DATADIR //数据存储目录-DSYSCONFDIR //配置文件(my.cnf)目录# make # make install7. 配置 mysql# cd /u01/app/mysql# cp ./support-files/my-default.cnf /etc/my.cnf # vi /etc/my.cnf在 [mysqld] 段修改basedir = /u01/app/mysqldatadir = /u01/app/mysql/data保存退出编辑。8. 初始化数据库# cd /u01/app/mysql# ./scripts/mysql_install_db --basedir=/u01/app/mysql --datadir=/u01/app/mysql/data --defaults-file=/etc/my.cnf --user=mysql# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld# chmod 755 /etc/rc.d/init.d/mysqld# chkconfig --add mysqld9. 设置启动脚本变量 # vi /etc/rc.d/init.d/mysqldbasedir=/u01/app/mysqldatadir=/u01/app/mysql/data保存退出。10. 设置变量环境# echo "PATH=$PATH:/u01/app/mysql/bin" >> /etc/profile (永久生效)# export PATH=$PATH:/u01/app/mysql/bin (当前生效)11. 启动服务# service mysqld start/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directoryStarting MySQL. [ OK ]如果这一步出现错误:Starting MySQL. ERROR! The server quit without updating PID file
除了网络搜索到的常见kill进程等方法之外,如果不起作用可参考以下页面的方法:
http://blog.sina.com.cn/s/blog_637e04c9010117ri.html
尝试了其中的solution 2 移除配置文件解决了问题
12. 设置数据库管理员root密码# mysqladmin -u root password '123456'(注:在当前会话窗口操作,否则会出现 “mysqladmin: command not found” 错误,除非重新启动系统。)重新启动服务# service mysqld restart /etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directoryShutting down MySQL. [ OK ]/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directoryStarting MySQL. [ OK ]13. 进入 MySQL# mysql -u root -p(注:在当前会话窗口操作,否则会出现 “mysql: command not found” 错误,除非重新启动系统。)Enter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.6.20 Source distributionCopyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 登录成功了,赶快感受一下 :)mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> select Host,User,Password from user; +-----------------------+------+-------------------------------------------+| Host | User | Password |+-----------------------+------+-------------------------------------------+| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || localhost.localdomain | root | || 127.0.0.1 | root | || ::1 | root | || localhost | | || localhost.localdomain | | |+-----------------------+------+-------------------------------------------+6 rows in set (0.00 sec)mysql>