centos6.5安装mysql-5.6.20

一.   准备工作

1.yum安装各个依赖包

[root@WebServer ~]# yum �Cy install gcc gcc-devel gcc-c++ gcc-c++-devel  zlib*  ncurses-devel ncurses openssl openssl-devel bison bison-devel libaio

[root@WebServer ~]# yum �Cy install cmake

[root@WebServer user]# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz

 

2.新建mysql组和用户

[root@WebServer ~]# groupadd mysql

[root@WebServer ~]# useradd �Cg mysql �Cs /sbin/nologin mysql

 

3.目录准备

[root@WebServer ~]# mkdir �Cp /hywl/mysql/etc

[root@WebServer ~]# mkdir �Cp / hywl/mysql/data

[root@WebServer ~]# mkdir �Cp / hywl/mysql/tmp

[root@WebServer ~]# chown �CR mysql.mysql /hywl/mysql

 

4.解压MySQL并进入安装目录

拷贝mysql-5.6.20.tar.gz到/home/mysql目录下

[root@WebServer ~]# tar zxvf mysql-5.6.20.tar.gz

[root@WebServer ~]# cd mysql-5.6.20

 

二.   编译并安装

1 .下载gmock-1.6.0.zip到/home/mysql/mysql-5.6.20/source_downloads目录下并编译安装:

[root@WebServer mysql-5.6.20]# cd source_downloads/

[root@WebServer source_downloads]# unzip gmock-1.6.0.zip

root@WebServer source_downloads]# cd gmock-1.6.0

[root@WebServer gmock-1.6.0]# ./configure

[root@WebServer gmock-1.6.0]# make

[root@WebServer gmock-1.6.0]# cd ..

 

2.编译MySQL

[root@WebServer mysql-5.6.20]# cmake �CDCMAKE_INSTALL_PREFIX=/hywl/mysql

[root@WebServer mysql-5.6.20]# cmake -DSYSCONFDIR=/hywl/mysql/etc

[root@WebServer mysql-5.6.20]# cmake -DMYSQL_DATADIR=/hywl/mysql/data

[root@WebServer mysql-5.6.20]# cmake -DMYSQL_TCP_PORT=3306

[root@WebServer mysql-5.6.20]# cmake -DMYSQL_UNIX_ADDR=/hywl/mysql/tmp/mysqld.sock

[root@WebServer mysql-5.6.20]# cmake -DMYSQL_USER=mysql

[root@WebServer mysql-5.6.20]# cmake -DEXTRA_CHARSETS=all

[root@WebServer mysql-5.6.20]# cmake -DWITH_READLINE=1

[root@WebServer mysql-5.6.20]# cmake -DWITH_SSL=system

[root@WebServer mysql-5.6.20]# cmake -DWITH_EMBEDDED_SERVER=1

[root@WebServer mysql-5.6.20]# cmake -DENABLED_LOCAL_INFILE=1

[root@WebServer mysql-5.6.20]# cmake -DWITH_INNOBASE_STORAGE_ENGINE=1

[root@WebServer mysql-5.6.20]# cmake -DENABLE_DOWNLOADS=1

*如果出现错误,删除mysql-5.6.20目录下的CmakeCache.txt重新使用cmake进行编译安装

 

3.安装

[root@WebServer mysql-5.6.20]# make && make install 

#时间有点长。

 

三.MySQL配置

1.客户端库文件的链接(未执行此步骤的话,在PHP编译时会提示找不到MySQL文件)

[root@WebServer mysql-5.6.20]# ln �Cs /hywl/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18

 

ps:我使用的是64位CentOS,如果使用的是32位请使用ln �Cs / hywl /mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

 

2.MySQL启动文件的配置

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

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

[root@WebServer mysql-5.6.20]# vim /etc/init.d/mysqld

//修改以下这2行的路径即可

basedir=/hywl/mysql

datadir=/hywl/mysql/data

 

3.设置MySQL配置文件

[root@WebServer mysql-5.6.20]# cp support-files/my-default.cnf / hywl /mysql/etc/my.cnf

[root@WebServer mysql-5.6.20]# rm �Crf /etc/my.cnf

[root@WebServer mysql-5.6.20]# ln �Cs / hywl /mysql/etc/my.cnf /etc/my.cnf

 

4.初始化数据库

[root@WebServer mysql-5.6.20]# cd / hywl /mysql

[root@WebServer mysql]# ./scripts/mysql_install_db �Cuser=mysql �Cbasedir=/hywl/mysql �Cdatadir=/ hywl /mysql/data

 

5.链接MySQL命令(这一步可以让我们方便很多,可以不用写出命令的路径,也可以写入/etc/profile的PATH中)

可以修改环境变量:

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

//增加一行:

export PATH=/hywl/mysql/bin:$PATH


[root@WebServer mysql]# source /etc/profile

//这时再查看系统环境变量,就能看见刚才加的东西已经生效了

[root@WebServer mysql]# echo $PATH

 

也可以:

[[root@WebServer mysql]#cd /usr/sbin

[root@WebServer sbin]# ln �Cs / hywl /mysql/bin/*

 

6.启动MySQL并设置为开机启动

[root@WebServer sbin]# service mysqld start ;chkconfig mysqld on

Starting MySQL.. SUCCESS!

 

7.设置MySQL root用户的密码

[root@WebServer ~]# mysqladmin �Cu root password mysql

//强烈不建议将数据库的密码设的简单

 

8.删除用户密码为空的用户

[root@WebServer ~]# mysql �Cu root �Cp

Enter password:

mysql> use mysql;

mysql> select Host,User,Password from user;

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

| Host      | User | Password                                  |

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

| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| webserver | root |                                          |

| 127.0.0.1 | root |                                          |

| ::1      | root |                                          |

| localhost |      |                                          |

| webserver |      |                                          |

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

6 rows in set (0.00 sec)

mysql> delete from user where password=””;

Query OK, 5 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> select Host,User,Password from user;

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

| Host      | User | Password                                  |

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

| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

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

1 row in set (0.00 sec)

mysql> exit;

9.如何知道你的数据目录在哪里。如果你运行多个服务器,你应该知道所有数据目录在哪里,但是如果你不知道确切的位置,由多种方法找到它:

9.1使用mysqladmin variables从你的服务器直接获得数据目录路径名。查找datadir变量的值,在Unix上,其输出类似于:
%mysqladmin -u username -p variables

+----------------------+----------------------+
| variable_name        | Value                |
+----------------------+----------------------+
| back_log             | 5                    |
| connect_timeout      | 5                    |
| basedir              | /var/local/          |
| datadir              | /usr/local/var/      |
....
9.2查找mysql运行的路径
%ps -ef | grep mysqld


你可能感兴趣的:(数据库,mysql,安装,centos,配置,系统,6.5,及,5.6.20)