Centos6.4源码编译安装MySQL5.6.17

时间:2022-06-25 02:35:34

Centos6.4源码编译安装MySQL5.6.17

 

首先查看系统版本平台:

[root@localhost ~]# cat /etc/redhat-release

CentOS release 6.4 (Final)

[root@localhost ~]# uname -a

Linux localhost.localdomain 2.6.32-358.el6.x86_64#1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

一、准备工作

1、添加epel

[root@localhost ~]#

rpm -ivhhttp://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

[root@localhost ~]# rpm --import/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

2、安装yum加速组件:

[root@localhost ~]#  yum install yum-plugin-fastestmirror -y

运行yum报错Error: Cannot retrieve metalink for repository: epel. Please verifyits path and try agai

[root@localhost appstores]# yum installyum-plugin-fastestmirror -y

Loaded plugins: fastestmirror, security

Determining fastest mirrors

Error: Cannot retrieve metalink forrepository: epel. Please verify its path and try again

解决办法:编译/etc/yum.repos.d/epel.repo,做如下改动

#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch

mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch

baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch

#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch

――――――――――――――――――――――――――――――

[root@localhost appstores]# yum installyum-plugin-fastestmirror -y

Loaded plugins: fastestmirror, security

Loading mirror speeds from cached hostfile

 *base: mirrors.btte.net

 *extras: mirrors.btte.net

 *updates: mirrors.btte.net

epel/primary_db                                                    | 6.1 MB     00:34    

extras                                                             | 3.4 kB     00:00    

extras/primary_db                                                   | 19 kB     00:00    

updates                                                            | 3.4 kB     00:00    

updates/primary_db                                                 | 3.1 MB     00:22    

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Packageyum-plugin-fastestmirror.noarch 0:1.1.30-14.el6 will be updated

---> Packageyum-plugin-fastestmirror.noarch 0:1.1.30-17.el6_5 will be an update

--> Finished Dependency Resolution

 

Dependencies Resolved

 

===========================================================================================

 Package                         Arch          Version                Repository      Size

===========================================================================================

Updating:

 yum-plugin-fastestmirror        noarch        1.1.30-17.el6_5        updates         28 k

 

Transaction Summary

===========================================================================================

Upgrade       1 Package(s)

 

Total download size: 28 k

Downloading Packages:

yum-plugin-fastestmirror-1.1.30-17.el6_5.noarch.rpm                 |  28 kB    00:00    

warning: rpmts_HdrFromFdno: Header V3RSA/SHA1 Signature, key ID c105b9de: NOKEY

Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

Importing GPG key 0xC105B9DE:

 Userid : CentOS-6 Key (CentOS 6 OfficialSigning Key) <centos-6-key@centos.org>

 Package:centos-release-6-4.el6.centos.10.x86_64(@anaconda-CentOS-201303020151.x86_64/6.4)

 From   :/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Warning: RPMDB altered outside of yum.

 Updating   :yum-plugin-fastestmirror-1.1.30-17.el6_5.noarch                         1/2

 Cleanup    :yum-plugin-fastestmirror-1.1.30-14.el6.noarch                           2/2

 Verifying  :yum-plugin-fastestmirror-1.1.30-17.el6_5.noarch                         1/2

 Verifying  :yum-plugin-fastestmirror-1.1.30-14.el6.noarch                          2/2

 

Updated:

 yum-plugin-fastestmirror.noarch 0:1.1.30-17.el6_5                                       

 

Complete!

―――――――――――――――――――――――――――――――――――――――――――――

3、准备编译MySQl所需环境

[root@localhost ~]# yum -y install make gcc-c++ bison-devel  ncurses-devel

 

4、编译安装cmake

[root@localhost ~]# wget http://wwwNaNake.org/files/v2.8/cmake-2.8.12.2.tar.gz

[root@localhost ~]# tar xfcmake-2.8.12.2.tar.gz

[root@localhost ~]# cd cmake-2.8.12.2

[root@localhost cmake-2.8.12.2]#./configure  --prefix=/usr/local/cmake

[root@localhost cmake-2.8.12.2]# gmake

[root@localhost cmake-2.8.12.2]#makeinstall

5、为cmake增加环境变量

[root@localhost ~]# vim /etc/profile  //编辑全局变量配置文件

[root@localhost ~]# source  /etc/profile //source立即生效

