通用二進制包安裝MySQL

實驗環境

1.centOS6.3

2.在centOS上添加一塊10G硬盤,分兩個區,每個500M,做LVM

3.下載mysql-5.5.33-linux2.6-i686.tar.gz包

 

一、添加硬盤並分區

1.在虛擬機中添加一個10G硬盤

wKioL1PwJBTAuY_oAAGQQwb-XZo880.jpg

2.分區

[root@client ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, norSun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier0xa37e9a46.
Changes will remain in memory only, until you decide towrite them.
After that, of course, the previous content won't berecoverable.
 
Warning: invalid flag 0x0000 of partition table 4 will becorrected by w(rite)
 
WARNING: DOS-compatible mode is deprecated. It's stronglyrecommended to
         switch offthe mode (command 'c') and change display units to
         sectors(command 'u').
 
Command (m for help): p
 
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa37e9a46
 
   Device Boot      Start         End      Blocks  Id  System
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305,default 1305): 500M       
 
Command (m for help): p
 
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa37e9a46
 
   Device Boot      Start         End      Blocks  Id  System
/dev/sdb1              1         500     4016218+ 83  Linux
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (501-1305, default 501): 
Using default value 501
Last cylinder, +cylinders or +size{K,M,G} (501-1305,default 1305): +500M
 
Command (m for help): p
 
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa37e9a46
 
   Device Boot      Start         End      Blocks  Id  System
/dev/sdb1              1         500     4016218+ 83  Linux
/dev/sdb2            501         565      522112+ 83  Linux


 

3.將分區修改爲邏輯卷類型

Command(m for help): t
Partitionnumber (1-4): 1
Hexcode (type L to list codes): 8e
Changedsystem type of partition 1 to 8e (Linux LVM)
 
Command(m for help): p
 
Disk/dev/sdb: 10.7 GB, 10737418240 bytes
255heads, 63 sectors/track, 1305 cylinders
Units= cylinders of 16065 * 512 = 8225280 bytes
Sectorsize (logical/physical): 512 bytes / 512 bytes
I/Osize (minimum/optimal): 512 bytes / 512 bytes
Diskidentifier: 0xa37e9a46
 
   Device Boot      Start         End      Blocks  Id  System
/dev/sdb1               1         500    4016218+  8e  Linux LVM
/dev/sdb2             501         565      522112+ 83  Linux
 
Command(m for help): t
Partitionnumber (1-4): 2
Hexcode (type L to list codes): 8e
Changedsystem type of partition 2 to 8e (Linux LVM)
 
Command(m for help): p
 
Disk/dev/sdb: 10.7 GB, 10737418240 bytes
255heads, 63 sectors/track, 1305 cylinders
Units= cylinders of 16065 * 512 = 8225280 bytes
Sectorsize (logical/physical): 512 bytes / 512 bytes
I/Osize (minimum/optimal): 512 bytes / 512 bytes
Diskidentifier: 0xa37e9a46
 
   Device Boot      Start         End      Blocks  Id  System
/dev/sdb1               1         500    4016218+  8e  Linux LVM
/dev/sdb2             501         565      522112+ 8e  Linux LVM


保存

Command(m for help): w
Thepartition table has been altered!
 
Callingioctl() to re-read partition table.
Syncingdisks.


 

二、將分區製作成邏輯卷

1.創建PV

[root@client~]# pvcreate /dev/sdb{1,2}
  Writing physical volume data to disk"/dev/sdb1"
  Physical volume "/dev/sdb1"successfully created
  Writing physical volume data to disk"/dev/sdb2"
  Physical volume "/dev/sdb2"successfully created


2.創建VG

[root@client~]# vgcreate myvg /dev/sdb/{1,2}
  Device /dev/sdb/1 not found (or ignored byfiltering).
  Unable to add physical volume '/dev/sdb/1' tovolume group 'myvg'.
[root@client~]# vgcreate myvg /dev/sdb{1,2}
  Volume group "myvg" successfullycreated
[root@client~]# vgs
  VG       #PV #LV #SN Attr   VSize VFree
  myvg       2   0   0 wz--n- 4.32g 4.32g
  vg_client  1   2   0 wz--n- 9.51g    0


3.創建LV

[root@client~]# lvcreate -L 5G -n mydata myvg 
  Volume group "myvg" hasinsufficient free space (1107 extents): 1280 required.
