【MySQL】源码安装

操作系统:Red Hat Enterprise Linux Server release 6.5

Mysql安装包:mysql-5.6.4-m7.tar.zip,下载地址:http://pan.baidu.com/s/1hrPKZru

##安装前请确保操作系统未安装其他版本MySQL数据库(查询语句 rpm -qa|grep -i mysql)

1.安装cmake软件

1)挂载redhat安装盘

 ##不能挂载,要先去虚拟机里面点击右下角光盘按钮,连接iso镜像

[root@lgr ~]# mount /dev/cdrom /mnt

mount: block device /dev/sr0 is write-protected, mounting read-only

2)安装cmake软件

[root@lgr ~]# cd /mnt/Packages/

[root@lgr Packages]# rpm -ivh cmake-2.6.4-5.el6.x86_64.rpm

warning: cmake-2.6.4-5.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY

Preparing...                ########################################### [100%]

   1:cmake                  ########################################### [100%]

2.为mysqld增加一个登录用户和组

[root@lgr ~]# groupadd mysql

[root@lgr ~]# useradd -r -g mysql -s /bin/false mysql

3.创建源码包上传目录/soft和MySQL安装目录/usr/local/mysql,并上传源码包到/soft目录

[root@lgr ~]# mkdir /soft

[root@lgr ~]# cd /soft

----上传源码包过程略----

4.解压源码包

[root@lgr soft]# unzip mysql-5.6.4-m7.tar.zip

[root@lgr soft]# tar zxvf mysql-5.6.4-m7.tar.gz

[root@drz soft]# ll

total 55024

drwxr-xr-x. 31 7161 wheel     4096 Dec 14  2011 mysql-5.6.4-m7

-rw-r--r--.  1 root root  28582504 Dec 21  2011 mysql-5.6.4-m7.tar.gz

-rw-r--r--.  1 root root  27682410 Jan 11 12:31 mysql-5.6.4-m7.tar.zip

-rw-r--r--.  1 root root      3075 Dec 21  2011 Readme--?+?.htm

##没有后缀的是解压出来的最终安装包

5.进入安装包目录

[root@lgr soft]# cd /soft/mysql-5.6.4-m7

6.配置源码  

 

##此处可以设置选项,做定制安装,具体选项查找官方文档2.9.4

[root@lgr mysql-5.6.4-m7]# cmake ./

7.编译

[root@lgr mysql-5.6.4-m7]# make

##等到出现100%时说明已经编译完成,需要很长时间。

8.安装MySQL

[root@lgr mysql-5.6.4-m7]# make install

 

至此,MySQL安装完成,下面开始配置

 

9.配置/usr/local/mysql中文件的权限

[root@lgr ~]# cd /usr/local/mysql

[root@lgr mysql]# chown -R mysql:mysql .

 

10.创建MySQL授权表

[root@lgr mysql]# scripts/mysql_install_db --user=mysql

Installing MySQL system tables...2017-01-09 22:58:05 0 [Warning] TIMESTAMP with imp

licit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2017-01-09 22:58:05 0 [Note] Ignoring --secure-file-priv value as server is running

 with --bootstrap.

。。。略。。。

New default config file was created as ./my.cnf and

will be used by default by the server when you start it.

You may edit this file to change server settings

##如果用root运行命令,应当使用--user选项。选项的值应与你在第一步为运行服务器所创建的登录账户相同。如果用该用户登录来运行命令,可以省略--user选项。

 

11.修改/usr/local/mysql下的文件权限

[root@lgr mysql]#  chown -R root .

[root@lgr mysql]#  chown -R mysql data

 

12.配置参数文件

[root@lgr mysql]# cp support-files/my-medium.cnf /etc/my.cnf

 

13.配置数据库启动脚本

[root@lgr mysql]# cp support-files/mysql.server /etc/init.d/mysql

 

14.配置环境变量

[root@lgr mysql]# vi /etc/profile

----添加如下内容----

export PATH=$PATH:/usr/local/mysql/bin

##生效profile

[root@drz mysql]# . /etc/profile

 

15.安全模式启动数据库

[root@lgr mysql]# bin/mysqld_safe --user=mysql &

[1] 17479

[root@lgr mysql]# 170109 23:07:07 mysqld_safe Logging to '/usr/local/mysql/data/lgr

.err'.170109 23:07:07 mysqld_safe Starting mysqld daemon with databases from /usr/local/m

ysql/data

[root@lgr mysql]# netstat -an |grep :3306

tcp        0      0 :::3306                     :::*                        LISTEN

[root@lgr mysql]# ps -ef |grep mysql

root      17479   2459  0 23:07 pts/0    00:00:00 /bin/sh bin/mysqld_safe --user=mysql

 

mysql     17570  17479  3 23:07 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --bas

edir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/lgr.err --pid-file=/usr/local/mysql/data/lgr.pidroot      17595   2459  0 23:07 pts/0    00:00:00 grep mysql

16.修改root用户的密码 

[root@drz mysql]# mysqladmin -u root password

17.登录数据库

[root@lgr mysql]# mysql -u root -p

 

The End!

 

 

 

 

 

 

 

 

 

 

原文地址:https://www.cnblogs.com/NextAction/p/7366663.html