[root@localhost ~]# tail -n2 /etc/profile //查看编译后的结果,也就是要添加的语句了

PATH=$PATH:/usr/local/cmake/bin

export PATH

 

5、准备MySql用户和组:

[root@localhost ~]# groupadd mysql&& useradd  -s /sbin/nologin  -g mysql -M mysql

[root@localhost ~]# grep mysql /etc/passwd/etc/group

/etc/passwd:mysql:x:500:500::/home/mysql:/sbin/nologin

 

6、创建MySQL数据存放目录并授权:

[root@localhost ~]# mkdir/data/mysql56  -pv  //递归创建

mkdir: created directory `/data'

mkdir: created directory `/data/mysql56'

[root@localhost ~]# chown -R mysql.mysql/data/mysql56  //修改数据目录所有者

[root@localhost ~]# ls -ld /data/mysql56

drwxr-xr-x. 2 mysql mysql 4096 May 21 00:38/data/mysql56

 

 

7、下载并解压MySQL源码包

[root@localhost ~ ]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.17.tar.gz

[root@localhost ~ ]# tar xfMySQL-5.6/mysql-5.6.17.tar.gz //解压

 

二、准备编译MySQl

编译源码,组织软件项目

切换到解压后的MySql源码目录中:

[root@localhost mysql]# tar xfmysql-5.6.17.tar.gz  //解压

[root@localhost mysql]# cd mysql-5.6.17  //进入MySQL源码目录

组织软件编译项目

[root@localhost mysql-5.6.17]

cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql56 \

-DMYSQL_DATADIR=/data/mysql56/  \

-DSYSCONFDIR=/etc \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysqld.sock\

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_DEBUG=0 \

-DMYSQL_USER=mysql

[root@localhost mysql-5.6.17]# make&& make install

漫长的等待。。。。。。可以看个电影消遣,或者听下网易云音乐哈!这个是我在上班的时候从17:05开始cmake的的,班上的机器配置是酷睿i3,4GB内存

17:31分钟cmake完毕,17:32分开始make 很快,几乎就在一瞬间,make install大概是3分钟左右!

 

――――――――――――――――――――――――――――――――――――

配置参数注释:

 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql      # 指定mysql安装位置

 -DMYSQL_DATADIR=/home/mysql/data               # 数据文件存放位置

 -DSYSCONFDIR=/etc                                 # 配置文件my.cnf的位置

 -DWITH_MYISAM_STORAGE_ENGINE=1              # 支持MyIASM引擎

 -DWITH_INNOBASE_STORAGE_ENGINE=1                   # 支持InnoDB引擎

 -DWITH_MEMORY_STORAGE_ENGINE=1            # 支持Memory引擎

 -DWITH_READLINE=1 # 快捷键功能

 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysqld.sock# 连接数据库socket路径

 -DMYSQL_TCP_PORT=3306                                      # 端口

 -DENABLED_LOCAL_INFILE=1                        # 允许从本地导入数据

 -DWITH_PARTITION_STORAGE_ENGINE=1                   # 安装支持数据库分区

 -DEXTRA_CHARSETS=all                                   # 安装所有的字符集

 -DDEFAULT_CHARSET=utf8                             # 默认字符

 -DDEFAULT_COLLATION=utf8_general_ci

――――――――――――――――――――――――――――――――――――――

 

三、编译完成后,继续下面的操作

1、修改MySQL安装目录的权限:

――――――――――――――――――――――――――――――

[root@localhost ~]# cd /usr/local/mysql56

#为了安全起见,安装完成后请修改权限给root用户

[root@localhost mysql56]# chown -Rmysql.mysql .

[root@localhost mysql56]# ls -l

total 156

drwxr-xr-x. 2 mysql mysql  4096 May 26 17:34bin

-rw-r--r--. 1 mysql mysql 17987 Mar 15 03:07 COPYING

drwxr-xr-x. 3 mysql mysql  4096 May 26 17:32data

drwxr-xr-x. 2 mysql mysql  4096 May 26 17:32docs

drwxr-xr-x. 3 mysql mysql  4096 May 26 17:32include

-rw-r--r--. 1 mysql mysql 89144 Mar 15 03:07 INSTALL-BINARY

drwxr-xr-x. 3 mysql mysql  4096 May 26 17:32lib

