Home >Database >Mysql Tutorial >centos编译安装mysql_MySQL

centos编译安装mysql_MySQL

WBOY
WBOYOriginal
2016-06-01 13:26:541089browse

CentOS

bitsCN.com

注:安装过程部分步骤需要root用户权限。

软件版本:centos 6.3

  mysql-5.5.35.tar.gz

 

1、检查/安装相关工具包、库文件

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

 

2、安装cmake包
tar zxvf cmake-2.8.12.1.tar.gz
cd cmake-2.8.12.1
./configure
gmake
gmake install

 

3、创建mysql用户(组)
groupadd mysql
useradd -r -g mysql mysql


4、创建mysql安装目录、数据库存放目录
mkdir -p /usr/local/mysql
mkdir -p /var/mysql/data

5、编译安装mysql
tar zxvf mysql-5.5.35.tar.gz
cd mysql-5.5.35
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql /
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock /
-DDEFAULT_CHARSET=utf8 /
-DDEFAULT_COLLATION=utf8_general_ci /
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk /
-DWITH_MYISAM_STORAGE_ENGINE=1 /
-DWITH_INNOBASE_STORAGE_ENGINE=1 /
-DWITH_MEMORY_STORAGE_ENGINE=1 /
-DWITH_READLINE=1 /
-DENABLED_LOCAL_INFILE=1 /
-DMYSQL_DATADIR=/var/mysql/data /
-DMYSQL_USER=mysql /
make
make install

6、修改相关目录权限
chown -R root.mysql /usr/local/mysql
chown -R mysql.mysql /var/mysql/data

7、初始化mysql
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql --datadir=/var/mysql/data

8、利用mysql配置文件模板,根据需要修改配置参数
cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
修改my.cnf如下:
port = 3306
socket = /tmp/mysql.sock
datadir = /var/mysql/data
...

9、复制服务启动脚本,启动mysql服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
service mysqld start

10、设置开机自动启动服务
chkconfig --add mysqld
chkconfig --level 35 mysqld on

11、将mysql加入系统环境变量
在/etc/profile中加入mysql/bin:
echo "export PATH=/usr/local/mysql/bin:$PATH" >>/etc/profile
source /etc/profile

 

12、对于生产环境,强烈建议运行安全安装脚本
mysql_secure_installation

按命令向导,设置数据库root用户密码,删除匿名用户,删除test数据库,限制数据库root用户远程登录。

13、建立mysql本地/远程连接用户

mysql> create database 数据库名称;
mysql> grant select,insert,update,delete on 数据库名称.* to 用户名@'%' identified by "密码";
mysql> flush privileges;

 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn