CentOS下MySQL数据库免编译方式安装

基础信息:

系统:CentOS6.5

运行内存:2G

磁盘大小:20G

安装步骤:

1)     下载mysql的免编译安装包,我这边下载的是mysql5.6.34版本

wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

2)     设置mysql的安装目录

tar -zxvf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz 

mv mysql-5.6.34-linux-glibc2.5-x86_64 /usr/local/mysql

3)     添加mysql用户和用户组

groupadd mysql

useradd -g mysql -M mysql(-M:强制!不要创建用户主文件夹,系统账号默认值)

4)     设置mysql的数据存储目录和权限设置

mkdir -p /work/mysql/data

chown -R mysql.mysql /work/mysql/data

5)     检测在/etc/目录下是否有my.cnf文件,如果有则进行下面的操作

mv my.cnf my.cnf_bak

6)     初始化mysql数据库

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/work/mysql/data --user=mysql

7)     添加mysqld为系统服务并设置自启动

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

chkconfig --add mysqld

chkconfig mysqld on

8)     修改my.cnf文件,由于我的mysql版本大于5.5,所以该my.cnf文件会安装在/usr/local/mysql/my.cnf下

/usr/local/mysql/my.cnf

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

basedir = /usr/local/mysql

datadir = /work/mysql/data

port = 3306

# server_id = .....

socket = /tmp/mysql.sock

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

join_buffer_size = 128M

sort_buffer_size = 2M

read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

将my.cnf文件修改为如上配置就可以了

提示:安装完成之后有碰到没法直接使用mysql命令进入mysql数据库中的情况,

情况如下:

mysql –u root

-bash:mysql:command not found

原因是系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,就会报上面的错误,我们需要做个映射链接到/usr/bin目录下,相当于建立一个链接文件,当mysql的完整路径是/usr/local/mysql/bin/mysql时,我们需要做如下设置就可以了:

ln –s /usr/local/mysql/bin/mysql /usr/bin


aliyun
赵群博客
请先登录后发表评论
  • 最新评论
  • 总共0条评论