drwxr-xr-x. 4 mysql mysql  4096 May 26 17:34man

drwxr-xr-x. 10 mysql mysql  4096 May 26 17:34 mysql-test

-rw-r--r--. 1 mysql mysql  2496 Mar 15 03:07README

drwxr-xr-x. 2 mysql mysql  4096 May 26 17:34scripts

drwxr-xr-x. 28 mysql mysql  4096 May 26 17:34 share

drwxr-xr-x. 4 mysql mysql  4096 May 26 17:34sql-bench

drwxr-xr-x. 3 mysql mysql  4096 May 26 17:34support-files

[root@localhost mysql56]#scripts/mysql_install_db --user=mysql

#先进行下一步再做如下权限的修改

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

Installing MySQL system tables...2014-05-2617:36:35 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.Please use --explicit_defaults_for_timestamp server option (see documentationfor more details).

2014-05-26 17:36:35 27956 [Note] InnoDB:Using atomics to ref count buffer pool pages

2014-05-26 17:36:35 27956 [Note] InnoDB:The InnoDB memory heap is disabled

2014-05-26 17:36:35 27956 [Note] InnoDB:Mutexes and rw_locks use GCC atomic builtins

2014-05-26 17:36:35 27956 [Note] InnoDB:Compressed tables use zlib 1.2.3

2014-05-26 17:36:35 27956 [Note] InnoDB:Using CPU crc32 instructions

2014-05-26 17:36:35 27956 [Note] InnoDB:Initializing buffer pool, size = 128.0M

2014-05-26 17:36:35 27956 [Note] InnoDB:Completed initialization of buffer pool

2014-05-26 17:36:35 27956 [Note] InnoDB:The first specified data file ./ibdata1 did not exist: a new database to becreated!

2014-05-26 17:36:35 27956 [Note] InnoDB:Setting file ./ibdata1 size to 12 MB

2014-05-26 17:36:35 27956 [Note] InnoDB:Database physically writes the file full: wait...

2014-05-26 17:36:36 27956 [Note] InnoDB:Setting log file ./ib_logfile101 size to 48 MB

2014-05-26 17:36:38 27956 [Note] InnoDB:Setting log file ./ib_logfile1 size to 48 MB

2014-05-26 17:36:41 27956 [Note] InnoDB:Renaming log file ./ib_logfile101 to ./ib_logfile0

2014-05-26 17:36:41 27956 [Warning] InnoDB:New log files created, LSN=45781

2014-05-26 17:36:41 27956 [Note] InnoDB:Doublewrite buffer not found: creating new

2014-05-26 17:36:41 27956 [Note] InnoDB:Doublewrite buffer created

2014-05-26 17:36:41 27956 [Note] InnoDB:128 rollback segment(s) are active.

2014-05-26 17:36:41 27956 [Warning] InnoDB:Creating foreign key constraint system tables.

2014-05-26 17:36:41 27956 [Note] InnoDB:Foreign key constraint system tables created

2014-05-26 17:36:41 27956 [Note] InnoDB:Creating tablespace and datafile system tables.

2014-05-26 17:36:41 27956 [Note] InnoDB:Tablespace and datafile system tables created.

2014-05-26 17:36:41 27956 [Note] InnoDB:Waiting for purge to start

2014-05-26 17:36:41 27956 [Note] InnoDB:5.6.17 started; log sequence number 0

2014-05-26 17:36:42 27956 [Note] Binlog end

2014-05-26 17:36:42 27956 [Note] InnoDB:FTS optimize thread exiting.

2014-05-26 17:36:42 27956 [Note] InnoDB:Starting shutdown...

2014-05-26 17:36:43 27956 [Note] InnoDB:Shutdown completed; log sequence number 1625977

OK

 

