[root@1inux ~]# fdisk /dev/sda

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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (7859-15665, default 7859):
Using default value 7859
Last cylinder, +cylinders or +size{K,M,G} (7859-15665, default 15665): +20G

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)



重读分区

[root@1inux ~]# partx -a /dev/sda


创建逻辑卷

[root@1inux ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
[root@1inux ~]# vgcreate myvg /dev/sda3
  Volume group "myvg" successfully created
[root@1inux ~]# lvcreate -L 10G -n mydata myvg
  Logical volume "mydata" created
[root@1inux ~]#

[root@1inux ~]# lvs
  LV     VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mydata myvg -wi-a----- 10.00g                                                    


格式化逻辑卷,并制定卷标为:MYDATA:

[root@1inux ~]# mke2fs -t ext4 -L MYDATA /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 width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 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

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@1inux ~]#


编辑/etc/fstab文件  使其开机自动挂载

LABEL=MYDATA            /data                   ext4    defaults        0 0

创建挂载点:

[root@1inux ~]# mkdir /data
[root@1inux ~]# mount -a
[root@1inux ~]# mount
.....
/dev/mapper/myvg-mydata on /data type ext4 (rw)
.....

在/data目录下创建子目录mydata专门用于存放数据库

[root@1inux ~]# cd /data/
[root@1inux data]# mkdir mydata
[root@1inux data]# ls
lost+found  mydata


安装mysql

[root@1inux ~]# ls
anaconda-ks.cfg  install.log.syslog
install.log      mariadb-5.5.40-linux-x86_64.tar.gz
[root@1inux ~]# tar xf mariadb-5.5.40-linux-x86_64.tar.gz -C /usr/local        //将mariadb解压至/usr/local目录
[root@1inux ~]#

[root@1inux local]# ln -sv mariadb-5.5.40-linux-x86_64/ mysql    //创建软连接
`mysql' -> `mariadb-5.5.40-linux-x86_64/'
[root@1inux local]#

[root@1inux mysql]# ls -l
total 220
drwxr-xr-x  2 root root   4096 May  1 20:18 bin
-rw-r--r--  1  500  500  17987 Oct  8  2014 COPYING
-rw-r--r--  1  500  500  26545 Oct  8  2014 COPYING.LESSER
drwxr-xr-x  3 root root   4096 May  1 20:18 data
-rw-r--r--  1  500  500   8245 Oct  8  2014 EXCEPTIONS-CLIENT
drwxr-xr-x  3 root root   4096 May  1 20:18 include
-rw-r--r--  1  500  500   8694 Oct  8  2014 INSTALL-BINARY
drwxr-xr-x  3 root root   4096 May  1 20:18 lib
drwxr-xr-x  4 root root   4096 May  1 20:18 man
drwxr-xr-x 11 root root   4096 May  1 20:18 mysql-test
-rw-r--r--  1  500  500 108813 Oct  8  2014 README
drwxr-xr-x  2 root root   4096 May  1 20:18 scripts
drwxr-xr-x 27 root root   4096 May  1 20:18 share
drwxr-xr-x  4 root root   4096 May  1 20:18 sql-bench
drwxr-xr-x  3 root root   4096 May  1 20:18 support-files
[root@1inux mysql]#

为mysql 创建系统用户:
[root@1inux mysql]# groupadd -r -g 306 mysql
[root@1inux mysql]# useradd -r -g 306 mysql
[root@1inux mysql]#

为mysql目录下的文件指定属主,属组

