文档章节

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

SVD
 SVD
发布于 2015/07/11 23:10
字数 1818
阅读 77
收藏 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文件)

© 著作权归作者所有

上一篇: cpuinfo
下一篇: 德雷福斯模型
SVD

SVD

粉丝 34
博文 209
码字总数 103064
作品 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

首先更新系统软件 $ 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
阿里云 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
Mysql 升级到 5.5 GA 时,PHP 5.2.6 编译出错!已解决!

今天把原来的 Mysql 5.1.35 升级至 Mysql 5.5 GA 由于 Mysql-Dev 也一同更新了。 所以必须重新编译 PHP 5.2.6 环境。 但编译出错,出现以下各种错误。 而最终的解决方式,是升级 PHP 至最新的...

范堡
2010/12/16
986
1
Liunx笔记:zabbix编译安装

Liunx笔记:zabbix编译安装 前言 之前的yum安装是方便。简单。但是呢,不方便升级。此处来个编译安装。 1.基础环境准备 [root@Aige ~]# cat /etc/redhat-release CentOS release 6.8 (Final...

segastar660
2018/06/29
0
0

没有更多内容

加载失败,请刷新页面

加载更多

阿里云POLARDB如何助力轻松筹打造5亿用户信赖的大病筹款平台?

轻松筹首创了“大病救助”模式,帮助了众多病患在第一时间解決了医疗资金等问题,为了从源头解决了医疗资金问题。而在轻松筹这样全球5.5亿用户信赖的大病筹款平台的背后,是日益增长的各种数...

阿里云云栖社区
12分钟前
3
0
Confluence 6 在升级过程中查看合并日志

为了监控升级的过程,你应该查看 application log 日志中的输出。 通常日志经常将会显示多个日志实例,这个实例是定义在日志的 INFO 级别的,通常格式如下: WikiToXhtmlMigrationThread-n -...

honeymoose
12分钟前
1
0
git diff 文件对比

git diff filepath 工作区与暂存区比较 git diff HEAD filepath 工作区与HEAD ( 当前工作分支) 比较 git diff --staged 或 --cached filepath 暂存区与HEAD比较 git diff branchName filepa......

李佳顺
13分钟前
1
0
spring mvc 定制化配置

spring mvc 自定义配置 1.实现某些接口,然后让上面的类加载进去. class MyHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public boolean......

最爱肉肉
15分钟前
1
0
OSG_采样像机的内容如果不显示到窗口上

cameraLight->setRenderTargetImplementation(Camera::FRAME_BUFFER_OBJECT);// 这句使内容不渲染到屏幕上cameraLight->setRenderOrder(Camera::PRE_RENDER); 1.setRenderTargetImplement......

洛克人杰洛
19分钟前
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部