1、创建mysql安装目录、mysql用户
[root@serv19 ~]# mkdir -p /u01/mysql/data
[root@serv19 ~]# groupadd mysql
[root@serv19 ~]# useradd -r -g mysql mysql
2、安装依赖包
[root@serv19 ~]# yum.repos.d]# yum install -y gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*
3、解压并安装cmake包
[root@serv19 ~]# tar -zxvf cmake-2.8.5.tar.gz
[root@serv19 u01]# cd cmake-2.8.5
[root@serv19 cmake-2.8.5]# ./configure
[root@serv19 cmake-2.8.5]# make && make install
4、解压安装mysql
[root@serv19 u01]# tar -zxvf mysql-5.6.19.tar.gz
[root@serv19 u01]# cd mysql-5.6.19
[root@serv19 mysql-5.6.19]# cmake \
> -DCMAKE_INSTALL_PREFIX=/u01/mysql \
> -DMYSQL_DATADIR=/u01/mysql/data \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DEXTRA_CHARSETS=all \
> -DENABLED_LOCAL_INFILE=1
参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql ----- 安装目录
-DINSTALL_DATADIR=/usr/local/mysql/data ----- 数据库存放目录
-DDEFAULT_CHARSET=utf8 ----- 使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci ----- 校验字符
-DEXTRA_CHARSETS=all ----- 安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 ----- 允许从本地导入数据
[root@serv19 mysql-5.6.19]# make
[root@serv19 mysql-5.6.19]# make install
5、mysql初始配置
(1)设置目录权限
[root@serv19 ~]# chown -R root.mysql /u01
[root@serv19 ~]# chown -R mysql.mysql /u01/mysql/data
(2)设置mysql服务
[root@serv19 mysql]# vi /etc/my.cnf
[mysqld]
basedir = /u01/mysql
datadir = /u01/mysql/data
log-error = /u01/mysql/mysql_error.log
pid-file = /u01/mysql/data/mysql.pid
user = mysql
port = 3306
socket = /tmp/mysql.sock
[client]
port = 3306
socket = /tmp/mysql.sock
(3)mysql初始化安装
[root@serv19 mysql]# scripts/mysql_install_db \
> --user=mysql \
> --basedir=/u01/mysql \
> --datadir=/u01/mysql/data
(4)设置环境变量
[root@serv19 mysql]# vi /root/.bash_profile
PATH=$PATH:$HOME/bin:/u01/mysql/bin:/u01/mysql/lib
[root@serv19 mysql]# source /root/.bash_profile
(5)将mysql添加到系统服务中
[root@serv19 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@serv19 mysql]# chmod +x /etc/init.d/mysqld
[root@serv19 mysql]# vi /etc/init.d/mysqld
basedir=/u01/mysql
datadir=/u01/mysql/data
[root@serv19 mysql]# chkconfig --add mysqld
[root@serv19 mysql]# chkconfig --level 345 mysqld on
[root@serv19 mysql]# service mysqld start
(6)修改mysql的root用户密码以及打开远程连接
[root@serv19 scripts]# mysql -u root
mysql> use mysql
mysql> update user set Password = password('root123') where User='root';
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root123";
mysql> flush privileges;
mysql> exit
[root@serv19 scripts]# mysql -u root -p