Filling help tables...2014-05-26 17:36:44 0[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use--explicit_defaults_for_timestamp server option (see documentation for moredetails).

2014-05-26 17:36:44 27979 [Note] InnoDB:Using atomics to ref count buffer pool pages

2014-05-26 17:36:44 27979 [Note] InnoDB:The InnoDB memory heap is disabled

2014-05-26 17:36:44 27979 [Note] InnoDB:Mutexes and rw_locks use GCC atomic builtins

2014-05-26 17:36:44 27979 [Note] InnoDB:Compressed tables use zlib 1.2.3

2014-05-26 17:36:44 27979 [Note] InnoDB:Using CPU crc32 instructions

2014-05-26 17:36:44 27979 [Note] InnoDB:Initializing buffer pool, size = 128.0M

2014-05-26 17:36:44 27979 [Note] InnoDB:Completed initialization of buffer pool

2014-05-26 17:36:44 27979 [Note] InnoDB:Highest supported file format is Barracuda.

2014-05-26 17:36:44 27979 [Note] InnoDB:128 rollback segment(s) are active.

2014-05-26 17:36:44 27979 [Note] InnoDB:Waiting for purge to start

2014-05-26 17:36:44 27979 [Note] InnoDB:5.6.17 started; log sequence number 1625977

2014-05-26 17:36:44 27979 [Note] Binlog end

2014-05-26 17:36:44 27979 [Note] InnoDB:FTS optimize thread exiting.

2014-05-26 17:36:44 27979 [Note] InnoDB:Starting shutdown...

2014-05-26 17:36:45 27979 [Note] InnoDB:Shutdown completed; log sequence number 1625987

OK

 

To start mysqld at boot time you have tocopy

support-files/mysql.server to the rightplace for your system

 

PLEASE REMEMBER TO SET A PASSWORD FOR THEMySQL root USER !

To do so, start the server, then issue thefollowing commands:

 

 ./bin/mysqladmin -u root password 'new-password'

 ./bin/mysqladmin -u root -h localhost.localdomain password'new-password'

 

Alternatively you can run:

 

 ./bin/mysql_secure_installation

 

which will also give you the option ofremoving the test

databases and anonymous user created bydefault.  This is

strongly recommended for productionservers.

 

See the manual for more instructions.

 

You can start the MySQL daemon with:

 

  cd. ; ./bin/mysqld_safe &

 

You can test the MySQL daemon with mysql-test-run.pl

 

  cdmysql-test ; perl mysql-test-run.pl

 

Please report any problems athttp://bugs.mysql.com/

 

The latest information about MySQL isavailable on the web at

 

 http://www.mysql.com

 

Support MySQL by buying support/licenses athttp://shop.mysql.com

 

New default config file was created as./my.cnf and

will be used by default by the server whenyou start it.

You may edit this file to change serversettings

 

WARNING: Default config file /etc/my.cnfexists on the system

This file will be read by default by theMySQL server

If you do not want to use this, eitherremove it, or use the

--defaults-file argument to mysqld_safewhen starting the server

 

#将权限设置给root用户,并设置给mysql组,取消其他用户的读写执行权限,仅留给mysql"rx"读执行权限,其他用户无任何权限

[root@localhost mysql56]# chown -R root.mysql . //严格设置权限

[root@localhost mysql56]# ls -l

total 160

drwxr-xr-x. 2 root mysql  4096 May 26 17:34bin

-rw-r--r--. 1 root mysql 17987 Mar 15 03:07 COPYING

drwxr-xr-x. 5 root mysql  4096 May 26 17:36data

drwxr-xr-x. 2 root mysql  4096 May 26 17:32docs

drwxr-xr-x. 3 root mysql  4096 May 26 17:32include

-rw-r--r--. 1 root mysql 89144 Mar 15 03:07 INSTALL-BINARY

drwxr-xr-x. 3 root mysql  4096 May 26 17:32lib

drwxr-xr-x. 4 root mysql  4096 May 26 17:34man

-rw-r--r--. 1 root mysql   943 May 26 17:36my.cnf

drwxr-xr-x. 10 root mysql  4096 May 26 17:34 mysql-test

-rw-r--r--. 1 root mysql  2496 Mar 15 03:07README

drwxr-xr-x. 2 root mysql  4096 May 26 17:34scripts

drwxr-xr-x. 28 root mysql  4096 May 26 17:34 share

drwxr-xr-x. 4 root mysql  4096 May 26 17:34sql-bench

drwxr-xr-x. 3 root mysql  4096 May 26 17:34support-files

#给数据库存放目录设置成mysql用户mysql

[root@localhost ~]# chown  -R mysql.mysql  /data/mysql56  

[root@localhost ~]# ls -ld /data/mysql56

drwxr-xr-x. 2 mysql mysql 4096 May 26 16:55/data/mysql56

[root@localhost ~]# cd /usr/local/mysql56

[root@localhost mysql56]# chown -R  mysql.mysql .

[root@localhost mysql56]# ls -l

total 160

drwxr-xr-x. 2 mysql mysql  4096 May 26 17:34bin

-rw-r--r--. 1 mysql mysql 17987 Mar 15 03:07 COPYING

drwxr-xr-x. 5 mysql mysql  4096 May 26 17:36data

drwxr-xr-x. 2 mysql mysql  4096 May 26 17:32docs

drwxr-xr-x. 3 mysql mysql  4096 May 26 17:32include

-rw-r--r--. 1 mysql mysql 89144 Mar 15 03:07 INSTALL-BINARY

drwxr-xr-x. 3 mysql mysql  4096 May 26 17:32lib

drwxr-xr-x. 4 mysql mysql  4096 May 26 17:34man

-rw-r--r--. 1 mysql mysql   943 May 26 17:36my.cnf

drwxr-xr-x. 10 mysql mysql  4096 May 26 17:34 mysql-test

-rw-r--r--. 1 mysql mysql  2496 Mar 15 03:07README

drwxr-xr-x. 2 mysql mysql  4096 May 26 17:34scripts

drwxr-xr-x. 28 mysql mysql  4096 May 26 17:34 share

drwxr-xr-x. 4 mysql mysql  4096 May 26 17:34sql-bench

drwxr-xr-x. 3 mysql mysql  4096 May 26 17:34support-files

 

#进行完上面的操作之后,为了安全起见,还是建议将MySQL安装目录的属主修改为root,属组修改为MySQL

[root@localhost mysql56]# chown -R root .

[root@localhost mysql56]# ls -l

total 164

drwxr-xr-x. 2 root mysql  4096 May 26 17:34bin

-rw-r--r--. 1 root mysql 17987 Mar 15 03:07 COPYING

drwxr-xr-x. 5 root mysql  4096 May 26 17:42data

drwxr-xr-x. 2 root mysql  4096 May 26 17:32docs

drwxr-xr-x. 3 root mysql  4096 May 26 17:32include

-rw-r--r--. 1 root mysql 89144 Mar 15 03:07 INSTALL-BINARY

drwxr-xr-x. 3 root mysql  4096 May 26 17:32lib

drwxr-xr-x. 4 root mysql  4096 May 26 17:34man

-rw-r--r--. 1 root mysql   943 May 26 17:36my.cnf

-rw-r--r--. 1 root root    943 May 26 17:42my-new.cnf

drwxr-xr-x. 10 root mysql  4096 May 26 17:34 mysql-test

-rw-r--r--. 1 root mysql  2496 Mar 15 03:07README

drwxr-xr-x. 2 root mysql  4096 May 26 17:34scripts

drwxr-xr-x. 28 root mysql  4096 May 26 17:34 share

drwxr-xr-x. 4 root mysql  4096 May 26 17:34sql-bench

drwxr-xr-x. 3 root mysql  4096 May 26 17:34support-files

――――――――――――――――――――――――――――――

 

2、将mysql的配置文件拷贝到/etc,并给/etc/my.cnf +x权限同时删除其他用户的写权限,仅仅留给root 和工作组 rx权限,其他一律删除连rx权限都删除

[root@localhost mysql56]# cp support-files/my-default.cnf /etc/my.cnf

[root@localhost mysql56]# ls -l /etc/my.cnf

-rw-r--r--. 1 root root 1145 May 26 17:46/etc/my.cnf

#修改my.cnf配置

[root@localhost mysql56]# vim /etc/my.cnf

#[mysqld] 添加如下两行:

basedir = /usr/local/mysql56

datadir = /data/mysql56

[root@localhost mysql56]# egrep"basedir|datadir" /etc/my.cnf -n //查询配置后的结果

18: basedir = /usr/local/mysql56

19: datadir = /data/mysql56

 

3、启动MySQL,最好按照下面的次序去启动MySQL

  初始化MySQL数据库目录

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

[root@localhost mysql56]# netstat -lnt|grep :3306

tcp       0      0 :::3306                     :::*                        LISTEN

 

4、上面是一种启动mysql的方法,还有一种简单的方便,如下:

#mysql的启动服务添加到系统服务中

[root@localhost mysql56]# cp support-files/mysql.server /etc/init.d/mysqld

#赋予启动脚本可执行权限

[root@localhost mysql56]# chmod 700/etc/init.d/mysqld //修改脚本启动权限

[root@localhost mysql56]# ls -l/etc/init.d/mysqld

-rwx------. 1 root root 10882 May 26 17:55/etc/init.d/mysqld

#现在可以使用下面的命令启动mysql

[root@localhost mysql56]# service mysqld restart  //System V风格启动MySQL服务

Shutting down MySQL..140526 17:56:56mysqld_safe mysqld from pid file /data/mysql56/localhost.localdomain.pid ended

 SUCCESS!

Starting MySQL. SUCCESS!

[1]+ Done                   bin/mysqld_safe --user=mysql

 

5MySQL启动成功与否验证:

(1)端口验证:

[root@localhost mysql56]# netstat -lnt|grep :3306

tcp       0      0 :::3306                     :::*                        LISTEN

 

(2)进程验证:

[root@localhost mysql56]# ps -ef |grepmysqld

root     5732     1  0 17:56 pts/2    00:00:00 /bin/sh/usr/local/mysql56/bin/mysqld_safe --datadir=/data/mysql56--pid-file=/data/mysql56/localhost.localdomain.pid

mysql    5871  5732  0 17:56 pts/2    00:00:00 /usr/local/mysql56/bin/mysqld--basedir=/usr/local/mysql56 --datadir=/data/mysql56--plugin-dir=/usr/local/mysql56/lib/plugin --user=mysql--log-error=/data/mysql56/localhost.localdomain.err--pid-file=/data/mysql56/localhost.localdomain.pid

root     5902 12688  0 17:58 pts/2    00:00:00 grep mysqld

 

(3)反查:

[root@localhost mysql56]# lsof -i:3306

COMMAND PID  USER   FD  TYPE DEVICE SIZE/OFF NODE NAME

mysqld 5871 mysql   10u  IPv6 126647      0t0 TCP *:mysql (LISTEN)

(4)查看进程:

[root@localhost mysql56]# ps aux | grepmysqld

root     5732  0.0  0.1 11336  1404 pts/2    S   17:56   0:00 /bin/sh/usr/local/mysql56/bin/mysqld_safe --datadir=/data/mysql56--pid-file=/data/mysql56/localhost.localdomain.pid

mysql    5871  0.4 43.8 1007548 596688pxs/2  Sl   17:56  0:00 /usr/local/mysql56/bin/mysqld --basedir=/usr/local/mysql56--datadir=/data/mysql56 --plugin-dir=/usr/local/mysql56/lib/plugin --user=mysql--log-error=/data/mysql56/localhost.localdomain.err--pid-file=/data/mysql56/localhost.localdomain.pid

root     5905  0.0  0.0 103240  824 pts/2    S+   17:59  0:00 grep mysqld

 

 

6、将mysql服务添加到开机启动项,让mysql服务开机启动

#添加服务到自启动项

[root@localhost ~]# chkconfig --level 3 mysqld on

[root@localhost ~]# chkconfig --list |grepmysqld

mysqld          0:off   1:off  2:on    3:on    4:on   5:on    6:off

 

7、添加环境变量:

[root@localhost mysql56]# mysql

-bash: mysql: command not found

[root@localhost mysql56]# vim /etc/profile

#添加如下两行

PATH=$PATH:/usr/local/mysql56/bin

export PATH

#source生效                                                                

[root@localhost mysql56]# source/etc/profile

#客户端输入验证

[root@localhost mysql56]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.17 Source distribution

 

Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

 

mysql> \q

Bye

默认情况下,MySQL不用输入密码即可进入MySQL数据库系统;因为mysql库中的user表初始化的时候没设置密码哦!

#查看MySQL版本信息:

mysql> select version();

+-----------+

| version() |

+-----------+

| 5.6.17   |

+-----------+

1 row in set (0.06 sec)

 

#查看系统中的所有库

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.07 sec)


