1.  安装MYSQL服务器需要的依赖库:

 

bison*  gcc*   gcc-c++*   autoconf*  automake*   zlib*   libxml2*  ncurses-devel*   libtool-ltdl-devel*

 

# rpm -ivhlibtool-ltdl-devel-2.2.6-15.5.el6.x86_64.rpm

    或者:

# yum install  bison gcc  gcc-c++  autoconf automake  zlib  libxml ncurses-devel  libtool-ltdl-devel

 

2.  安装编译MYSQL 5.X.X以上版本需要的cmake包:

 

# rpm -qa |grep cmake                                                                              (先检查系统里是否已经安装了cmake包)

# cd /mnt/Packages

# rpm -ivh cmake-2.6.4-5.el6.x86_64.rpm

    或者:

# wget http://wwwNaNake.org/files/v2.8/cmake-2.8.6.tar.gz

# tar zxvf cmake-2.8.6.tar.gz

# cd cmake-2.8.6/

# ./configure

# gmake

# gmake install 

 

3.  创建MYSQL用户和组,创建数据存储目录和日志存储目录,并设置权限:

 

# groupadd mysql

# useradd -g mysql -s /sbin/nologin mysql

# mkdir -p /data/mysql

# chown -R mysql:mysql /data/mysql

# mkdir -p /data/mysql_log

# chown -R mysql:mysql /data/mysql_log

 

4.  编译安装MYSQL 5.5.22服务器:

 

# cd /usr/local/src

# wget http://down1.chinaunix.net/distfiles/mysql-5.5.38.tar.gz          (如果已经下载好了源代码包就不用再下载)

 

# tar zxvf mysql-5.5.38.tar.gz

# cd mysql-5.5.38

 

# cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc-DMYSQL_DATADIR=/data/mysql -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql

 

# gmake

# gmake install

 

5.  设置MYSQL服务器配置文件:

 

# cd /usr/local/mysql

# cp ./support-files/my-huge.cnf /etc/my.cnf

 

# vi /etc/my.cnf                                                                                                  (根据自己的需要在不同的配置区域添加或修改选项)                                                                          

[mysqld]

 

# FOR GLOBAL

max_allowed_packet = 100M

sort_buffer_size = 5M

read_buffer_size = 5M

read_rnd_buffer_size = 10M

max_connections = 1000

skip-name-resolve

 

# FOR MYISAM

 

# FOR BIN_LOG AND SLOW_LOG

binlog_format = MIXED

log_bin = /data/mysql_log/mysql-bin                              

log_bin_index =/data/mysql_log/mysql-bin.index

slow_query_log = on

long_query_time = 1

slow_query_log_file =/data/mysql_log/mysql-slow.log

log_queries_not_using_indexes = on

 

# FOR INNODB

innodb_data_home_dir = /data/mysql

innodb_data_file_path =ibdata1:100G;ibdata2:100G;ibdata3:100M:autoextend

innodb_buffer_pool_size = 1024M

innodb_additional_mem_pool_size = 100M

innodb_flush_log_at_trx_commit = 2

 

6.  初始化数据库,并添加为MYSQLD系统服务:

 

# cd /usr/local/mysql

# ./scripts/mysql_install_db--datadir=/data/mysql --basedir=/usr/local/mysql --defaults-file=/etc/my.cnf--user=mysql

# cp ./support-files/mysql.server  /etc/rc.d/init.d/mysqld

# chmod 755 /etc/rc.d/init.d/mysqld

# chkconfig --add mysqld

# chkconfig --level 24 mysqld off

 

7.  设置启动脚本变量:

 

# vi /etc/rc.d/init.d/mysqld

basedir=/usr/local/mysql

datadir=/data/mysql

 

8.  设置环境变量:

 

# vi /etc/profile                                                                                                      (在全局配置文件最后一行添加,所有用户会话都有效)

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

# . /etc/profile

    或者:

# export PATH=$PATH:/usr/local/mysql/bin                                        (当前用户会话中有效)

    

9.  启动MYSQL服务:

 

# service mysqld start

 

10.  设置数据库管理员root密码,重新启动mysqld服务:

 

# mysqladmin -u root password '123456'

# service mysqld restart

 

# 查看mysql服务监听端口状态:

# netstat -npalt | grep 3306

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

 

# 查看mysql进程状态:

# ps -ef | grep mysql

root    18769         1   0 14:43  pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql--pid-file=/data/mysql/centos1.pid

mysql  19033  18769   0 14:43  pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql--datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql

                                                                         --log-error=/data/mysql/centos1.err--pid-file=/data/mysql/centos1.pid --socket=/tmp/mysqld.sock --port=3306

 

11.  登录MYSQL服务器: 

 

# mysql -uroot -p123456

mysql> show databases;

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

| Database           |

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

| information_schema    |

| mysql                        |

| performance_schema |

| test                           |

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

4 rows in set (0.00 sec)

 

mysql> use mysql;

Database changed

mysql> show tables;

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

| Tables_in_mysql           |

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

| columns_priv               |

........

 

12.  管理MYSQL 创建数据库库,创建表等

# 显示mysql存储引擎:

mysql> show engines;

 

# 更改字符集:

mysql> show variables like 'character_set_%';

mysql> set character_set_client=utf8;