[root@mysql ~]# groupadd -r mysql
[root@mysql ~]# useradd -g mysql -r -s /sbin/nologin mysql
4.创建mysql的数据目录(创建逻辑卷存放数据)
[root@mysql ~]# fdisk /dev/sda #创建一个新分区类型为8e
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x0000a0a2
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1301 10240000 83 Linux
/dev/sda3 1301 1938 5120000 83 Linux
/dev/sda4 1938 2611 5405696 5 Extended
/dev/sda5 1939 2066 1024000 82 Linux swap / Solaris
/dev/sda6 1938 1938 1129+ 83 Linux
/dev/sda7 2066 2327 2099724 8e Linux LVM
[root@mysql ~]# partx -a /dev/sda #让内核重新读取一下分区
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
[root@mysql ~]# fdisk -l #查看新建的分区
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x0000a0a2
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1301 10240000 83 Linux
/dev/sda3 1301 1938 5120000 83 Linux
/dev/sda4 1938 2611 5405696 5 Extended
/dev/sda5 1939 2066 1024000 82 Linux swap / Solaris
/dev/sda6 1938 1938 1129+ 83 Linux
/dev/sda7 2066 2327 2099724 8e Linux LVM
Partition table entries are not in disk order
[root@mysql ~]# yum install -y lvm2 #安装lvm
[root@mysql ~]# pvcreate /dev/sda7 #创建物理卷
Physical volume "/dev/sda7" successfully created
[root@mysql ~]# vgcreate myvg /dev/sda7 #创建卷组
Volume group "myvg" successfully created
[root@mysql ~]# lvcreate -L 1G -n mydata myvg #创建逻辑卷
Logical volume "mydata" created
[root@mysql ~]# lvs #查看逻辑卷
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
mydata myvg -wi-a---- 1.00g
[root@mysql ~]# mkfs.ext4 /dev/myvg/mydata #格式化
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
5.挂载设置
[root@mysql ~]# mkdir /mydata #创建挂载目录
[root@mysql ~]# vim /etc/fstab #修改挂载配置文件
#新增一行
/dev/myvg/mydata /mydata ext3 defaults 0 0
[root@mysql ~]# mount -a #挂载
[root@mysql ~]# mount #查看所有挂载
/dev/sda2 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)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda3 on /data type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/myvg-mydata on /mydata type ext4 (rw)
6.数据目录配置
[root@mysql ~]# cd /mydata/
[root@mysql mydata]# mkdir data
[root@mysql mydata]# chown -R mysql.mysql data
[root@mysql mydata]# ll
总用量 20
drwxr-xr-x 2 mysql mysql 4096 7月 18 13:16 data
drwx------ 2 root root 16384 7月 18 13:10 lost+found
[root@mysql ~]# /usr/local/mysql/scripts/mysql_install_db --datadir=/mydata/data --user=mysql
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
[root@mysql data]# ls #查看生成的文件
ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema test
[root@mysql data]# cd /usr/local/mysql/
[root@mysql mysql]# ls
bin data include lib my.cnf README share support-files
COPYING docs INSTALL-BINARY man mysql-test scripts sql-bench
#在/usr/local/mysql目录下自动生成my.cnf的配置文件
[root@mysql mysql]# cat my.cnf #查看一下配置文件
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[root@mysql mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.12-log Source distribution
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
[root@web httpd]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/Osize (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000a0a2
Device Boot Start End Blocks Id System
/dev/sda1* 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda226 1301 10240000 83 Linux
/dev/sda31301 1938 5120000 83 Linux
/dev/sda41938 2611 5405696 5 Extended
/dev/sda51939 2066 1024000 82 Linux swap / Solaris
[root@web httpd]#
(3). 创建逻辑分区
[root@web ~]# fdisk /dev/sda
/dev/sda72066 2327 2099724 8e Linux LVM #我这里是测试环境就创建了一个2G分区
[root@web ~]# partx -a /dev/sda #告诉内核有关存在和磁盘上的分区的编号
[root@web ~]# pvcreate /dev/sda7 #创建物理卷
Physical volume "/dev/sda7"successfully created
[root@web ~]# vgcreate myvg /dev/sda7 #创建卷组
Volume group "myvg"successfully created
[root@web ~]#
[root@web ~]# lvcreate -n mydata -L 1G myvg #创建一个1G的逻辑卷
Logical volume "mydata"created
[root@web ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
mydata myvg -wi-a---- 1.00g
[root@web ~]#
[root@web ~]# mkfs.ext4 /dev/myvg/mydata #格式化
[root@web ~]# mkdir /mydata #创建挂载目录
[root@web ~]# mount /dev/myvg/mydata /mydata/ #挂载
[root@web ~]# vim /etc/fstab
/dev/myvg/mydata/mydataext4 defaults 0 0 #增加这一行
[root@web ~]# mount –a #测试挂载是否成功
[root@web ~]# mount
/dev/sda2on / typeext4 (rw)
proc on /proctypeproc (rw)
sysfs on /systypesysfs (rw)
devpts on /dev/ptstypedevpts (rw,gid=5,mode=620)
tmpfs on /dev/shmtypetmpfs (rw)
/dev/sda1on /boottypeext4 (rw)
/dev/sda3on /datatypeext4 (rw)
none on /proc/sys/fs/binfmt_misctypebinfmt_misc (rw)
/dev/mapper/myvg-mydataon /mydatatypeext4 (rw)
[root@web ~]#
(4). 为了便于管理在/mydata目录下再创建个子目录data用于存放数据
[root@web ~]# mkdir /mydata/data
[root@web ~]# ls /mydata/
data lost+found
2. 新建用户以安全方式运行进程
[root@web ~]# groupadd -r mysql
[root@web ~]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
[root@web ~]# chown -R mysql:mysql /mydata/data
3. 安装并初始化mysql5.6.12
(1). 通用二进制包安装
[root@web src]# tar -xf mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ #-C指定解压目录
[root@web local]# ln -sv mysql-5.6.12-linux-glibc2.5-x86_64/ mysql #创建软链接
`mysql' -> `mysql-5.6.12-linux-glibc2.5-x86_64/'
[root@web local]# cd mysql
[root@web mysql]# ls
bin data include lib mysql-testscripts sql-bench
COPYING docs INSTALL-BINARY manREADME share support-files
[root@web mysql]#
[root@web mysql]# chown -R mysql:mysql . #更改属主属组
[root@web mysql]# ll
total 76
drwxr-xr-x 2 mysql mysql 4096 Jun 29 21:12 bin
-rw-r--r-- 1 mysql mysql 17987 May 21 23:18 COPYING
drwxr-xr-x 3 mysql mysql 4096 Jun 29 21:12 data
drwxr-xr-x 2 mysql mysql 4096 Jun 29 21:12 docs
drwxr-xr-x 3 mysql mysql 4096 Jun 29 21:12 include
-rw-r--r-- 1 mysql mysql 7469 May 21 23:18 INSTALL-BINARY
drwxr-xr-x 3 mysql mysql 4096 Jun 29 21:12 lib
drwxr-xr-x 4 mysql mysql 4096 Jun 29 21:12 man
drwxr-xr-x 10 mysql mysql 4096 Jun 29 21:12 mysql-test
-rw-r--r-- 1 mysql mysql 2496 May 21 23:18 README
drwxr-xr-x 2 mysql mysql 4096 Jun 29 21:12 scripts
drwxr-xr-x 28 mysql mysql 4096 Jun 29 21:12 share
drwxr-xr-x 4 mysql mysql 4096 Jun 29 21:12 sql-bench
drwxr-xr-x 3 mysql mysql 4096 Jun 29 21:12 support-files
(2). 执行mysql 初始化的data存放位置的准备
[root@web mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data #执行mysql 初始化的data存放位置的准备
Installing MySQL system tables..../bin/mysqld: error whileloading shared libraries: libaio.so.1: cannot openshared object file: No such fileor directory
#初始化时报错说缺少libaio.so我们安装一下
[root@web mysql]# yum install libaio
[root@web mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data #再次执行mysql 初始化的data存放位置的准备
To start mysqld at boot timeyou have to copy
support-files/mysql.server to the right place foryour system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To doso, start the server, thenissue the following commands:
./bin/mysqladmin-u root password 'new-password'
./bin/mysqladmin-u root -h web.test.com password 'new-password'
Alternatively you can run:
./bin/mysql_secure_installation
whichwill also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended forproduction servers.
See the manual formoreinstructions.
You can start the MySQL daemon with:
cd. ; ./bin/mysqld_safe&
You can testthe MySQL daemon with mysql-test-run.pl
cdmysql-test; perl mysql-test-run.pl
Please report any problems with the ./bin/mysqlbugscript!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licensesat http://shop.mysql.com
WARNING: Found existing config file./my.cnf on the system.
Because this filemight be inuse, it was not replaced,
but was used inbootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config filewas created as ./my-new.cnf,
please compare it with your fileand take the changes you need.
WARNING: Default config file/etc/my.cnf exists on the system
This filewill be readby default by the MySQL server
If you donot want to use this, either remove it, or use the
--defaults-fileargument to mysqld_safe when starting the server
[root@web mysql]#
[root@web mysql]# ls /mydata/data/ #查看 data 目录有文件说明初始化成功
ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema test
[root@web mysql]# cd /usr/local/mysql/
[root@web mysql]# chown root /usr/local/mysql/* -R
[root@web mysql]# ll
total 84
drwxr-xr-x 2 root mysql 4096 Jun 29 21:12 bin
-rw-r--r-- 1 root mysql 17987 May 21 23:18 COPYING
drwxr-xr-x 3 root mysql 4096 Jun 29 21:12 data
drwxr-xr-x 2 root mysql 4096 Jun 29 21:12 docs
drwxr-xr-x 3 root mysql 4096 Jun 29 21:12 include
-rw-r--r-- 1 root mysql 7469 May 21 23:18 INSTALL-BINARY
drwxr-xr-x 3 root mysql 4096 Jun 29 21:12 lib
drwxr-xr-x 4 root mysql 4096 Jun 29 21:12 man
-rw-r--r-- 1 root root 943 Jun 29 21:18 my.cnf
-rw-r--r-- 1 root root 943 Jun 29 21:23 my-new.cnf
drwxr-xr-x 10 root mysql 4096 Jun 29 21:12 mysql-test
-rw-r--r-- 1 root mysql 2496 May 21 23:18 README
drwxr-xr-x 2 root mysql 4096 Jun 29 21:12 scripts
drwxr-xr-x 28 root mysql 4096 Jun 29 21:12 share
drwxr-xr-x 4 root mysql 4096 Jun 29 21:12 sql-bench
drwxr-xr-x 3 root mysql 4096 Jun 29 21:12 support-files
[root@web mysql]#
[root@web mysql]# ll
total 84
drwxr-xr-x 2 root mysql 4096 Jun 29 21:12 bin
-rw-r--r-- 1 root mysql 17987 May 21 23:18 COPYING
drwxr-xr-x 3 root mysql 4096 Jun 29 21:12 data
drwxr-xr-x 2 root mysql 4096 Jun 29 21:12 docs
drwxr-xr-x 3 root mysql 4096 Jun 29 21:12 include
-rw-r--r-- 1 root mysql 7469 May 21 23:18 INSTALL-BINARY
drwxr-xr-x 3 root mysql 4096 Jun 29 21:12 lib
drwxr-xr-x 4 root mysql 4096 Jun 29 21:12 man
-rw-r--r-- 1 root root 943 Jun 29 21:18 my.cnf
-rw-r--r-- 1 root root 943 Jun 29 21:23 my-new.cnf
drwxr-xr-x 10 root mysql 4096 Jun 29 21:12 mysql-test
-rw-r--r-- 1 root mysql 2496 May 21 23:18 README
drwxr-xr-x 2 root mysql 4096 Jun 29 21:12 scripts
drwxr-xr-x 28 root mysql 4096 Jun 29 21:12 share
drwxr-xr-x 4 root mysql 4096 Jun 29 21:12 sql-bench
drwxr-xr-x 3 root mysql 4096 Jun 29 21:12 support-files
[root@web mysql]#
[root@web mysql]# cat my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[root@web mysql]#
[root@web mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection idis 1
Server version: 5.6.12-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/orits affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/orits
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or '\h'forhelp. Type '\c'to clearthe current input statement.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test|
+--------------------+
4 rows inset(0.02 sec)
mysql>
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.03 sec)