Centos6.4源碼編譯安裝MySQL5.6.17mysql
首先查看系統版本平臺:c++
[root@localhost ~]# cat /etc/redhat-releaseweb
CentOS release 6.4 (Final)sql
[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/Linuxvim
1、準備工做centos
1、添加epel源安全
[root@localhost ~]#bash
rpm -ivhhttp://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmapp
[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 //解壓
2、準備編譯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
——————————————————————————————————————
3、編譯完成後,繼續下面的操做
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
5、MySQL啓動成功與否驗證:
(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