Centos6.4平台安装MySQL
平台:centos6.4
MySQL:mysql-5.5.33-linux2.6-x86_64.tar.gz
一,搭建LVM,以及安装前的准备:
#查看当前磁盘的分区(这里单独拿一块新加磁盘做LVM)
[root@magine356wj ~]# fdisk -l /dev/sdb Disk /dev/sdb: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 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: 0x946065d9 Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux /dev/sdb2 1307 2612 10490445 83 Linux /dev/sdb3 2613 3918 10490445 83 Linux /dev/sdb4 3919 15665 94357777+ 5 Extended /dev/sdb5 3919 7835 31463271 83 Linux /dev/sdb6 7836 11752 31463271 83 Linux
#修改磁盘属性为8e(磁盘8e为LVM)
[root@magine356wj ~]# fdisk /dev/sdb WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to switch off the mode (command ‘c‘) and change display units to sectors (command ‘u‘). Command (m for help): t Partition number (1-6): 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): t Partition number (1-6): 6 Hex code (type L to list codes): 8e Changed system type of partition 6 to 8e (Linux LVM) Command (m for help): t Partition number (1-6): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@magine356wj ~]# fdisk -l /dev/sdb Disk /dev/sdb: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 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: 0x946065d9 Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 8e Linux LVM /dev/sdb2 1307 2612 10490445 8e Linux LVM /dev/sdb3 2613 3918 10490445 83 Linux /dev/sdb4 3919 15665 94357777+ 5 Extended /dev/sdb5 3919 7835 31463271 83 Linux /dev/sdb6 7836 11752 31463271 8e Linux LVM
#创建LVM
[root@magine356wj ~]# pvcreate /dev/sdb{1,2,6} Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdb2" successfully created Physical volume "/dev/sdb6" successfully created [root@magine356wj ~]# vgcreate myvg /dev/sdb{1,2,6} Volume group "myvg" successfully created [root@magine356wj ~]# vgs VG #PV #LV #SN Attr VSize VFree myvg 3 0 0 wz--n- 50.00g 50.00g vg_magine356wj 1 3 0 wz--n- 119.51g 0 [root@magine356wj ~]# lvcreate -L 20G -n mydata myvg Logical volume "mydata" created [root@magine356wj ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert mydata myvg -wi-a---- 20.00g lv_home vg_magine356wj -wi-ao--- 67.57g lv_root vg_magine356wj -wi-ao--- 50.00g lv_swap vg_magine356wj -wi-ao--- 1.94g [root@magine356wj ~]# mke2fs -t ext4 -L MYDATA -b 4096 /dev/myvg/mydata mke2fs 1.41.12 (17-May-2010) Filesystem label=MYDATA OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe blocks 1310720 inodes, 5242880 blocks 262144 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 160 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 26 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
#开机自动挂载LVM
vim /etc/fstab
[root@magine356wj ~]# mkdir /mydata [root@magine356wj ~]# mount -a [root@magine356wj ~]# mount /dev/mapper/vg_magine356wj-lv_root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") /dev/sda1 on /boot type ext4 (rw) /dev/mapper/vg_magine356wj-lv_home on /home type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) /dev/mapper/myvg-mydata on /mydata type ext4 (rw)
#新建用户mysql,并修改相关文件对应属主属组
[root@magine356wj ~]# useradd -r mysql [root@magine356wj ~]# id mysql uid=496(mysql) gid=493(mysql) groups=493(mysql) [root@magine356wj ~]# cd /mydata [root@magine356wj mydata]# mkdir data [root@magine356wj mydata]# chown -R mysql:mysql /mydata/data [root@magine356wj mydata]# ls -ld /mydata/data drwxr-xr-x. 2 mysql mysql 4096 Aug 6 20:10 /mydata/data
二,安装MySQL:
http://dev.mysql.com/downloads/mysql/
下载mysql-5.5.33-linux2.6-x86_64.tar.gz
[root@magine356wj ~]# ls anaconda-ks.cfg install.log.syslog linux-3.10.tar.xz install.log linux-2.6.32.60.tar.xz mysql-5.5.33-linux2.6-x86_64.tar.gz [root@magine356wj ~]# tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local [root@magine356wj ~]# cd /usr/local [root@magine356wj local]# ln -sv mysql-5.5.33-linux2.6-x86_64/ mysql `mysql‘ -> `mysql-5.5.33-linux2.6-x86_64/‘ [root@magine356wj local]# cd mysql/ [root@magine356wj mysql]# chown -R root:mysql /usr/local/mysql/* [root@magine356wj mysql]# ls -l /usr/local/mysql/ total 200 drwxr-xr-x. 2 root mysql 4096 Aug 6 20:16 bin -rw-r--r--. 1 root mysql 17987 Jul 15 2013 COPYING drwxr-xr-x. 3 root mysql 4096 Aug 6 20:17 data drwxr-xr-x. 2 root mysql 4096 Aug 6 20:16 docs drwxr-xr-x. 3 root mysql 4096 Aug 6 20:17 include -rw-r--r--. 1 root mysql 134493 Jul 15 2013 INSTALL-BINARY drwxr-xr-x. 3 root mysql 4096 Aug 6 20:17 lib drwxr-xr-x. 4 root mysql 4096 Aug 6 20:17 man drwxr-xr-x. 10 root mysql 4096 Aug 6 20:17 mysql-test -rw-r--r--. 1 root mysql 2496 Jul 15 2013 README drwxr-xr-x. 2 root mysql 4096 Aug 6 20:17 scripts drwxr-xr-x. 27 root mysql 4096 Aug 6 20:17 share drwxr-xr-x. 4 root mysql 4096 Aug 6 20:17 sql-bench drwxr-xr-x. 3 root mysql 4096 Aug 6 20:17 support-files [root@magine356wj mysql]# cd support-files/ [root@magine356wj support-files]# ls -l total 100 -rwxr-xr-x. 1 root mysql 1153 Jul 15 2013 binary-configure -rwxr-xr-x. 1 root mysql 4528 Jul 15 2013 config.huge.ini -rwxr-xr-x. 1 root mysql 2382 Jul 15 2013 config.medium.ini -rwxr-xr-x. 1 root mysql 1626 Jul 15 2013 config.small.ini -rw-r--r--. 1 root mysql 773 Jul 15 2013 magic -rw-r--r--. 1 root mysql 4691 Jul 15 2013 my-huge.cnf -rw-r--r--. 1 root mysql 19759 Jul 15 2013 my-innodb-heavy-4G.cnf -rw-r--r--. 1 root mysql 4665 Jul 15 2013 my-large.cnf -rw-r--r--. 1 root mysql 4676 Jul 15 2013 my-medium.cnf -rw-r--r--. 1 root mysql 2840 Jul 15 2013 my-small.cnf -rwxr-xr-x. 1 root mysql 1061 Jul 15 2013 mysqld_multi.server -rwxr-xr-x. 1 root mysql 839 Jul 15 2013 mysql-log-rotate -rwxr-xr-x. 1 root mysql 10880 Jul 15 2013 mysql.server -rwxr-xr-x. 1 root mysql 1326 Jul 15 2013 ndb-config-2-node.ini drwxr-xr-x. 2 root mysql 4096 Aug 6 20:17 solaris [root@magine356wj support-files]# cp my-large.cnf /etc/my.cnf cp: overwrite `/etc/my.cnf‘? y [root@magine356wj support-files]# vim /etc/my.cnf
添加语句: datadir = /mydata/data
#添加服务脚本,开机自动运行
[root@magine356wj support-files]# cp mysql.server /etc/rc.d/init.d/mysqld [root@magine356wj support-files]# chkconfig --add mysqld [root@magine356wj support-files]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
#MySQL初始化
[root@magine356wj support-files]# cd .. [root@magine356wj mysql]# ls scripts/ mysql_install_db [root@magine356wj mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data WARNING: The host ‘magine356wj‘ could not be looked up with resolveip. This probably means that your libc libraries are not 100 % compatible with this binary MySQL version. The MySQL daemon, mysqld, should work normally with the exception that host name resolving will not work. This means that you should use IP addresses instead of hostnames when specifying MySQL privileges ! Installing MySQL system tables... OK Filling help tables... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: ./bin/mysqladmin -u root password ‘new-password‘ ./bin/mysqladmin -u root -h magine356wj password ‘new-password‘ Alternatively you can run: ./bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. 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 cd ./mysql-test ; perl mysql-test-run.pl Please report any problems with the ./bin/mysqlbug script!
#启动mysqld,并检查是否监听3306端口
[root@magine356wj mysql]# service mysqld start Starting MySQL... [ OK ] [root@magine356wj mysql]# ss -tanl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 :::111 :::* LISTEN 0 128 *:111 *:* LISTEN 0 128 :::22 :::* LISTEN 0 128 *:22 *:* LISTEN 0 128 :::40054 :::* LISTEN 0 128 *:38550 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:6010 *:* LISTEN 0 128 ::1:6010 :::* LISTEN 0 50 *:3306 *:*
#设置环境变量
#设置man
[root@magine356wj ~]# vim /etc/man.config ########################################################################## 48行后添加语句: MANPATH /usr/local/mysql/man
#添加头文件
[root@magine356wj ~]# ln -sv /usr/local/mysql/include /usr/include/mysql `/usr/include/mysql‘ -> `/usr/local/mysql/include‘ [root@magine356wj ~]# ls /usr/include/mysql/ decimal.h my_attribute.h my_global.h mysqld_ername.h my_sys.h sql_state.h errmsg.h my_compiler.h my_list.h mysqld_error.h my_xml.h sslopt-case.h keycache.h my_config.h my_net.h mysql_embed.h plugin_audit.h sslopt-longopts.h m_ctype.h my_dbug.h my_pthread.h mysql.h plugin_ftparser.h sslopt-vars.h m_string.h my_dir.h mysql mysql_time.h plugin.h typelib.h my_alloc.h my_getopt.h mysql_com.h mysql_version.h sql_common.h
[root@magine356wj mysql]# cd [root@magine356wj ~]# vim /etc/profile profile profile.d/ [root@magine356wj ~]# vim /etc/profile.d/mysql.sh ########################################################################## 添加语句: export PATH = /usr/local/mysql/bin:$PATH [root@magine356wj ~]# . /etc/profile.d/mysql.sh
#添加库文件
[root@magine356wj ~]# vim /etc/ld.so.conf ld.so.conf ld.so.conf.d/ [root@magine356wj ~]# vim /etc/ld.so.conf.d/mysql.conf ########################################################################## 添加语句: /usr/local/mysql/lib [root@magine356wj ~]# ldconfig -v | grep mysql /usr/local/mysql/lib: libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0 /usr/lib64/mysql: libmysqlclient.so.16 -> libmysqlclient.so.16.0.0 libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0
三,安装完成,测试:
[root@magine356wj ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.33-log MySQL Community Server (GPL) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is 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> SELECT VERSION(); +------------+ | VERSION() | +------------+ | 5.5.33-log | +------------+ 1 row in set (0.00 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.01 sec) mysql> \q Bye
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。