在编译安装mysql之前,先了解一下mysql具体是做什么用的
1、Mysql是一个开放源码的小型关系型数据库管理系统,开放者为瑞典MYSQL AB公司,目前MYSQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多种小型网站为降低网站总体拥有的成本而选择了MYSQL作为网站数据库。
2、安装 Mysql
2.1、安装简介
用户名:mysql
安装目录:/usr/local/mysql
数据库目录:/usr/local/data/mysql/data
源码包:mysql-5.6.24.tar.gz
2.2、添加用户
useradd -s /sbin/nologin mysql
2.3、建立所需目录
mkdir /usr/local/mysql
mkdir -p /usr/local/data/mysql/data
chown -R mysql:mysql /usr/local/data/mysql/data
2.4、安装编译所需文件或程序
yum install gcc gcc-c++ cmake ncurses-devel bison
2.5、mysql下载网址
mysql源码包下载链接http://dev.mysql.com/downloads/mysql/5.7.html
mysql参考手册http://dev.mysql.com/doc/
2.6、编译安装
下载mysql源码包后,该源码包在root的目录下
cd /root
tar -zxvf mysql-5.6.24.tar.gz
cd mysql-5.6.24
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1
make && make install
2.7、编译安装mysql后,添加权限
chown -R mysql:mysql /usr/local/mysql
cp -a /root/mysql-5.6.24/support-files/mysql-default.conf /etc/my.cnf
cp -a /root/mysql-5.6.24/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
2.8、设置mysql服务为开机启动
chkconfig --level 345 mysqld on echo "export PATH=/usr/local/mysql/bin/:$PATH" >> /etc/profile
source /etc/profile
2.9初始化数据库
/usr/local/mysql/scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/data/mysql/data
vi /etc/my.cnf(在文件最后添加下面两个语句)
basedir=/usr/local/mysql
datadir=/usr/local/data/mysql/data
3、启动数据库
service mysqld start
3.1、创建mysql管理员
/usr/local/mysql/bin/mysqladmin -u root password '123456'
-------------------------------------------------------------------------------------------
下面开始安装
[BEGIN] 2015/12/18 22:03:34 [root@localhost ~]# mkdir -p /usr/local/data/mysql/data [root@localhost ~]# useradd -s /sbin/nologin mysql [root@localhost ~]# chown -R mysql:mysql /usr/local/data/mysql/data [root@localhost ~]# yum install gcc gcc-c++ cmake ncurses-devel bison [root@localhost ~]# tar -zxvf mysql-5.6.24.tar.gz [root@localhost ~]# cd mysql-5.6.24 [root@localhost mysql-5.6.24]# mkdir /usr/local/mysql [root@localhost mysql-5.6.24]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 [root@localhost mysql-5.6.24]# make [root@localhost mysql-5.6.24]# make install [root@localhost mysql-5.6.24]# chown -R mysql:mysql /usr/local/mysql/ [root@localhost mysql-5.6.24]# cp -a /root/mysql-5.6.24/support-files/my-default.cnf /etc/my.cnf [root@localhost mysql-5.6.24]# cp -a /root/mysql-5.6.24/support-files/mysql.server /etc/init.d/mysqld [root@localhost mysql-5.6.24]# chmod a+x /etc/init.d/mysqld [root@localhost mysql-5.6.24]# chkconfig --level 345 mysqld on [root@localhost mysql-5.6.24]# echo "export PATH=/usr/local/mysql/bin/:$PATH" >> /etc/profile [root@localhost mysql-5.6.24]# source /etc/profile [root@localhost mysql-5.6.24]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/data/mysql/data [root@localhost mysql-5.6.24]# vi /etc/my.cnf [root@localhost mysql-5.6.24]# service mysqld start Starting MySQL... SUCCESS! [root@localhost mysql-5.6.24]# /usr/local/mysql/bin/mysqladmin -u root password '123456' [root@localhost mysql-5.6.24]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.24 Source distribution Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> exit Bye