centos下mysql 5源码安装全过程记录

Posted 菜鸡啄米米

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos下mysql 5源码安装全过程记录相关的知识,希望对你有一定的参考价值。

参考:http://blog.csdn.net/mycwq/article/details/24488691

 

  1. 安装cmake,mysql 5.5以后的版本要通过cmake进行编译

在新装的CentOS 5.7系统中,先安装了nginx(含nginx必备依赖:gzip 模块需要 zlib 库;rewrite 模块需要 pcre 库;ssl 功能需要 openssl 库),结果安装cmake过程中在./bootstrap这一步无法通过,原因未知。后通过VM快照恢复到未安装nginx前,顺利安装cmake。

安装步骤:

  1. 官网下载http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
  2. tar zxvf cmake-2.8.10.2.tar.gz
  3. cd cmake-2.8.10.2     
  4. ./bootstrap
  5. make
  6. make install
  7. cmake –h      验证安装结果

 

  1. 开始安装mysql

官网下载源码安装包:https://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.57.tar.gz

安装mysql

  1.  [[email protected] ~]# wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.37.tar.gz  
  2. [[email protected] ~]# tar xvf mysql-5.5.37.tar.gz  
  3. [[email protected] ~]# cd mysql-5.5.37  
  4. [[email protected] mysql-5.5.37]# cmake ./  

可能还会报这个错,没有就跳过 

  1. CMake Error at cmake/readline.cmake:83(MESSAGE):  
  2. Curses library not found.  Pleaseinstall appropriate package,  
  3. remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name islibncurses5-dev, on Redhat and derivates it is ncurses-devel.  
  4. Call Stack (most recent call first):  
  5.  cmake/readline.cmake:127 (FIND_CURSES)  
  6.  cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT)  
  7.  CMakeLists.txt:355 (MYSQL_CHECK_READLINE  
  8. -- Configuring incomplete, errors occurred!  
  9. See also "/root/my/mysql-5.5.37/CMakeFiles/CMakeOutput.log".  
  10. See also"/root/my/mysql-5.5.37/CMakeFiles/CMakeError.log".  

说明centos系统没有ncurses-devel

  1.  [[email protected] ~]# wget http://invisible-island.net/datafiles/release/ncurses.tar.gz  
  2. [[email protected] ~]# cd ncurses-5.9  
  3. [[email protected] ncurses-5.9]#./configure  
  4. [[email protected] ncurses-5.9]# make  
  5. [[email protected] ncurses-5.9]# make install  

再删除刚才编译生成的 CMakeCache.txt 文件,否则无法进行下一步

  1.  [[email protected] mysql-5.5.37]# rm -f CMakeCache.txt  

继续编译mysql

  1.  [[email protected] ~]# cmake ./  
  2. [[email protected] ~]# make  
  3. [[email protected] ~]# make install  

这样,mysql默认将成功安装到/usr/local/mysql

 

创建mysql用户组

  1.  [[email protected] ~]# groupadd mysql  
  2. [[email protected] ~]# useradd –r –g mysql mysql  
  3. [[email protected] ~]# chown –R mysql.mysql /usr/local/mysql  


启动mysql

  1.  [[email protected] ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql  

这里可能会发生错误,没有就跳过:

  1. FATAL ERROR: Could not find./bin/my_print_defaults  
  2. If you compiled from source, you need torun ‘make install‘ to  
  3. copy the software into the correct locationready for operation.  
  4. If you are using a binary release, you musteither be at the top  
  5. level of the extracted archive, or pass the --basedir option  
  6. pointing to that location.  

解决方法:

  1.  [[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data  

再启动mysql

  1.  [[email protected] ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql  

 

注册mysql服务,开机自动启动

 1.设置mysql配置文件到/etc目录

  1.  [[email protected] ~]# cp /usr/local/mysql/support-files/my-medium.cnf/etc/my.cnf  

2.设置mysql开机自启

  1.  [[email protected] ~]# cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysql  
  2. [[email protected] ~]# chmod +x /etc/init.d/mysql  
  3. [[email protected] ~]# /sbin/chkconfig --add mysql  

3.启动mysql服务

  1.  [[email protected] ~]# service mysql start  

 

测试mysql是否安装成功

  1.  [[email protected] ~]# /usr/local/mysql/bin/mysql -u root -p  
  2. Enter password:   
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  4. Your MySQL connection id is 1  
  5. Server version: 5.5.37 Source distribution  
  6.    
  7. Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.  
  8.    
  9. Oracle is a registered trademark of OracleCorporation and/or its  
  10. affiliates. Other names may be trademarksof their respective  
  11. owners.  
  12.    
  13. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ toclear the current input statement.  
  14.    
  15. mysql> show databases;  
  16. +--------------------+  
  17. | Database           |  
  18. +--------------------+  
  19. | information_schema |  
  20. | mysql              |  
  21. | performance_schema |  
  22. | test               |  
  23. +--------------------+  
  24. 4 rows in set (0.03 sec)  

 

参考:

http://blog.csdn.net/mycwq/article/details/24488691

最后启动mysql的时候报错,出现The server quit without updating PID file错误

解决过程:http://blog.sina.com.cn/s/blog_637e04c9010117ri.html

[[email protected] ~]# cd /usr/local/mysql

[[email protected] mysql]# chown -R mysql.mysql .
[[email protected] mysql]# su - mysql
[[email protected] ~]$ cd /usr/local/mysql
[[email protected] mysql]$ scripts/mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password ‘new-password‘
./bin/mysqladmin -u root -h localhost.localdomain password ‘new-password‘

Alternatively you can run:
./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems with the ./bin/mysqlbug script!

[[email protected] mysql]$ /usr/local/mysql/bin/mysqld_safe --user=mysql &
[1] 11767
[[email protected] mysql]$ 120502 07:01:17 mysqld_safe Logging to ‘/usr/local/mysql/data/localhost.localdomain.err‘.
120502 07:01:17 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[[email protected] mysql]$ /etc/rc.d/init.d/mysql status
MySQL running (11830)                                     [  OK  ]
[[email protected] mysql]$ /etc/rc.d/init.d/mysql start
Starting MySQL                                             [  OK  ]

最后这里↗$ /etc/rc.d/init.d/mysql start可能需要切回root用户才能成功启动

 

额外配置

如果非本地环境无法登陆mysql,做如下更改

1.Centos中防火墙开放3306端口:

-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT

2.Mysql中允许root用户任意IP登陆:

Update user set host=”%” where user=”root”;

3. mysql取消表名区分大小写

修改 /etc/my.cnf:在[mysqld]节点下,加入一行: lower_case_table_names=1

4.使用mysql-workbench工具导入.sql文件

 
























以上是关于centos下mysql 5源码安装全过程记录的主要内容,如果未能解决你的问题,请参考以下文章

CentOS6.5+mysql5.1源码安装过程

linux 源码安装mysql 5.5

CentOS 6.6 下源码编译安装MySQL 5.7.5

CentOS 6.5下源码安装MySQL 5.6

mysql5.7.10 源码编译安装记录 (centos6.4)

CentOS 7中源码安装MySQL 5.7.6