单实例MySQL安装

1、建立账号

   [root@opsedu ~]# groupadd mysql

[root@opsedu ~]# useradd -s /sbin/nologin -g mysql -Mmysql

       useradd参数说明:

                -s/sbin/nologin 表示禁止该用户登录

                -gmysql 指定属于mysql

                -M表示不创建用户家目录

2、配置安装环境

    创建目录并授权:

   [root@opsedu ~]# mkdir /home/tools

[root@opsedu ~]# mkdir -p /usr/local/mysql

    [root@opsedu ~]#mkdir -p /data/mysql

    [root@opsedu ~]#chown -R mysql.mysql /usr/local/mysql/

    [root@opsedu ~]#chown -R mysql:mysql /data/mysql

    安装系统软件包:

[root@opsedu ~]# yum install gcc gcc-c++ make cmakencurses-devel bison perl

配置解析:

   [root@opsedu ~]# hostname

opsedu

[root@opsedu ~]# vim /etc/hosts

10.47.129.177 opsedu        添加一条

安装cmake

   [root@opsedu ~]# rpm -qa | grep cmake   使用系统自带cmake,编译时,有时候会报错

cmake-2.8.12.2-4.el6.x86_64         版本2.8.12

[root@opsedu ~]# yum remove cmake �Cy

[root@opsedu ~]# cd /home/tools

[root@opsedu tools]# wget https://cmake.org/files/v2.8/cmake-2.8.12.tar.gz

[root@opsedu tools]# tar -zxf cmake-2.8.12.tar.gz

[root@opsedu tools]# cd cmake-2.8.12

[root@opsedu cmake-2.8.12]# ./configure

    wKiom1arHQmjmS9yAAAbdgeUjPk099.png

[root@opsedu cmake-2.8.12]# gmake

[root@opsedu cmake-2.8.12]# gmake install

[root@opsedu cmake-2.8.12]# cd ..

[root@opsedu tools]# cmake --version

cmake version 2.8.12

3、安装mysql

[root@opsedu tools]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.37.tar.gz

[root@opsedu tools]# tar -zxf mysql-5.5.37.tar.gz

[root@opsedu tools]# cd mysql-5.5.37

 

[root@opsedu 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

    编译安装:

[root@opsedu mysql-5.5.37]# make

[root@opsedu mysql-5.5.37]# make install

    拷贝配置:

[root@opsedu 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

[root@opsedu mysql-5.5.37]# /bin/cpsupport-files/my-huge.cnf /etc/my.cnf

    创建mysql数据库文件:

[root@opsedu mysql-5.5.37]#/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql--datadir=/data/mysql --user=mysql

    启动mysql:

[root@opsedu mysql-5.5.37]#  /usr/local/mysql/bin/mysqld_safe --user=mysql&

[root@opsedu mysql-5.5.37]# netstat -lnt|grep 3306

tcp       0     0 0.0.0.0:3306          0.0.0.0:*               LISTEN

    配置mysql:

[root@opsedu ~]# echo 'exportPATH=/usr/local/mysql/bin:$PATH' >>/etc/profile

[root@opsedu ~]# source /etc/profile

    配置mysql开机启动:

[root@opsedu mysql-5.5.37]# cpsupport-files/mysql.server /etc/init.d/mysqld

[root@opsedu mysql-5.5.37]# chmod 700 /etc/init.d/mysqld

[root@opsedu ~]# chkconfig --add mysqld

[root@opsedu ~]# chkconfig mysqld on

    mysql root用户增加密码:

[root@opsedu ~]# mysqladmin -uroot password'q.123456'

    安装之后的选项:

[root@opsedu ~]# 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)


你可能感兴趣的:(mysql,实例)