[root@client~]# lvcreate -L 1G -n mydata myvg 
  Logical volume "mydata" created
[root@client~]# lvs
  LV     VG        Attr     LSize Pool Origin Data%  Move Log Copy%  Convert
  mydata myvg      -wi-a--- 1.00g                                           
  lv_root vg_client -wi-ao-- 7.54g                                           
  lv_swap vg_client -wi-ao-- 1.97g


4.設置文件系統

[root@client~]# mke2fs -t ext4 -L MYDATA -b 4096 /dev/myvg/mydata
mke2fs1.41.12 (17-May-2010)
Filesystemlabel=MYDATA
OStype: Linux
Blocksize=4096 (log=2)
Fragmentsize=4096 (log=2)
Stride=0blocks, Stripe width=0 blocks
65536inodes, 262144 blocks
13107blocks (5.00%) reserved for the super user
Firstdata block=0
Maximumfilesystem blocks=268435456
8block groups
32768blocks per group, 32768 fragments per group
8192inodes per group
Superblockbackups stored on blocks: 
        32768, 98304, 163840, 229376
 
Writinginode tables: done                           
Creatingjournal (8192 blocks): done
Writingsuperblocks and filesystem accounting information: done
 
Thisfilesystem will be automatically checked every 23 mounts or
180days, whichever comes first.  Use tune2fs-c or -i to override.


5.設置開機自動掛載

[root@client~]# vim /etc/fstab
#
#/etc/fstab
#Created by anaconda on Fri Aug 15 05:18:37 2014
#
#Accessible filesystems, by reference, are maintained under '/dev/disk'
#See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_client-lv_root/                       ext4    defaults        1 1
UUID=16663165-0f7e-47cc-a670-5c6d7cc38a08/boot                   ext4    defaults        1 2
/dev/mapper/vg_client-lv_swapswap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
~
~
~
~
LABEL=MYDATA            /mydata                 ext4    defaults        0 0

  

 

 

三、創建掛載點並掛載文件系統

[root@client~]# mkdir /mydata
[root@client~]# mount -a 
[root@client~]# mount
/dev/mapper/vg_client-lv_rooton / type ext4 (rw)
procon /proc type proc (rw)
sysfson /sys type sysfs (rw)
devptson /dev/pts type devpts (rw,gid=5,mode=620)
tmpfson /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1on /boot type ext4 (rw)
noneon /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/myvg-mydataon /mydata type ext4 (rw)
[root@client~]# mkdir /mydata/data
[root@client~]# useradd -r mysql
[root@client~]# id mysql
uid=498(mysql)gid=498(mysql) groups=498(mysql)
[root@client~]# chown -R mysql.mysql /mydata/data/
[root@client~]# ls -ld /mydata/data/
drwxr-xr-x.2 mysql mysql 4096 Aug 15 06:07 /mydata/data/


 

四、安裝MySQL

1.下載

去官方網站下載需要的版本

[root@client ~]# ls 
anaconda-ks.cfg  install.log.syslog
install.log      mysql-5.5.33-linux2.6-i686.tar.gz


2.解壓到指定目錄(這裏是/usr/local/)

[root@client~]# tar xf mysql-5.5.33-linux2.6-i686.tar.gz -C /usr/local/
[root@client~]# cd /usr/local/
[root@clientlocal]# ls 
bin  games   lib      mysql-5.5.33-linux2.6-i686 share
etc  include libexec  sbin                        src


3.做軟鏈接,將mysql-5.5.33-linux2.6-i686鏈接到mysql,方便操作

[root@clientlocal]# ln -sv mysql-5.5.33-linux2.6-i686 mysql        
`mysql'-> `mysql-5.5.33-linux2.6-i686'
[root@clientlocal]# ls 
bin  games   lib      mysql                      sbin   src
etc  include libexec  mysql-5.5.33-linux2.6-i686 share
 
[root@clientlocal]# cd mysql
[root@clientmysql]# ls 
bin      data include         lib  mysql-test scripts  sql-bench
COPYING  docs INSTALL-BINARY  man  README     share    support-files


4.修改權限:將mysql目錄下的所有文件修改成屬主爲root,屬組爲mysql

 