8、修改默认root账户密码,默认密码为空

[root@localhost ~]# mysqladmin  -uroot password //建议使用此方法设置密码

回车在接下来的提示中设置新密码即可。。。。。。。

New password:

Confirm new password:

[root@localhost ~]# mysql

ERROR 1045 (28000): Access denied for user'root'@'localhost' (using password: NO)

[root@localhost ~]# mysql -uroot-p'123.com'

Warning: Using a password on the commandline interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 6

Server version: 5.6.17 Source distribution

 

Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

 

9、启动MySQL

[root@localhost ~]#/usr/local/mysql56/bin/mysqld_safe --defaults-file=/etc/my.cnf  &

[1] 6306

[root@localhost ~]# 140526 18:21:55mysqld_safe Logging to '/data/mysql56/localhost.localdomain.err'.

140526 18:21:55 mysqld_safe Starting mysqlddaemon with databases from /data/mysql56

验证MySQL是否被正常启动

[root@localhost mysql56]# netstat -tulanp|grep :3306

tcp       0      0 :::3306                     :::*                        LISTEN      6274/mysqld        

[root@localhost mysql56]# killall mysqld

[root@localhost mysql56]# killall mysqld

mysqld: no process killed

#或者

[root@localhost mysql56]#/etc/init.d/mysqld start

