1、建立账号
[[email protected] ~]# groupadd mysql
[[email protected] ~]# useradd -s /sbin/nologin -g mysql -Mmysql
useradd参数说明:
-s/sbin/nologin 表示禁止该用户登录
-gmysql 指定属于mysql组
-M表示不创建用户家目录
2、配置安装环境
创建目录并授权:
[[email protected] ~]# mkdir /home/tools
[[email protected] ~]# mkdir -p /usr/local/mysql
[[email protected] ~]#mkdir -p /data/mysql
[[email protected] ~]#chown -R mysql.mysql /usr/local/mysql/
[[email protected] ~]#chown -R mysql:mysql /data/mysql
安装系统软件包:
[[email protected] ~]# yum install gcc gcc-c++ make cmakencurses-devel bison perl
配置解析:
[[email protected] ~]# hostname
opsedu
[[email protected] ~]# vim /etc/hosts
10.47.129.177 opsedu 添加一条
安装cmake:
[[email protected] ~]# rpm -qa | grep cmake 使用系统自带cmake,编译时,有时候会报错
cmake-2.8.12.2-4.el6.x86_64 版本2.8.12
[[email protected] ~]# yum remove cmake –y
[[email protected] ~]# cd /home/tools
[[email protected] tools]# wget https://cmake.org/files/v2.8/cmake-2.8.12.tar.gz
[[email protected] tools]# tar -zxf cmake-2.8.12.tar.gz
[[email protected] tools]# cd cmake-2.8.12
[[email protected] cmake-2.8.12]# ./configure
[[email protected] cmake-2.8.12]# gmake
[[email protected] cmake-2.8.12]# gmake install
[[email protected] cmake-2.8.12]# cd ..
[[email protected] tools]# cmake --version
cmake version 2.8.12
3、安装mysql
[[email protected] tools]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.37.tar.gz
[[email protected] tools]# tar -zxf mysql-5.5.37.tar.gz
[[email protected] tools]# cd mysql-5.5.37
[[email protected] mysql-5.5.37]# cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
> -DMYSQL_DATADIR=/data/mysql \
> -DMYSQL_TCP_PORT=3306 \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DEXTRA_CHARSETS=all \
> -DENABLED_LOCAL_INFILE=ON \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_FEDERATED_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
> -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
> -DWITH_FAST_MUTEXES=1 \
> -DWITH_ZLIB=bundled \
> -DENABLED_LOCAL_INFILE=1 \
> -DWITH_READLINE=1 \
> -DWITH_EMBEDDED_SERVER=1 \
> -DWITH_DEBUG=0 \
> -DMYSQL_UNIX_ADDR=/tmp/mysql.sock
编译安装:
[[email protected] mysql-5.5.37]# make
[[email protected] mysql-5.5.37]# make install
拷贝配置:
[[email protected] mysql-5.5.37]# ll support-files/*.cnf
-rw-r--r-- 1 root root 4671 Jan 29 15:11 support-files/my-huge.cnf
-rw-r--r-- 1 root root 19759 Jan 29 15:11support-files/my-innodb-heavy-4G.cnf
-rw-r--r-- 1 root root 4645 Jan 29 15:11 support-files/my-large.cnf
-rw-r--r-- 1 root root 4656 Jan 29 15:11 support-files/my-medium.cnf
-rw-r--r-- 1 root root 2820 Jan 29 15:11 support-files/my-small.cnf
[[email protected] mysql-5.5.37]# /bin/cpsupport-files/my-huge.cnf /etc/my.cnf
创建mysql数据库文件:
[[email protected] mysql-5.5.37]#/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql--datadir=/data/mysql --user=mysql
启动mysql:
[[email protected] mysql-5.5.37]# /usr/local/mysql/bin/mysqld_safe --user=mysql&
[[email protected] mysql-5.5.37]# netstat -lnt|grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
配置mysql:
[[email protected] ~]# echo ‘exportPATH=/usr/local/mysql/bin:$PATH‘ >>/etc/profile
[[email protected] ~]# source /etc/profile
配置mysql开机启动:
[[email protected] mysql-5.5.37]# cpsupport-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql-5.5.37]# chmod 700 /etc/init.d/mysqld
[[email protected] ~]# chkconfig --add mysqld
[[email protected] ~]# chkconfig mysqld on
为mysql root用户增加密码:
[[email protected] ~]# mysqladmin -uroot password‘q.123456‘
安装之后的选项:
[[email protected] ~]# mysql -uroot -pq.123456
mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost |*026FC8CD6C3B58F3C3566D83F8189585C9F3F292 |
| root | opsedu | |
| root | 127.0.0.1 | |
| root | ::1 | |
| |localhost | |
| |opsedu | |
+------+-----------+-------------------------------------------+
6 rows in set (0.00 sec)
删除无用的账号:
mysql> delete from mysql.user where user=‘ ‘;
Query OK, 2 rows affected (0.00 sec)
mysql> delete from mysql.user where password=‘ ‘;
Query OK, 3 rows affected (0.00 sec)
mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost |*026FC8CD6C3B58F3C3566D83F8189585C9F3F292 |
+------+-----------+-------------------------------------------+
1 row in set (0.00 sec)