[root@client mysql]# chown -R root:mysql/usr/local/mysql/*
[root@clientmysql]# ls -l
total200
drwxr-xr-x.  2 root mysql  4096 Aug 15 06:09 bin
-rw-r--r--.  1 root mysql 17987 Jul 15  2013 COPYING
drwxr-xr-x.  3 root mysql  4096 Aug 15 06:09 data
drwxr-xr-x.  2 root mysql  4096 Aug 15 06:09 docs
drwxr-xr-x.  3 root mysql  4096 Aug 15 06:09 include
-rw-r--r--.  1 root mysql 134493 Jul 15  2013 INSTALL-BINARY
drwxr-xr-x.  3 root mysql  4096 Aug 15 06:09 lib
drwxr-xr-x.  4 root mysql  4096 Aug 15 06:09 man
drwxr-xr-x.10 root mysql   4096 Aug 15 06:09mysql-test
-rw-r--r--.  1 root mysql  2496 Jul 15  2013 README
drwxr-xr-x.  2 root mysql  4096 Aug 15 06:09 scripts
drwxr-xr-x.27 root mysql   4096 Aug 15 06:09 share
drwxr-xr-x.  4 root mysql  4096 Aug 15 06:09 sql-bench
drwxr-xr-x.  3 root mysql  4096 Aug 15 06:09 support-files


support-files內的文件基本都是配置模版,複製需要的模版到/etc下適當修改即可

[root@clientmysql]# cd support-files/
[root@clientsupport-files]# ls 
binary-configure   my-huge.cnf             mysqld_multi.server
config.huge.ini    my-innodb-heavy-4G.cnf  mysql-log-rotate
config.medium.ini  my-large.cnf            mysql.server
config.small.ini   my-medium.cnf           ndb-config-2-node.ini
magic              my-small.cnf            solaris
[root@clientsupport-files]# cp my-large.cnf /etc/my.cnf
[root@clientsupport-files]# vim /etc/my.cnf


在[mysqld]下添加datadir=/mydata/data

五、初始化MySQL

1.複製啓動腳本,並加入開機自啓動

[root@clientsupport-files]# cp mysql.server /etc/rc.d/init.d/mysqld
[root@clientsupport-files]# chkconfig --add mysqld
[root@clientsupport-files]# chkconfig --list mysqld
mysqld          0:off   1:off  2:on    3:on    4:on   5:on    6:off


2.啓動服務

[root@clientsupport-files]# service mysqld start
StartingMySQL. ERROR! The server quit without updating PID file (/mydata/data/client.com.pid).


啓動服務失敗,提示沒有更新PID文件,並在/mydata/data/目錄下生成錯誤文件

[root@clientsupport-files]# ls /mydata/data/
client.com.err


進入目錄查看文件內容

[root@clientsupport-files]# cd /mydata/data/
[root@clientdata]# ls 
client.com.err
[root@clientdata]# tail client.com.err
14081506:20:56 mysqld_safe Starting mysqld daemon with databases from /mydata/data
/usr/local/mysql/bin/mysqld:error while loading shared libraries: libaio.so.1: cannot open shared objectfile: No such file or directory
14081506:20:56 mysqld_safe mysqld from pid file /mydata/data/client.com.pid ended


報錯中表明:1.缺少libaio.so 2.缺少MySQL自身需要的數據庫表

刪除/mydata/data/下的文件,使用mysql_install_db腳本創建MySQL的初始化表

 [root@client /]# cd /usr/local/mysql
[root@clientmysql]# ls 
bin      data include         lib  mysql-test scripts  sql-bench
COPYING  docs INSTALL-BINARY  man  README     share    support-files
[root@clientmysql]# rm -rf /mydata/data/*
[root@clientmysql]# ls 
bin      data include         lib  mysql-test scripts  sql-bench
COPYING  docs INSTALL-BINARY  man  README     share    support-files
[root@clientmysql]# ls scripts/
mysql_install_db


3.執行初始化腳本命令,指明用戶和目錄

[root@clientmysql]#scripts/mysql_install_db--user=mysql --datadir=/mydata/data/
InstallingMySQL system tables...
./bin/mysqld:error while loading shared libraries: libaio.so.1: cannot open shared objectfile: No such file or directory
 
Installationof system tables failed!  Examine thelogs in
/mydata/data/for more information.
 
Youcan try to start the mysqld daemon with:
 
    shell> ./bin/mysqld --skip-grant &
 