Starting MySQL. SUCCESS!

[root@localhost mysql56]# netstat -tulanp|grep :3306

tcp       0      0 :::3306                     :::*                        LISTEN      6593/mysqld        

[root@localhost mysql56]#

     

10、测试MySQL是否启动

# 1)查看是否有进程mysql

[root@localhost mysql56]# ps -ef | grepmysqld

root     6454     1  0 18:23 pts/0    00:00:00 /bin/sh/usr/local/mysql56/bin/mysqld_safe --datadir=/data/mysql56--pid-file=/data/mysql56/localhost.localdomain.pid

mysql    6593  6454  1 18:23 pts/0    00:00:00 /usr/local/mysql56/bin/mysqld--basedir=/usr/local/mysql56 --datadir=/data/mysql56--plugin-dir=/usr/local/mysql56/lib/plugin --user=mysql--log-error=/data/mysql56/localhost.localdomain.err --pid-file=/data/mysql56/localhost.localdomain.pid

root     6624 12569  0 18:23 pts/0    00:00:00 grep mysqld

# 2)查看端口是否运行

[root@localhost mysql56]# netstat -tulanp|grep :3306

tcp       0      0 :::3306                     :::*                        LISTEN      6593/mysqld

 

11、去除MySQL版本,创建MySQL软链接,方便日后新版本的升级

