欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

RHEL6.2编译安装MySQL 5.6.16过程分享

程序员文章站 2024-03-01 19:25:10
一、环境说明: 复制代码 代码如下: [root@beanvm ~]# cat /etc/redhat-release red hat enterprise linu...

一、环境说明:

复制代码 代码如下:

[root@beanvm ~]# cat /etc/redhat-release
red hat enterprise linux server release 6.2 (santiago)
[root@beanvm ~]# uname -a
linux beanvm 2.6.32-220.el6.i686 #1 smp wed nov 9 08:02:18 est 2011 i686 i686 i386 gnu/linux

二、准备工作与系统配置

1.下载安装包

这里下载的是较新的mysql 5.6.16版本,更新迭代的太快了,文件为:mysql-5.6.16.tar.gz

下载地址:

2. 安装编译必须的包

复制代码 代码如下:

[root@beanvm ~]# rpm -ivh bison-devel-2.4.1-5.el6.i686.rpm
warning: bison-devel-2.4.1-5.el6.i686.rpm: header v3 rsa/sha256 signature, key id c105b9de: nokey
preparing...                ########################################### [100%]
   1:bison-devel            ########################################### [100%]
[root@beanvm ~]# rpm -ivh ncurses-devel-5.7-3.20090208.el6.i686.rpm
warning: ncurses-devel-5.7-3.20090208.el6.i686.rpm: header v3 rsa/sha256 signature, key id fd431d51: nokey
preparing...                ########################################### [100%]
   1:ncurses-devel          ########################################### [100%]

个人经验上面两个包是比较容易缺失,像gcc,make,cmake则是必备的了,也建议检查一下:

复制代码 代码如下:

[root@beanvm ~]# rpm -qa |grep gcc-c++
gcc-c++-4.4.6-3.el6.i686
[root@beanvm ~]# rpm -qa |grep make
imake-1.0.2-11.el6.i686
automake-1.11.1-1.2.el6.noarch
cmake-2.6.4-5.el6.i686
make-3.81-19.el6.i686

3.创建mysql用户和组

复制代码 代码如下:

[root@beanvm ~]# groupadd mysql
[root@beanvm ~]# useradd -g mysql mysql
[root@beanvm ~]# passwd mysql

4.配置环境变量

复制代码 代码如下:

[root@beanvm ~]# su – mysql

在.bash_profile文件中为path变量追加mysql路径:

复制代码 代码如下:
export path=/sbin:$home/bin:/usr/local/mysql/bin:$path

三、安装mysql

解压安装包:

复制代码 代码如下:
[root@beanvm ~]# tar -xvf mysql-5.6.16.tar.gz
[root@beanvm ~]# cd mysql-5.6.16

编译脚本如下:

复制代码 代码如下:

cmake \
# mysql根目录
-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

make && make install

基本上安装的选项还是一目了然的,更多的选项示意参见:

编译时间是机器而定,我的有20多分钟的样子。

安装完成后要给根目录指定为mysql用户和组,也可以在这时候进行mysql用户和组的创建工作:

复制代码 代码如下:

[root@beanvm ~]# chown -r mysql:mysql /usr/local/mysql

安装完成的mysql根目录如下:

复制代码 代码如下:

[root@beanvm ~]# ls -l /usr/local/mysql/
total 164
drwxr-xr-x.  2 mysql mysql  4096 feb 15 14:40 bin
-rw-r--r--.  1 mysql mysql 17987 jan 14 23:38 copying
drwxr-xr-x.  6 mysql mysql  4096 feb 18 16:32 data
drwxr-xr-x.  2 mysql mysql  4096 feb 15 14:39 docs
drwxr-xr-x.  3 mysql mysql  4096 feb 15 14:39 include
-rw-r--r--.  1 mysql mysql 88109 jan 14 23:38 install-binary
drwxr-xr-x.  3 mysql mysql  4096 feb 15 14:39 lib
drwxr-xr-x.  4 mysql mysql  4096 feb 15 14:40 man
-rw-r--r--.  1 mysql mysql   943 feb 15 14:56 my.cnf
-rw-r--r--.  1 mysql mysql   943 feb 18 16:26 my-new.cnf
drwxr-xr-x. 10 mysql mysql  4096 feb 15 14:40 mysql-test
-rw-r--r--.  1 mysql mysql  2496 jan 14 23:38 readme
drwxr-xr-x.  2 mysql mysql  4096 feb 15 14:40 scripts
drwxr-xr-x. 28 mysql mysql  4096 feb 15 14:40 share
drwxr-xr-x.  4 mysql mysql  4096 feb 15 14:40 sql-bench
drwxr-xr-x.  3 mysql mysql  4096 feb 15 14:40 support-files

可以看到已经创建一个默认的配置文件my.cnf。

四、mysql初始化

执行初始化脚本来创建数据库:

复制代码 代码如下:

[root@beanvm ~]# cd /usr/local/mysql/scripts/
[root@beanvm scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

创建mysql服务并启动:

复制代码 代码如下:

[root@beanvm ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@beanvm ~]# service mysql start
starting mysql.. success!

接下来就是配置数据库了,在新版的mysql安装过程中提供了一个脚本用于自动完成数据库使用前的配置工作,这个脚本位于/usr/local/mysql/bin/mysql_secure_installation,它会完成以下任务:


1.指定root用户密码(默认是没有密码的)
2.删除匿名用户
3.设置root用户的远程访问(对应的要在防火墙中开启3306端口)
4.是否删除测试数据库
5.重载权限表

这里建议使用这个脚本,执行过程如下:

复制代码 代码如下:

[mysql@beanvm ~]$ /usr/local/mysql/bin/mysql_secure_installation

note: running all parts of this script is recommended for all mysql
      servers in production use!  please read each step carefully!

in order to log into mysql to secure it, we'll need the current
password for the root user.  if you've just installed mysql, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

enter current password for root (enter for none):
ok, successfully used password, moving on...

setting the root password ensures that nobody can log into the mysql
root user without the proper authorisation.

you already have a root password set, so you can safely answer 'n'.

change the root password? [y/n] y
new password:
re-enter new password:
password updated successfully!
reloading privilege tables..
 ... success!

by default, a mysql installation has an anonymous user, allowing anyone
to log into mysql without having to have a user account created for
them.  this is intended only for testing, and to make the installation
go a bit smoother.  you should remove them before moving into a
production environment.

remove anonymous users? [y/n] y
 ... success!

normally, root should only be allowed to connect from 'localhost'.  this
ensures that someone cannot guess at the root password from the network.

disallow root login remotely? [y/n] n
 ... skipping.

by default, mysql comes with a database named 'test' that anyone can
access.  this is also intended only for testing, and should be removed
before moving into a production environment.

remove test database and access to it? [y/n] n
 ... skipping.

reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

reload privilege tables now? [y/n] y
 ... success!

all done!  if you've completed all of the above steps, your mysql
installation should now be secure.

thanks for using mysql!

cleaning up...

当然也可以手动完成这些操作:

复制代码 代码如下:

[mysql@beanvm ~]$ mysqladmin -u root password 'new-password'
[mysql@beanvm ~]$ mysqladmin -u root -h beanvm password 'new-password'
[mysql@beanvm ~]$ mysql -u root -p
enter password:
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 19
server version: 5.6.16 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> delete from mysql.user where user='';
query ok, 2 rows affected (0.01 sec)

mysql> grant all privileges on *.* to 'root'@'%' identified by 'mypasswd' with grant option;
query ok, 0 rows affected (0.01 sec)

mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)