在这里我选择了mysql-5.5.33-linux2.6-x86_64.tar.gz的版本,各位可以根据自己的实际需要选择了哈。

1、MYSQL下载地址http://mirrors.sohu.com/mysql/

2、下载源码包wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.33-linux2.6-x86_64.tar.gz

3、MYSQL5.5X以上版本均采用CMAKE安装方式,需要先安装CMAKE工具

  # wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz

  # tar zxvf cmake-2.8.4.tar.gz

  # cd cmake-2.8.4

  # ./configure

  # make

  # make install

3、解压源码包并进入目录

   tar xzvf mysql-5.5.33-linux2.6-x86_64.tar.gz

   cd mysql-5.5.33-linux2.6-x86_64

4、确认编译环境是否具备

   yum -y install gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool*

5、创建mysql安装目录及数据目录

  安装目录mkdir /data/mysql

  数据存储mkdir /data/mysql/data

6、创建用户和用户组与赋予数据存放目录权限

 groupadd mysql

 useradd -g mysql mysql

 chown mysql.mysql -R /data/mysql/

7、进行编译安装,配置编译参数

  cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

 -DMYSQL_DATADIR=/usr/local/mysql/data \

 -DMYSQL_TCP_PORT=3306 \

 -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysqld.sock \

 -DMYSQL_USER=mysql \

 -DDEFAULT_CHARSET=utf8 \

 -DDEFAULT_COLLATION=utf8_general_ci \

 -DEXTRA_CHARSETS=all \

 -DWITH_READLINE=1 \

 -DWITH_EMBEDDED_SERVER=1 \

 -DENABLED_LOCAL_INFILE=1 \

 -DWITH_INNOBASE_STORAGE_ENGINE=1

   make && make install


8、复制配置文件到/etc目录下并初始化数据库

  cp /data/mysql/support-files/my-medium.cnf  /etc/my.cnf

9、配置启动脚本

   cp /data/mysql/support-files/mysql.server  /etc/init.d/mysql

10、初始化数据库

  /usr/local/mysql/scripts/mysql_install_db \

  --defaults-file=/etc/my.cnf \

  --basedir=/usr/local/mysql \

  --datadir=/usr/local/mysql/data \

  --user=mysql

11、赋权并修改MYSQL启动位置

   chmod +x /etc/init.d/mysql

   cp  /usr/local/mysql/bin/mysql  /usr/bin/

12、启动数据库并配置数据库密码

  service mysql start

  /data/mysql/bin/mysqladmin -u root password 'hrdtech2013'

  [root@hrd ~]# mysql -u root -p

  Enter password:

  mysql>

  或者修改密码

  UPDATE user SET password=PASSWORD("new password") WHERE user='root';

13、授权用户本地与远程访问数据库的权限

   grant all privileges on *.* to root@'%' identified by 'hrdtech2013';

   flush privileges;

14、my.cnf优化

   [client]

   #password       = your_password

   port            = 3306

   socket          = /data/mysql/data/mysqld.sock

   default-character-set = utf8

   # The MySQL server

   [mysqld]

   port            = 3306

   socket          = /data/mysql/data/mysqld.sock

   log-error = /data/mysql/data

   pid-file = /data/mysql/data/hrd.pid

   skip-external-locking

   key_buffer_size = 256M

   max_allowed_packet = 4M

   table_open_cache = 1024

   sort_buffer_size = 2M

   net_buffer_length = 8K

   read_buffer_size = 1M

   tmp_table_size = 16M

   read_rnd_buffer_size = 8M

   myisam_sort_buffer_size = 8M

   back_log = 200

   skip-name-resolve

   max_connections = 1000

   wait_timeout = 120

   thread_concurrency = 8

   long_query_time = 2

   slow-query_log

   slow-query_log_file = /data/mysql/data/slow.log

   lower_case_table_names = 1


15、mysql字符集优化

   SHOW VARIABLES LIKE 'CHARACTER%';  查看字符环境

   1、在[client]字段里加入default-character-set=utf8,如下:

  [client]

  port = 3306

  socket = /var/lib/mysql/mysql.sock

  default-character-set=utf8


  2、在[mysqld]字段里加入character-set-server=utf8,如下:

  [mysqld]

  port = 3306

  socket = /var/lib/mysql/mysql.sock

  character-set-server=utf8