设为首页 收藏本站
查看: 1192|回复: 0

[经验分享] Centos6.4源码编译安装MySQL5.6.17

[复制链接]
累计签到:77 天
连续签到:1 天
发表于 2014-5-27 08:23:02 | 显示全部楼层 |阅读模式
Centos6.4源码编译安装MySQL5.6.17

首先查看系统版本平台:
[iyunv@localhost ~]# cat /etc/redhat-release
CentOS release 6.4 (Final)
[iyunv@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
[iyunv@localhost ~]#
rpm -ivhhttp://dl.fedoraproject.org/pub/ ... ease-6-8.noarch.rpm
[iyunv@localhost ~]# rpm --import/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
2、安装yum加速组件:
[iyunv@localhost ~]#  yum install yum-plugin-fastestmirror -y
运行yum报错Error: Cannot retrieve metalink for repository: epel. Please verifyits path and try agai
[iyunv@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
——————————————————————————————
[iyunv@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所需环境
[iyunv@localhost ~]# yum -y install makegcc-c++ bison-devel  ncurses-devel

4、编译安装cmake
[iyunv@localhost ~]# wgethttp://wwwNaNake.org/files/v2.8/cmake-2.8.12.2.tar.gz
[iyunv@localhost ~]# tar xfcmake-2.8.12.2.tar.gz
[iyunv@localhost ~]# cd cmake-2.8.12.2
[iyunv@localhost cmake-2.8.12.2]#./configure  --prefix=/usr/local/cmake
[iyunv@localhost cmake-2.8.12.2]# gmake
[iyunv@localhost cmake-2.8.12.2]#makeinstall
5、为cmake增加环境变量
[iyunv@localhost ~]# vim /etc/profile
[iyunv@localhost ~]# source  /etc/profile
[iyunv@localhost ~]# tail -n2 /etc/profile
PATH=$PATH:/usr/local/cmake/bin
export PATH

5、准备MySql用户和组:
[iyunv@localhost ~]# groupadd mysql&& useradd  -s /sbin/nologin  -g mysql -M mysql
[iyunv@localhost ~]# grep mysql /etc/passwd/etc/group
/etc/passwd:mysql:x:500:500::/home/mysql:/sbin/nologin

6、创建MySQL数据存放目录并授权:
[iyunv@localhost ~]# mkdir/data/mysql56  -pv
mkdir: created directory `/data'
mkdir: created directory `/data/mysql56'
[iyunv@localhost ~]# chown -R mysql.mysql/data/mysql56
[iyunv@localhost ~]# ls -ld /data/mysql56
drwxr-xr-x. 2 mysql mysql 4096 May 21 00:38/data/mysql56


7、下载并解压MySQL源码包
[iyunv@localhost ~ ]# wgethttp://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.17.tar.gz
[iyunv@localhost ~ ]# tar xfMySQL-5.6/mysql-5.6.17.tar.gz

二、准备编译MySQl
编译源码,组织软件项目
切换到解压后的MySql源码目录中:
解压MySql的命令是:
[iyunv@localhost mysql]# tar xfmysql-5.6.17.tar.gz
[iyunv@localhost mysql]# cd mysql-5.6.17
[iyunv@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
[iyunv@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安装目录的权限:
——————————————————————————————
[iyunv@localhost ~]# cd /usr/local/mysql56
#为了安全起见,安装完成后请修改权限给root用户
[iyunv@localhost mysql56]# chown -Rmysql.mysql .
[iyunv@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
[iyunv@localhost mysql56]#scripts/mysql_install_db --user=mysql
#先进行下一步再做如下权限的修改
[iyunv@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"读执行权限,其他用户无任何权限
[iyunv@localhost mysql56]# chown -Rroot.mysql .
[iyunv@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
[iyunv@localhost ~]# chown  -R mysql.mysql  /data/mysql56
[iyunv@localhost ~]# ls -ld /data/mysql56
drwxr-xr-x. 2 mysql mysql 4096 May 26 16:55/data/mysql56
[iyunv@localhost ~]# cd /usr/local/mysql56
[iyunv@localhost mysql56]# chown -Rmysql.mysql .
[iyunv@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
[iyunv@localhost mysql56]# chown -R root .
[iyunv@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权限都删除
[iyunv@localhost mysql56]# cpsupport-files/my-default.cnf /etc/my.cnf
[iyunv@localhost mysql56]# ls -l /etc/my.cnf
-rw-r--r--. 1 root root 1145 May 26 17:46/etc/my.cnf
#修改my.cnf配置
[iyunv@localhost mysql56]# vim /etc/my.cnf
#[mysqld] 添加如下两行:
basedir = /usr/local/mysql56
datadir = /data/mysql56
[iyunv@localhost mysql56]# egrep"basedir|datadir" /etc/my.cnf -n
18: basedir = /usr/local/mysql56
19: datadir = /data/mysql56

3、启动MySQL,最好按照下面的次序去启动MySQL
[iyunv@localhost mysql56]#scripts/mysql_install_db --basedir=/usr/local/mysql56 --datadir=/data/mysql56 --user=mysql
[iyunv@localhost mysql56]# netstat -lnt|grep :3306
tcp       0      0 :::3306                     :::*                        LISTEN

4、上面是一种启动mysql的方法,还有一种简单的方便,如下:
#将mysql的启动服务添加到系统服务中
[iyunv@localhost mysql56]# cpsupport-files/mysql.server /etc/init.d/mysqld
#赋予启动脚本可执行权限
[iyunv@localhost mysql56]# chmod 700/etc/init.d/mysqld
[iyunv@localhost mysql56]# ls -l/etc/init.d/mysqld
-rwx------. 1 root root 10882 May 26 17:55/etc/init.d/mysqld
#现在可以使用下面的命令启动mysql
[iyunv@localhost mysql56]# service mysqldrestart
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)端口验证:
[iyunv@localhost mysql56]# netstat -lnt|grep :3306
tcp       0      0 :::3306                     :::*                        LISTEN

(2)进程验证:
[iyunv@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)反查:
[iyunv@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)查看进程:
[iyunv@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服务开机启动
#添加服务到自启动项
[iyunv@localhost ~]# chkconfig --level 3mysqld on
[iyunv@localhost ~]# chkconfig --list |grepmysqld
mysqld          0:off   1:off  2:on    3:on    4:on   5:on    6:off

7、添加环境变量:
[iyunv@localhost mysql56]# mysql
-bash: mysql: command not found
[iyunv@localhost mysql56]# vim /etc/profile
#添加如下两行
PATH=$PATH:/usr/local/mysql56/bin
export PATH
#source生效                                                               
[iyunv@localhost mysql56]# source/etc/profile
#客户端输入验证
[iyunv@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> 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账户密码,默认密码为空

[iyunv@localhost ~]# mysqladmin  -uroot password
回车在接下来的提示中设置新密码即可。。。。。。。
New password:
Confirm new password:
[iyunv@localhost ~]# mysql
ERROR 1045 (28000): Access denied for user'root'@'localhost' (using password: NO)
[iyunv@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
[iyunv@localhost ~]#/usr/local/mysql56/bin/mysqld_safe --defaults-file=/etc/my.cnf  &
[1] 6306
[iyunv@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

[iyunv@localhost mysql56]# netstat -tulanp|grep :3306
tcp       0      0 :::3306                     :::*                        LISTEN      6274/mysqld        
[iyunv@localhost mysql56]# killall mysqld
[iyunv@localhost mysql56]# killall mysqld
mysqld: no process killed
#或者
[iyunv@localhost mysql56]#/etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[iyunv@localhost mysql56]# netstat -tulanp|grep :3306
tcp       0      0 :::3306                     :::*                        LISTEN      6593/mysqld        
[iyunv@localhost mysql56]#

10、测试MySQL是否启动
# 1)查看是否有进程mysql
[iyunv@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)查看端口是否运行
[iyunv@localhost mysql56]# netstat -tulanp|grep :3306
tcp       0      0 :::3306                     :::*                        LISTEN      6593/mysqld

11、去除MySQL版本,创建MySQL软链接,方便日后新版本的升级
[iyunv@localhost ~]# ln -s/usr/local/mysql56 /usr/local/mysql
[iyunv@localhost ~]# ll /usr/local/mysql
lrwxrwxrwx. 1 root root 18 May 26 11:18/usr/local/mysql -> /usr/local/mysql56

12修改/etc/my.cnf配置文件
[iyunv@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、下面来验证建库和建表语句
[iyunv@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)
—————————————————————————————————————————————   


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-19663-1-1.html 上篇帖子: mysql 网站程序自动备份脚本 下篇帖子: linux下安装mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表