文档章节

编译安装mysql与mysql error 解决之道

SVD
 SVD
发布于 2015/07/11 23:10
字数 1818
阅读 72
收藏 0

今天在济南出差,通过尝试编译安装mysql,使得一个诡异的问题得到解决。下面以流水的方式记述一下问题具体是怎样得到解决的。

昨天转发了一篇博文——error : The server quit without updating PID file

后来遇到了问题,error : cannot connect to local mysql server through socket (/tmp/mysql.sock)

后来辗转周折,先是删除mysql,然后用yum install mysql的方式重新安装MySQL,结果并没有得到改善。 

Linux下编译安装MySQL

下面是在 CentOS 6.5 下编译安装 MySQL 5.6.20 (作者安装的是5.6.20,然而我在按照这个地址下载mysql源码时遇到障碍,所以换了另外一个版本)

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 -version

3.安装 ncurses 和 bison

# yum -y install ncurses-devel
# yum -y install bison

4. 创建mysql组和用户

# groupadd mysql
# useradd -g mysql mysql

5. 创建数据库目录及分配访问权限

# mkdir -p /home/app/mysql
# chown -R root:mysql /home/app/mysql
# chown -R mysql:mysql /home/app/mysql/data

6. 编译安装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=/home/app/mysql -DMYSQL_DATADIR=/home/app/mysql/data -DMYSQL_BASEDIR=/home/app/mysql

最后一行命令反复折腾了我好几遍,一定要注意一些细节,比如空格的问题。

参数说明:

-DCMAKE_INSTALL_PREFIX    //安装根目录

-DINSTALL_DATADIR         //数据存储目录

-DSYSCONFDIR              //配置文件(my.cnf)目录

# make 
# make install


7. 配置 mysql

其中my-default.cnf需要结合实际情况判断,具体的文件名需要与实际相符。

# cd /home/app/mysql
# cp ./support-files/my-default.cnf /etc/my.cnf
# vi /etc/my.cnf

这一步十分关键,在 [mysqld] 段修改

basedir = /home/app/mysql
datadir = /home/app/mysql/data


保存退出编辑。


8. 初始化数据库

# cd /home/app/mysql
# ./scripts/mysql_install_db --basedir=/home/app/mysql --datadir=/home/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 mysqld

mysql_install_db这个地方需要特别注意。

9. 设置启动脚本变量 

# vi /etc/rc.d/init.d/mysqld
basedir=/home/app/mysql
datadir=/home/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: /home/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /home/app/mysql/data: is a directory
Starting MySQL.                                            [  OK  ]

12. 设置数据库管理员root密码

本来理论上我可以直接进入设置密码的环节。然而事与愿违,坑总是很多,历经千辛做了前面的那些工作,结果系统报错:MySQL: Starting MySQL….. ERROR! The server quit without updating PID file

# mysqladmin -u root password 'wushuu'

(注:在当前会话窗口操作,否则会出现 “mysqladmin: command not found” 错误,除非重新启动系统。)

终于找到了一篇可以解决我的问题的文档

This step-by-step guide is mainly for FreeBSD, however the idea is the same for Linux. Every once a while, when I update my FreeBSD box, the system likes to shutdown my MySQL server. Therefore, I need to start it again after the update is done. Unfortunately, the upgrade process is not smooth every time. Sometimes it will throw me some error.

/usr/local/etc/rc.d/mysql.server start

Oh well, I got the following error messages:

Starting MySQL..... ERROR! The server quit without updating PID file.

Sometimes, the message will tell you the exact location of which PID file:

Starting MySQL..... ERROR! The server quit without updating PID file (/var/db/mysql/www.icesquare.com.pid).

There are several solutions to troubleshoot these problems. I will go over each one by one.

Solution 1: Reboot The Computer

Although it sounds simple, but it really works. During the system upgrade, the OS may disable some of your daemons. Instead of troubleshooting each one by one, the easiest way is to start everything over. For example, I experienced this problem today after upgrading the Apache and Ruby (Yes, MySQL is not part of the update), and I got this error message afterward. After rebooting the computer, the error message is gone.

Solution 2: Remove Your MySQL Config File

If you have modified your MySQL configuration file, MySQL may not like it few versions after (MySQL is not backward compatibility friendly). It can be the problem of using an unsupported variable, or something similar. The easiest way is to remove your configuration file, and try to start the MySQL server again:

Backup your MySQL configuration first.

mv /etc/my.cnf /etc/my.cnf.backup

And restart the MySQL server again:

/usr/local/share/mysql/mysql.server start

Hopefully you will see the following message:

Starting MySQL. SUCCESS!

Solution 3: Upgrade Your Database File

Sometimes, the newer MySQL doesn’t like the database created in earlier version. I discovered this when I upgrade to MySQL 5.5.7:

Starting MySQL..... ERROR! The server quit without updating PID file (/var/db/mysql/www.icesquare.com.pid).

Since MySQL tells me which PID file causes the problem, I open the file and take a look what’s going on:

sudo tail /var/db/mysql/www.icesquare.com.err

And I saw something interesting: tables: Table ‘mysql.proxies_priv’ doesn’t exist:

101112 10:49:16 InnoDB: Initializing buffer pool, size = 128.0M 101112 10:49:16 InnoDB: Completed initialization of buffer pool 101112 10:49:16 InnoDB: highest supported file format is Barracuda. 101112 10:49:17 InnoDB: 1.1.3 started; log sequence number 1589404 101112 10:49:17 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.proxies_priv' doesn't exist 101112 10:49:17 mysqld_safe mysqld from pid file /var/db/mysql/www.icesquare.com.pid ended

 