[root@localhost ~]# ln -s/usr/local/mysql56 /usr/local/mysql

[root@localhost ~]# ll /usr/local/mysql

lrwxrwxrwx. 1 root root 18 May 26 11:18/usr/local/mysql -> /usr/local/mysql56


12修改/etc/my.cnf配置文件

[root@client100 support-files]# vim/etc/my.cnf

# 配置文件内容如下: [目前,这里只做简单配置,下篇文章会详述]

[mysqld]

 basedir = /usr/local/mysql56

 datadir = /data/mysql56

 port= 3306

 server_id = 100

 socket = /usr/local/mysql/mysqld.sock


# 下面是删除mysql数据库中,密码为空的用户

mysql> use mysql;

Database changed

mysql> select database();

+------------+

| database() |

+------------+

| mysql      |

+------------+

1 row in set (0.00 sec)


mysql> select User,Host,Password from user;

+------+-----------------------+-------------------------------------------+

| User | Host                  | Password                                  |

+------+-----------------------+-------------------------------------------+

| root | localhost             | *AC241830FFDDC8943AB31CBD47D758E79F7953EA |

| root | localhost.localdomain |                                           |

| root | 127.0.0.1             |                                           |

| root | ::1                   |                                           |

|      | localhost             |                                           |

|      | localhost.localdomain |                                           |

+------+-----------------------+-------------------------------------------+

6 rows in set (0.01 sec)


mysql> delete from mysql.user where user='';

Query OK, 2 rows affected (0.01 sec)


mysql> select User,Password,Host from user;

+------+-------------------------------------------+-----------------------+

| User | Password                                  | Host                  |

+------+-------------------------------------------+-----------------------+

| root | *AC241830FFDDC8943AB31CBD47D758E79F7953EA | localhost             |

| root |                                           | localhost.localdomain |

| root |                                           | 127.0.0.1             |

| root |                                           | ::1                   |

+------+-------------------------------------------+-----------------------+

4 rows in set (0.00 sec)

mysql> delete from mysql.user where password='';

Query OK, 3 rows affected (0.01 sec)


mysql> select User,Password,Host from user;

+------+-------------------------------------------+-----------+

| User | Password                                  | Host      |

+------+-------------------------------------------+-----------+