[root@1inux mysql]# chown -R root.mysql ./*
[root@1inux mysql]# ls -l
total 220
drwxr-xr-x  2 root mysql   4096 May  1 20:18 bin        //所有二进制文件
-rw-r--r--  1 root mysql  17987 Oct  8  2014 COPYING
-rw-r--r--  1 root mysql  26545 Oct  8  2014 COPYING.LESSER
drwxr-xr-x  3 root mysql   4096 May  1 20:18 data        //存放数据的文件
-rw-r--r--  1 root mysql   8245 Oct  8  2014 EXCEPTIONS-CLIENT
drwxr-xr-x  3 root mysql   4096 May  1 20:18 include        //头文件
-rw-r--r--  1 root mysql   8694 Oct  8  2014 INSTALL-BINARY
drwxr-xr-x  3 root mysql   4096 May  1 20:18 lib        //库文件
drwxr-xr-x  4 root mysql   4096 May  1 20:18 man        //帮助文档
drwxr-xr-x 11 root mysql   4096 May  1 20:18 mysql-test        //mysql测试组件
-rw-r--r--  1 root mysql 108813 Oct  8  2014 README        
drwxr-xr-x  2 root mysql   4096 May  1 20:18 scripts        //补充脚本文件
drwxr-xr-x 27 root mysql   4096 May  1 20:18 share
drwxr-xr-x  4 root mysql   4096 May  1 20:18 sql-bench        //压力测试用
drwxr-xr-x  3 root mysql   4096 May  1 20:18 support-files    //提供支持功能的文件
[root@1inux mysql]#

为存放数据的目录指定权限,为了让mysql能够对其目录的数据有读写等权限
[root@1inux mysql]# chown -R mysql.mysql /data/mydata/
[root@1inux mysql]#


配置mysql配置文件:
    【MySQL的配置文件查找次序:/etc/my.cnf --> /etc/mysql/my.cnf --> ~/.my.cnf】



[root@1inux mysql]# ls -l support-files/
total 80
-rwxr-xr-x 1 root mysql  1153 Oct  9  2014 binary-configure
-rw-r--r-- 1 root mysql  1328 Oct  8  2014 magic
-rw-r--r-- 1 root mysql  4914 Oct  9  2014 my-huge.cnf    //适用于较大内存的环境
-rw-r--r-- 1 root mysql 20418 Oct  9  2014 my-innodb-heavy-4G.cnf    //使用innodb搜索引擎拥有4G内内存的情况
-rw-r--r-- 1 root mysql  4901 Oct  9  2014 my-large.cnf    //适用于有512内存的服务器
-rw-r--r-- 1 root mysql  4914 Oct  9  2014 my-medium.cnf
-rw-r--r-- 1 root mysql  2840 Oct  9  2014 my-small.cnf
-rwxr-xr-x 1 root mysql  1061 Oct  9  2014 mysqld_multi.server
-rwxr-xr-x 1 root mysql   839 Oct  9  2014 mysql-log-rotate
-rwxr-xr-x 1 root mysql 12062 Oct  9  2014 mysql.server
drwxr-xr-x 3 root mysql  4096 May  1 20:18 SELinux
[root@1inux mysql]#


