mysql 5.5.37_编译安装mysql-5.5.37

一、环境

系统:CentOS 6.4x64最小化安装

IP:192.168.3.54

二、安装基础软件包[root@httpd conf]# yum -y install make gcc-c++ cmake bison-devel  ncurses-devel

三、安装mysql

1.创建用户[root@httpd ~]# groupadd mysql

[root@httpd ~]# useradd -g mysql mysql -s /sbin/nologin

2.解压软件包[root@httpd ~]# tar xf mysql-5.5.37.tar.gz

3.编译配置参数#创建用来存放Mysql数据的目录

[root@httpd ~]# mkdir -p /data/mysql/data

[root@httpd ~]# cd mysql-5.5.37

[root@httpd mysql-5.5.37]# cmake \

> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.37 \

> -DMYSQL_DATADIR=/data/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

[root@httpd mysql-5.5.37]# make && make install

4.数据目录初始化[root@httpd mysql-5.5.37]# cd /usr/local/mysql-5.5.37/

[root@httpd mysql-5.5.37]# scripts/mysql_install_db --datadir=/data/mysql/data/ --user=mysql --basedir=/usr/local/mysql-5.5.37/

Installing MySQL system tables...

OK

Filling help tables...

OK                            #到这里显示的有2个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:

/usr/local/mysql-5.5.37//bin/mysqladmin -u root password 'new-password'

/usr/local/mysql-5.5.37//bin/mysqladmin -u root -h httpd password 'new-password'

Alternatively you can run:

/usr/local/mysql-5.5.37//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 /usr/local/mysql-5.5.37/ ; /usr/local/mysql-5.5.37//bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/local/mysql-5.5.37//mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

5.复制mysql配置文件[root@httpd mysql-5.5.37]# cp -rf support-files/my-large.cnf /etc/my.cnf

6.创建启动脚本[root@httpd mysql-5.5.37]# cp support-files/mysql.server /etc/init.d/mysqld

[root@httpd mysql-5.5.37]# chmod +x /etc/init.d/mysqld

[root@httpd mysql-5.5.37]# /etc/init.d/mysqld start

Starting MySQL.. SUCCESS!

[root@httpd mysql-5.5.37]# netstat -anpt |grep mysql

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      21814/mysqld

7.连接到数据库[root@httpd ~]# which mysql

/usr/bin/which: no mysql in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)

#配置软连接

[root@httpd ~]# ln -s /usr/local/mysql-5.5.37/ /usr/local/mysql

[root@httpd ~]# ln -s /usr/local/mysql-5.5.37/bin/* /usr/sbin/

[root@httpd ~]# which mysql

/usr/sbin/mysql

连接到数据库

[root@httpd ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.5.37-log 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>

#默认的情况下是没有密码的,设置root账号的密码,设置密码是ly36843

mysql> update user set password=password('lyao36843') where host="localhost" and user="root";

Query OK, 1 row affected (0.03 sec)

Rows matched: 1  Changed: 1  Warnings: 0

mysql> update user set password=password('lyao36843') where host="127.0.0.1" and user="root";

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

mysql> select user,host,password from mysql.user;

+------+-----------+-------------------------------------------+

| user | host      | password                                  |

+------+-----------+-------------------------------------------+

| root | localhost | *B181A5BCA7C882221F5B8F6F9657AE71FF67EDDB |

| root | httpd     |                                           |

| root | 127.0.0.1 | *B181A5BCA7C882221F5B8F6F9657AE71FF67EDDB |

| root | ::1       |                                           |

|      | localhost |                                           |

|      | httpd     |                                           |

+------+-----------+-------------------------------------------+

6 rows in set (0.00 sec)

#清除mysql用户表中不安全的用户

mysql> delete from mysql.user where password='';

Query OK, 4 rows affected (0.03 sec)

mysql> select user,host,password from mysql.user;

+------+-----------+-------------------------------------------+

| user | host      | password                                  |

+------+-----------+-------------------------------------------+

| root | localhost | *B181A5BCA7C882221F5B8F6F9657AE71FF67EDDB |

| root | 127.0.0.1 | *B181A5BCA7C882221F5B8F6F9657AE71FF67EDDB |

+------+-----------+-------------------------------------------+

2 rows in set (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

#退出数据库重新连接

[root@httpd ~]# mysql -u root -p -h 127.0.0.1

Enter password:                 #输入之前设置的mysql数据库密码

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.5.37-log 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>

8.最后将mysql添加到开机自动启动[root@httpd ~]# chkconfig --add mysqld

[root@httpd ~]# chkconfig mysqld on

[root@httpd ~]# chkconfig mysqld --list

mysqld         0:off1:off2:on3:on4:on5:on6:off

让MySQL命令行提示符显示当前所在数据库,在my.cnf配置文件中添加如下参数[mysql]                    #该内容一定要添加在这一段下面

prompt=(\\u@\\h) [\\d]>\\

最后附上mysql安装脚本,mysql安装文件需要实现下载好,不同的版本只需要更改变量VERSION即可

,该脚本在运行时,需要提供mysql的root账号密码。#!/bin/bash

DATADIR='/data/mysql/data'

VERSION='mysql-5.5.37'

export LANG=zh_CN.UTF-8

#Source function library.

. /etc/init.d/functions

#camke install mysql5.5.X

install_mysql(){

read -p "please input a password for root: " PASSWD

if [ ! -d $DATADIR ];then

mkdir -p $DATADIR

fi

yum install cmake make gcc-c++ bison-devel ncurses-devel -y

id mysql &>/dev/null

if [ $? -ne 0 ];then

useradd mysql -s /sbin/nologin -M

fi

#useradd mysql -s /sbin/nologin -M

#change datadir owner to mysql

chown -R mysql.mysql $DATADIR

cd

#wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.38.tar.gz

tar xf $VERSION.tar.gz

cd $VERSION

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/$VERSION \

-DMYSQL_DATADIR=$DATADIR \

-DMYSQL_UNIX_ADDR=$DATADIR/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DENABLED_LOCAL_INFILE=ON \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

-DWITHOUT_PARTITION_STORAGE_ENGINE=1

make && make install

if [ $? -ne 0 ];then

action "install mysql is failed"  /bin/false

exit $?

fi

sleep 2

#link

ln -s /usr/local/$VERSION/ /usr/local/mysql

ln -s /usr/local/mysql/bin/* /usr/bin/

#copy config and start file

/bin/cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

chmod 700 /etc/init.d/mysqld

#init mysql

/usr/local/mysql/scripts/mysql_install_db  --basedir=/usr/local/mysql --datadir=$DATADIR --user=mysql

if [ $? -ne 0 ];then

action "install mysql is failed"  /bin/false

exit $?

fi

#check mysql

/etc/init.d/mysqld start

if [ $? -ne 0 ];then

action "mysql start is failed"  /bin/false

exit $?

fi

chkconfig --add mysqld

chkconfig mysqld on

/usr/local/mysql/bin/mysql -e "update mysql.user set password=password('$PASSWD') where host='localhost' and user='root';"

/usr/local/mysql/bin/mysql -e "update mysql.user set password=password('$PASSWD') where host='127.0.0.1' and user='root';"

/usr/local/mysql/bin/mysql -e "delete from mysql.user where password='';"

/usr/local/mysql/bin/mysql -e "flush privileges;"

#/usr/local/mysql/bin/mysql -e "select version();" >/dev/null 2>&1

if [ $? -eq 0 ];then

echo "+---------------------------+"

echo "+------mysql安装完成--------+"

echo "+---------------------------+"

fi

#/etc/init.d/mysqld stop

}

install_mysql

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值