| root | *AC241830FFDDC8943AB31CBD47D758E79F7953EA | localhost |

+------+-------------------------------------------+-----------+

1 row in set (0.00 sec)

# 刷新授权表

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)


13、下面来验证建库和建表语句

[root@localhost ~]# mysql -uroot-p'123.com'

Warning: Using a password on the commandline interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.6.17 Source distribution

 

Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

mysql> create database students;

Query OK, 1 row affected (0.00 sec)

 

mysql> use students;

Database changed

mysql> create table test1(

   -> id int(4) not null primary key auto_increment,

   -> name char(20) not null

   -> );

Query OK, 0 rows affected (0.25 sec)

 

mysql> insert into test1(id,name)values(1,'zhangsan');

insert into test1(id,name)values(2,'lisi');

insert into test1(id,name)values(3,'wangwu');

Query OK, 1 row affected (0.02 sec)

 

mysql> insert into test1(id,name)values(2,'lisi');

insert into test1(id,name)values(4,'maliu');

insert into test1(id,name)values(5,'zaqi');

Query OK, 1 row affected (0.07 sec)

 

mysql> insert into test1(id,name)values(3,'wangwu');

Query OK, 1 row affected (0.01 sec)

 

mysql> insert into test1(id,name)values(4,'maliu');

Query OK, 1 row affected (0.01 sec)

 

mysql> insert into test1(id,name)values(5,'zaqi');

insert into test1(id,name)values(6,'zaba');

insert into test1(id,name)values(7,'zaojiu');

insert into test1(id,name)values(8,'wanliu');Query OK, 1 row affected (0.12 sec)

 

mysql> insert into test1(id,name)values(6,'zaba');

Query OK, 1 row affected (0.01 sec)

 

mysql> insert into test1(id,name)values(7,'zaojiu');

Query OK, 1 row affected (0.01 sec)

 

mysql> insert into test1(id,name)values(8,'wanliu');

Query OK, 1 row affected (0.00 sec)

 

mysql> select * from test1;

+----+----------+

| id | name     |

+----+----------+

|  1| zhangsan |

|  2| lisi     |

|  3| wangwu   |

|  4| maliu    |

|  5| zaqi     |

|  6| zaba     |

|  7| zaojiu   |

|  8| wanliu   |

+----+----------+

8 rows in set (0.00 sec)

 

14、最后看一眼字符集:

mysql> SHOW VARIABLES LIKE 'character%';

+--------------------------+------------------------------------+

| Variable_name            | Value                              |

+--------------------------+------------------------------------+

| character_set_client     | utf8                               |

| character_set_connection | utf8                               |

| character_set_database   | utf8                               |

| character_set_filesystem | binary                             |

| character_set_results    | utf8                               |

| character_set_server     | utf8                               |

| character_set_system     | utf8                               |

| character_sets_dir       | /usr/local/mysql56/share/charsets/ |

+--------------------------+------------------------------------+

8 rows in set (0.01 sec)

 

OK,到此,一个基本的MySQL环境算是搭建完毕了,不足之处还请大家多多提出宝贵意见和建议!

                                                                                           

―――――――――――――――――――――――――――――――――――――――

附注:

#建表语句

create table test1(

id int(4) not null primary keyauto_increment,

name char(20) not null

);

 

insert into test1(id,name)values(1,'zhangsan');

insert into test1(id,name)values(2,'lisi');

insert into test1(id,name)values(3,'wangwu');

insert into test1(id,name)values(4,'maliu');

insert into test1(id,name)values(5,'zaqi');

insert into test1(id,name)values(6,'zaba');

insert into test1(id,name)values(7,'zaojiu');

insert into test1(id,name) values(8,'wanliu');

 

#查询结果

mysql> select * from test1;

+----+----------+

| id | name     |

+----+----------+

|  1| zhangsan |

|  2| lisi     |

|  3| wangwu   |

|  4| maliu    |

|  5| zaqi     |

|  6| zaba     |

|  7| zaojiu   |

|  8| wanliu   |

+----+----------+

8 rows in set (0.00 sec)

―――――――――――――――――――――――――――――――――――――――――――――                                                                                                                                                           韩艳威  2014-05-26

本文出自 “Linux运维之路启示录” 博客,请务必保留此出处http://hanyanwei.blog.51cto.com/8672126/1417349