mysql搭建方法

或者直接到其他服务器上拷贝:
scp -@192.168.50.175:/opt/soft/mysql-5.6.23
2.查已装版本
[root@host2 backup]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64
3.删除
[root@host2 backup]# yum remove mysql-libs-5.1.71-1.el6.x86_64
Loaded plugins: fastestmirror, refresh-packagekit, security
。。。
Removed:
mysql-libs.x86_64 0:5.1.71-1.el6Dependency Removed:
cronie.x86_64 0:1.4.4-12.el6
cronie-anacron.x86_64 0:1.4.4-12.el6
crontabs.noarch 0:1.10-33.el6
postfix.x86_64 2:2.6.6-2.2.el6_1
redhat-lsb.x86_64 0:4.0-7.el6.centos
redhat-lsb-compat.x86_64 0:4.0-7.el6.centos
redhat-lsb-core.x86_64 0:4.0-7.el6.centos
redhat-lsb-graphics.x86_64 0:4.0-7.el6.centos
redhat-lsb-printing.x86_64 0:4.0-7.el6.centos
sysstat.x86_64 0:9.0.4-22.el6

Complete!

4.安装依赖
[root@host2 backup]# yum -y install wget gcc gcc-c++ ncurses-devel cmake make perl
。。。
Complete!
[root@host2 backup]#########################################
###这段留底,发时去掉######################
########################################
[root@host2 backup]#
[root@host2 backup]# rpm -qa | grep wget
wget-1.12-1.8.el6.x86_64
[root@host2 backup]# rpm -qa | grep gcc
libgcc-4.4.7-11.el6.x86_64
gcc-gnat-4.4.7-11.el6.x86_64
gcc-c++-4.4.7-11.el6.x86_64
gcc-gfortran-4.4.7-11.el6.x86_64
gcc-objc-4.4.7-11.el6.x86_64
gcc-java-4.4.7-11.el6.x86_64
gcc-4.4.7-11.el6.x86_64
gcc-objc++-4.4.7-11.el6.x86_64
[root@host2 backup]# rpm -qa | grep ncurser-devel
[root@host2 backup]# rpm -qa | grep cmake
[root@host2 backup]# rpm -qa | grep make
make-3.81-20.el6.x86_64
automake-1.11.1-4.el6.noarch
[root@host2 backup]# rpm -qa | grep gmake
[root@host2 backup]# rpm -qa | grep per
perl-Pod-Simple-3.13-136.el6_6.1.x86_64
perl-devel-5.10.1-136.el6_6.1.x86_64
perl-Text-Diff-1.37-2.1.el6.noarch

5.创建mysql用户和组
[root@host2 backup]# groupadd mysql
[root@host2 backup]# useradd -r -g mysql mysql
6.查看用户和组
[root@host2 backup]# id mysql
uid=495(mysql) gid=501(mysql) groups=501(mysql)
7.创建mysql安装目录和数据库文件存放目录
[root@host2 backup]# mkdir -p /usr/local/mysql
[root@host2 backup]# mkdir -p /usr/local/mysql/data
8.cmake配置
[root@host2 mysql-5.6.22]# make clean
[root@host2 mysql-5.6.22]# rm -f CMakeCache.txt
[root@host2 mysql-5.6.22]#
[root@host2 mysql-5.6.22]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
9.编译代码,这一步时间有些长
[root@host2 mysql-5.6.22]# make
10.安装
[root@host2 mysql-5.6.22]# make install
11.查看结果
[root@host2 ~]# ll /usr/local/mysql/
total 168
drwxr-xr-x.  2 root root   4096 Jan 21 00:24 bin
-rw-r–r–.  1 root root  17987 Nov 21 13:39 COPYING
drwxr-xr-x.  3 root root   4096 Jan 21 00:24 data
drwxr-xr-x.  2 root root   4096 Jan 21 00:24 docs
drwxr-xr-x.  3 root root   4096 Jan 21 00:24 include
-rw-r–r–.  1 root root 101760 Nov 21 13:40 INSTALL-BINARY
drwxr-xr-x.  3 root root   4096 Jan 21 00:24 lib
drwxr-xr-x.  4 root root   4096 Jan 21 00:24 man
drwxr-xr-x. 10 root root   4096 Jan 21 00:25 mysql-test
-rw-r–r–.  1 root root   2496 Nov 21 13:39 README
drwxr-xr-x.  2 root root   4096 Jan 21 00:24 scripts
drwxr-xr-x. 28 root root   4096 Jan 21 00:25 share
drwxr-xr-x.  4 root root   4096 Jan 21 00:25 sql-bench
drwxr-xr-x.  2 root root   4096 Jan 21 00:25 support-files
[root@host2 ~]# ll /usr/local/mysql/data/
total 4
drwxr-xr-x. 2 root root 4096 Jan 21 00:24 test
12.清除临时文件
[root@host2 mysql-5.6.22]# make clean
13.修改目录属主数组
[root@host2 mysql-5.6.22]# chown -R mysql:mysql /usr/local/mysql/data
[root@host2 mysql-5.6.22]# chown -R mysql:mysql /usr/local/mysql
14.创建MySQL Server系统表
[root@host2 mysql-5.6.22]# cd /usr/local/mysql/
[root@host2 mysql]#scripts/mysql_install_db –user=mysql –datadir=/usr/local/mysql/data
15.把初始化生成的 /usr/local/mysql/my.cnf 配置文件的属主数组更改为mysql:
[root@host2 mysql]# chown -R mysql:mysql /usr/local/mysql
16.配置启动脚本
[root@host2 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
17.启动MySQL
[root@host2 mysql]# /etc/init.d/mysql status
ERROR! MySQL is not running
[root@host2 mysql]# /etc/init.d/mysql start
Starting MySQL.. SUCCESS!
[root@host2 mysql]# netstat -anpl | grep mysql
tcp        0      0 :::3306                     :::*                        LISTEN      25391/mysqld
unix  2      [ ACC ]     STREAM     LISTENING     241269 25391/mysqld        /usr/local/mysql/mysql.sock
18.配置环境变量(看需要,可以vi /etc/profile)
[root@host2 ~]# vi /root/.bash_profile
在后面追加:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH[root@host2 ~]# source /root/.bash_profile

19.mysql root登录 默认密码为空
20.添加用户名和密码:
21.关闭防火墙:
22.使用Navicat连接: