1.准备工作
[[email protected]]# cd /cnpc/
百度云盘 mysql-5.6.26.tar.gz链接:http://pan.baidu.com/s/1dDe9ifv 密码:ifus
[root@cnpc01 cnpc]# tar zxvf mysql-5.6.26.tar.gz //解压文件
[root@cnpc01cnpc]# ls
hadoop-2.2.0 mysql-5.6.26 mysql-5.6.26.tar.gz
[root@cnpc01cnpc]# cd mysql-5.6.26
2.必要软件包
[[email protected]]# yum -y install gccgcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt*libtool-ltdl-devel* make cmake
3.编译安装
#默认情况下是安装在/usr/local/mysql
[[email protected]]# cmake .
出错了!!!!
-- Configuring incomplete, errors occurred!
See also"/cnpc/mysql-5.6.26/CMakeFiles/CMakeOutput.log".
See also"/cnpc/mysql-5.6.26/CMakeFiles/CMakeError.log".
#如果cmake期间碰到上述错误,应该安装ncurses-develrpm包,然后移除CMakeCache.txt,反之跳过
[root@cnpc01 mysql-5.6.26]# yum -y installncurses-devel
[root@cnpc01 mysql-5.6.26]# find / -nameCMakeCache.txt
/cnpc/mysql-5.6.26/CMakeCache.txt
[root@cnpc01 mysql-5.6.26]# rm -rf/cnpc/mysql-5.6.26/CMakeCache.txt
[root@cnpc01 mysql-5.6.26]# cmake .
[[email protected]]# make && make install
注:
cmake . 的默认配置如下(不需要执行)
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
4.添加用户
[[email protected]]# groupadd mysql
[[email protected]]# useradd -r -g mysql mysql
修改目录所有者
[[email protected]]# chown -R mysql.mysql /usr/local/mysql
5.初始化数据库
[[email protected]]# cd /usr/local/mysql/scripts
[root@cnpc01scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data
6.注册服务
[root@cnpc01scripts]# cd /usr/local/mysql/support-files
[root@cnpc01 support-files]# cp mysql.server /etc/rc.d/init.d/mysql //注册服务
[root@cnpc01 support-files]# cp my-default.cnf /etc/my.cnf //使用默认配置文件
cp: overwrite `/etc/my.cnf'?y(这里得注意了,输入y覆盖,如果你直接回车,表示不覆盖,以后面启动service mysql start 可能会出现以下错误)
Starting MySQL. ERROR! Theserver quit without updating PID file (/var/lib/mysql/cnpc01.pid).
[root@cnpc01 support-files]# chkconfig --add mysql //让chkconfig管理mysql 服务
[root@cnpc01 support-files]# chkconfig mysql on //开机启动
[root@cnpc01support-files]# service mysql start
Starting MySQL.. SUCCESS! //初步启动成功
7.mySql管理员root默认密码为空,需要修改
[root@cnpc01 support-files]# /usr/local/mysql/bin/mysqladmin -u rootpassword 'newpassword '
测试连接mysql
[root@cnpc01~]# cd /usr/local/mysql/bin/
[root@cnpc01bin]# ./mysql -u root -p
Enterpassword:
Welcome to theMySQL monitor. Commands end with ; or\g.
Your MySQLconnection id is 2
Serverversion: 5.6.26 Source distribution
Copyright (c)2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is aregistered 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> showdatabases;
+--------------------+
|Database |
+--------------------+
|information_schema |
| mysql |
|performance_schema |
| test |
+--------------------+
4 rows in set(0.06 sec)
8.如果需要远程访问,执行如下语句
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
大功告成!
遇到如下错误有多种解决办法
Starting MySQL. ERROR!The server quit without updating PID file (/var/lib/mysql/cnpc01.pid).
我是使用如下 方式解决的(第4种方法),我在网上找了下资料,大概有7种,不行了就一个个试试,总会有解决的办法的
[root@cnpc01support-files]# vi /etc/my.cnf
[mysqld]
#datadir=/var/lib/mysql修改前
datadir = /usr/local/mysql/data //修改后
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disablingsymbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
1.可能是/usr/local/mysql/data/rekfan.pid文件没有写的权限
解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” “chmod -R 755 /usr/local/mysql/data” 然后重新启动mysqld!
2.可能进程里已经存在mysql进程
解决方法:用命令“ps -ef|grep mysqld”查看是否有mysqld进程,如果有使用“kill -9 进程号”杀死,然后重新启动mysqld!
3.可能是第二次在机器上安装mysql,有残余数据影响了服务的启动。
解决方法:去mysql的数据目录/data看看,如果存在mysql-bin.index,就赶快把它删除掉吧,它就是罪魁祸首了。
4.mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打开这个文件查看在[mysqld]节下有没有指定数据目录(datadir)。
解决方法:请在[mysqld]下设置这一行: datadir =/usr/local/mysql/data,参考你安装时执行的命令
./mysql_install_db--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
5.skip-federated字段问题
解决方法:检查一下/etc/my.cnf文件中有没有没被注释掉的skip-federated字段,如果有就立即注释掉吧。
6.错误日志目录不存在
解决方法:使用“chown” “chmod”命令赋予mysql所有者及权限
7.selinux惹的祸,如果是centos系统,默认会开启selinux
解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器试试。