[root@1inux mysql]# mkdir /etc/mysql        //创建目录
[root@1inux mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf
[root@1inux mysql]#


初始化mysql


[root@1inux mysql]# scripts/mysql_install_db --help  查看帮助

  --datadir=path         mysql数据存放的路径
  --defaults-file=name  自定义mysql配置文件路径
  --user=user_name     以哪个用户的身份运行
  --skip-name-resolve  禁止使用DNS做名称反解
  --basedir=path       The path to the MariaDB installation directory.
  --builddir=path      If using --srcdir with out-of-directory builds, you
                       will need to set this to the location of the build
                       directory where built files reside.
  --cross-bootstrap    For internal use.  Used when building the MariaDB system
                       tables on a different host than the target.
  --defaults-extra-file=name
                       Read this file after the global files are read.
  --force              Causes mysql_install_db to run even if DNS does not
                       work.  In that case, grant table entries that normally
                       use hostnames will use IP addresses.
  --help               Display this help and exit.                     
  --ldata=path         The path to the MariaDB data directory. Same as
                       --datadir.
  --no-defaults        Don't read default options from any option file.
  --defaults-file=path Read only this configuration file.
  --rpm                For internal use.  This option is used by RPM files
                       during the MariaDB installation process.
  --srcdir=path        The path to the MariaDB source directory.  This option
                       uses the compiled binaries and support files within the
                       source tree, useful for if you don't want to install
                       MariaDB yet and just want to create the system tables.
-------------------------------------------------------------------------------

[root@1inux mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mydata

[root@1inux mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mydata
WARNING: The host '1inux' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MariaDB version. The MariaDB 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 MariaDB privileges !
Installing MariaDB/MySQL system tables in '/data/mydata' ...
150501 20:48:22 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
OK
Filling help tables...
150501 20:48:22 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
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 MariaDB 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 1inux 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 MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/data/mydata'

You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Support MariaDB development by buying support/new features from
SkySQL Ab. You can contact us about this at [email protected].
Alternatively consider joining our community based development effort:
http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

[root@1inux mysql]#
 
查看是否初始化完成

[root@1inux mysql]# ls -l /data/mydata/
total 1080
-rw-rw---- 1 mysql mysql   16384 May  1 20:48 aria_log.00000001
-rw-rw---- 1 mysql mysql      52 May  1 20:48 aria_log_control
drwx------ 2 mysql root     4096 May  1 20:48 mysql
-rw-rw---- 1 mysql mysql   28391 May  1 20:48 mysql-bin.000001
-rw-rw---- 1 mysql mysql 1038814 May  1 20:48 mysql-bin.000002
-rw-rw---- 1 mysql mysql      38 May  1 20:48 mysql-bin.index
drwx------ 2 mysql mysql    4096 May  1 20:48 performance_schema
drwx------ 2 mysql root     4096 May  1 20:48 test
[root@1inux mysql]#

注:mysql数据库中的每个数据库是以其名字命名的目录


编辑配置文件:
[root@1inux mysql]# vim /etc/mysql/my.cnf

在thread_concurrency = 8 下面添加如下两行:
datadir = /data/mydata        //如果不指定,默认会认为其数据存储目录是安装目录下的data目录
innodb_file_per_table = on


配置服务脚本:
    
[root@1inux mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@1inux mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@1inux mysql]# chkconfig --add mysqld
[root@1inux mysql]# chkconfig --list mysqld
mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@1inux mysql]# service mysqld start
Starting MySQL..                                           [  OK  ]
[root@1inux mysql]#

查看端口:
[root@1inux mysql]# ss -tnl
State       Recv-Q Send-Q        Local Address:Port          Peer Address:Port
LISTEN      0      128                      :::22                      :::*     
LISTEN      0      128                       *:22                       *:*     
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      128                      :::41915                   :::*     
LISTEN      0      50                        *:3306                     *:*        //3306处于监听状态 标明mysql已经成功启动
LISTEN      0      128                       *:59694                    *:*     
LISTEN      0      128                      :::111                     :::*     
LISTEN      0      128                       *:111                      *:*     
[root@1inux mysql]#


编辑文件
[root@1inux mysql]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH

[root@1inux mysql]# . /etc/profile.d/mysql.sh        //重读配置文件


添加man帮助路径

[root@1inux mysql]# vim /etc/man.config
[root@1inux mysql]#

MANPATH /usr/local/mysql/man

输出mysql的头文件至系统头文件路径/usr/include:

[root@1inux mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
`/usr/include/mysql' -> `/usr/local/mysql/include/'
[root@1inux mysql]#


输出mysql的库文件给系统库查找路径:

# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf


而后让系统重新载入系统库:
# ldconfig



添加至服务列表
[root@1inux mysql]# chkconfig --add mysqld
[root@1inux mysql]#  chkconfig mysqld on
[root@1inux mysql]#  chkconfig --list mysqld
mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@1inux mysql]# service mysqld start
Starting MySQL..                                           [  OK  ]
[root@1inux mysql]#





连接mysql
[root@1inux mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.40-MariaDB-log MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>