anduse the command line tool ./bin/mysql
toconnect to the mysql database and look at the grant tables:
 
    shell> ./bin/mysql -u root mysql
    mysql> show tables
 
Try'mysqld --help' if you have problems with paths.  Using --log
givesyou a log in /mydata/data/ that may be helpful.
 
Pleaseconsult the MySQL manual section
'Problemsrunning mysql_install_db', and the manual section that
describesproblems on your OS.  Another informationsource are the
MySQLemail archives available at http://lists.mysql.com/.
 
Pleasecheck all of the above before mailing us! And remember, if
youdo mail us, you MUST use the ./bin/mysqlbug script!


再次報錯,提醒安裝libaio.so文件

4.安裝依賴包:yum查找libaio相關文件

 

[root@client mysql]# yum list all *libaio*
Loadedplugins: fastestmirror
Loadingmirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * epel: mirrors.ustc.edu.cn
 * extras: mirrors.btte.net
 * updates: mirrors.btte.net
AvailablePackages
libaio.i686                                    0.3.107-10.el6                                base
libaio-devel.i686                               0.3.107-10.el6                                base


安裝

[root@clientmysql]# yum install libaio.i686 libaio-devel.i686


5.再次執行腳本初始化

 

[root@client mysql]# scripts/mysql_install_db--user=mysql --datadir=/mydata/data
InstallingMySQL system tables...
OK
Fillinghelp tables...
OK


 

 

[root@clientmysql]# ls /mydata/data/
mysql  mysql-bin.000001  mysql-bin.000002  mysql-bin.index  performance_schema  test


6.再次啓動mysqld服務

[root@clientmysql]# service mysqld start
StartingMySQL.... SUCCESS!


啓動成功

查看3306端口是否啓用

[root@clientmysql]# ss –tanl


 

六、連接mysql

[root@clientmysql]# mysql
-bash:mysql: command not found


提示沒找到命令,原因是mysql相關命令路徑在/usr/local/mysql/bin/中,並沒有加入環境變量,所以無法找到。

 

[root@client mysql]# ls /usr/local/mysql/bin/
innochecksum       mysqlbinlog                 mysqldump                  mysqlslap
msql2mysql         mysqlbug                    mysqldumpslow              mysqltest
myisamchk          mysqlcheck                  mysql_embedded             mysqltest_embedded
myisam_ftdump      mysql_client_test           mysql_find_rows            mysql_tzinfo_to_sql
myisamlog          mysql_client_test_embedded  mysql_fix_extensions       mysql_upgrade
myisampack         mysql_config                mysqlhotcopy               mysql_waitpid
my_print_defaults  mysql_convert_table_format  mysqlimport                mysql_zap
mysql              mysqld                      mysql_plugin               perror
mysqlaccess        mysqld-debug                mysql_secure_installation  replace
mysqlaccess.conf   mysqld_multi                mysql_setpermission        resolveip
mysqladmin         mysqld_safe                 mysqlshow                  resolve_stack_dump


寫一個腳本,將mysql二進制命令路徑加入環境變量

[root@clientmysql]# vim /etc/profile.d/mysql.sh
~exportPATH=/usr/local/mysql/bin/:$PATH
 
"/etc/profile.d/mysql.sh"[New] 1L, 39C written


讀取腳本(注意這裏的點表示source,與後面的腳本路徑之間有空格)                               

 

[root@client mysql]# . /etc/profile.d/mysql.sh
再次執行mysql
[root@clientmysql]# mysql
Welcometo the MySQL monitor.  Commands end with; or \g.
YourMySQL connection id is 1
Serverversion: 5.5.33-log MySQL Community Server (GPL)
 
Copyright(c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
 
Oracleis a registered trademark of Oracle Corporation and/or its
affiliates.Other names may be trademarks of their respective
owners.
 
Type'help;' or '\h' for help. Type '\c' to clear the current input statement.


查看mysql版本

mysql>SELECT VERSION();
+------------+
|VERSION()  |
+------------+
|5.5.33-log |
+------------+
1row in set (0.00 sec)


查看有哪些數據庫

mysql>SHOW DATABASES;
+--------------------+
|Database           |
+--------------------+
|information_schema |
|mysql              |
|performance_schema |
|test               |
+--------------------+
4rows in set (0.00 sec)



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章