The reason is very simple. MySQL could not open a table created in the earlier version (< 5.7.7) because it is not compatible with the current version. So, we can try to start the MySQL in safe mode through rc.d. First, you can edit the /etc/rc.conf and put the following into the file:

mysql_enable="YES" mysql_args="--skip-grant-tables --skip-networking"

Restart MySQL through rc.d:

/usr/local/etc/rc.d/mysql-server start

If you did it right, you should see something like the following:

Starting MySQL.. SUCCESS!

Now, MySQL is already running the safe-mode. We want to perform a MySQL upgrade on all tables:

sudo mysql_upgrade

You should see something like this:

Looking for 'mysql' as: mysql Looking for 'mysqlcheck' as: mysqlcheck Running 'mysqlcheck' with connection arguments: '--port=3306' '--socket=/tmp/mysql.sock' Running 'mysqlcheck' with connection arguments: '--port=3306' '--socket=/tmp/mysql.sock' mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK mysql.general_log OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.servers OK mysql.slow_log OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK mysql.time_zone_name OK mysql.time_zone_transition OK mysql.time_zone_transition_type OK mysql.user OK Running 'mysql_fix_privilege_tables'... OK

Now, we want to switch the MySQL back to normal mode by commenting the extra options in /etc/rc.conf:

mysql_enable="YES" #mysql_args="--skip-grant-tables --skip-networking"

And restart MySQL through /etc/rc.d:

/usr/local/etc/rc.d/mysql-server restart

Now the MySQL is up and running again!

Happy MySQLing.

–Derrick

重新启动服务

# service mysqld restart 
/etc/init.d/mysqld: line 46: /home/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /home/app/mysql/data: is a directory
/etc/init.d/mysqld: line 46: /home/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /home/app/mysql/data: is a directory
Shutting down MySQL.                                       [  OK  ]
/etc/init.d/mysqld: line 46: /home/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /home/app/mysql/data: is a directory
Starting 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 3
Server version: 5.6.20 Source distribution
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>


登录成功了,赶快感受一下 :)

总之,一般而言,如果是mysql.sock 的error,基本上是由于mysql service 没有启动,从而不能用socket通信的方式从终端terminal与mysql server通信;然而当你敲service mysql start之后就有可能会遇到另外一个错误,without updating pid files ,那么此时的解决之道是查看对应的和pid文件在同一个目录下的后缀为err的错误日志,然后按照本教程一步步操作即可。(/var/db/mysql/www.icesquare.com.err文件)

© 著作权归作者所有

共有 人打赏支持
SVD

SVD

粉丝 33
博文 195
码字总数 97009
作品 0
海淀
加载中

评论(1)

SVD
SVD
mysql启动时出现错误 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 解决之道
在安装PHPadmin的过程与遇到的问题及解决方法总结

1,编译安装Apache的时候没有报错,版本是httpd-2.2.29.tar.gz 2,安装MySQL时也没有报错,版本是MySQL-server-5.6.17 记得大概是的 3,编译安装PHPadmin也没有报错 3,编译安装PHP时,出现报...

皖教育厅长
2015/01/08
0
0
阿里云 Centos 7 PHP7环境配置 LNMP

阿里云 Centos 7 PHP7环境配置 LNMP (centos7+nginx+MySQL5.7.9+PHP7) 首先更新系统软件</str> $ yum update 安装nginx</str></str> 1.安装nginx源 $ yum localinstall http://nginx.org/pa......

小田天
2016/11/21
0
0
阿里云里Centos 7 PHP7环境配置 LNMP

首先更新系统软件 $ yum update 安装nginx 1.安装nginx源 $ yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 2.安装nginx $......

听风讲你
2017/05/19
0
0
源码编译mysql5.5过程记录

官网安装教程: http://dev.mysql.com/doc/refman/5.5/en/installing-source-distribution.html CentOS6.3源码安装mysql-5.5.27 #mysql5.5以上使用cmake代替configure编译,首先需要安装cma......

shezjl
2015/08/31
0
0
LAMP之mysql的安装

前言:参照阿铭的安装方法进行安装。 安装包下载:链接:http://pan.baidu.com/s/1gf7GBab 密码:gdqn 一、安装mysql cd /usr/local/src/ #进入安装包路径,可自己选择上传安装包路径 tar zx...

abiu
2016/09/29
0
0

没有更多内容

加载失败,请刷新页面

加载更多

各种开源汇编、反汇编引擎的非专业比较

由于平时业余兴趣和工作需要,研究过并使用过时下流行的各种开源的x86/64汇编和反汇编引擎。如果要对汇编指令进行分析和操作,要么自己研究Intel指令集写一个,要么就用现成的开源引擎。自己...

simpower
18分钟前
3
0
(4)添加vue-router

(4)添加vue-router 1 安装vue-router cnpm install vue-router --save 2 页面准备 新建目录/src/views/common,此目录下面建立4个组件404.vue、home.vue、login.vue、theme.vue。每个文件...

neumeng
20分钟前
2
0
高可用性系统在大众点评的实践与经验

背景 所谓高可用性指的是系统如何保证比较高的服务可用率,在出现故障时如何应对,包括及时发现、故障转移、尽快从故障中恢复等等。本文主要以点评的交易系统的演进为主来描述如何做到高可用...

Skqing
28分钟前
3
0
Network protocols

The network stack does serveral seemingly-impossible things. It does reliable transmission over our unreliable networks, usually without any detactable hiccups. It adapts smooth......

nao
29分钟前
1
0
Android 生命周期方法

1,onCreate(); 2,onStart(); 3,onResume(); //打开页面,前三个方法自动执行 4,onPause(); 5,onStop(); //打开其他页面,前一个页面执行这俩方法 6,onRestart(); //onStart(),onResume //当关闭...

lanyu96
36分钟前
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部