1、下载到Linux中
mariadb 二进制分发版(类似于windows上的下载解压后可直接运行的绿色软件)的文件名格式为 mariadb-VERSION-OS.tar.gz,其中 VERSION 是版本号,OS表示分发版安装的操作系统类型
可到官网下载:
https://downloads.mariadb.org
2、解压到指定目录,并为解压后的目录创建一个名为mysql的链接
tar xf mysql-5.5.42-linux2.6-x86_64.tar.gz -C /usr/local/
cd /usr/local
ln -s mariadb-5.5.36-linux-x86_64 mysql
[root@node1 ~]# tar -xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local [root@node1 ~]# cd /usr/local [root@node1 local]# ls apache apr apr-util bin etc games include lib lib64 libexec mariadb-5.5.36-linux-x86_64 sbin share src [root@node1 local]# ln -s mariadb-5.5.36-linux-x86_64/ mysql [root@node1 local]# cd mysql [root@node1 mysql]# ls bin COPYING COPYING.LESSER data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files [root@node1 mysql]# less INSTALL-BINARY #查看安装说明 ... The basic commands that you must execute to install and use a MariaDB binary distribution are: shell> groupadd mysql shell> useradd -g mysql mysql shell> cd /usr/local shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf - shell> ln -s full-path-to-mysql-VERSION-OS mysql shell> cd mysql shell> chown -R mysql . shell> chgrp -R mysql . shell> scripts/mysql_install_db --user=mysql shell> chown -R root . shell> chown -R mysql data shell> bin/mysqld_safe --user=mysql & Note ...
3、添加mysql用户和mysql组
mariadb(mysql)是以系统用户mysql的身份运行的,因此这里首先创建一个系统用户mysql
groupadd mysql
useradd -r -g mysql mysql
[root@node1 ~]# useradd -r mysql [root@node1 ~]# id mysql uid=496(mysql) gid=493(mysql) groups=493(mysql)
4、更改目录属主属组
chown -R root:mysql /usr/local/mysql (mysql目录的属主、属组分别设为root和mysql,注意,mysql目录下有个data目录,如果欲将其作为数据目录,其属主应修改为mysql)
[root@node1 mysql]# ll total 212 drwxr-xr-x 2 root root 4096 Jan 3 11:08 bin -rw-r--r-- 1 wittgenstein wittgenstein 17987 Feb 24 2014 COPYING -rw-r--r-- 1 wittgenstein wittgenstein 26545 Feb 24 2014 COPYING.LESSER drwxr-xr-x 3 root root 4096 Jan 3 11:08 data drwxr-xr-x 2 root root 4096 Jan 3 11:08 docs drwxr-xr-x 3 root root 4096 Jan 3 11:08 include -rw-r--r-- 1 wittgenstein wittgenstein 8694 Feb 24 2014 INSTALL-BINARY drwxr-xr-x 3 root root 4096 Jan 3 11:08 lib drwxr-xr-x 4 root root 4096 Jan 3 11:08 man drwxr-xr-x 11 root root 4096 Jan 3 11:08 mysql-test -rw-r--r-- 1 wittgenstein wittgenstein 108813 Feb 24 2014 README drwxr-xr-x 2 root root 4096 Jan 3 11:08 scripts drwxr-xr-x 27 root root 4096 Jan 3 11:08 share drwxr-xr-x 4 root root 4096 Jan 3 11:08 sql-bench drwxr-xr-x 4 root root 4096 Jan 3 11:08 support-files [root@node1 mysql]# chown -R root.mysql . [root@node1 mysql]# ll total 212 drwxr-xr-x 2 root mysql 4096 Jan 3 11:08 bin -rw-r--r-- 1 root mysql 17987 Feb 24 2014 COPYING -rw-r--r-- 1 root mysql 26545 Feb 24 2014 COPYING.LESSER drwxr-xr-x 3 root mysql 4096 Jan 3 11:08 data drwxr-xr-x 2 root mysql 4096 Jan 3 11:08 docs drwxr-xr-x 3 root mysql 4096 Jan 3 11:08 include -rw-r--r-- 1 root mysql 8694 Feb 24 2014 INSTALL-BINARY drwxr-xr-x 3 root mysql 4096 Jan 3 11:08 lib drwxr-xr-x 4 root mysql 4096 Jan 3 11:08 man drwxr-xr-x 11 root mysql 4096 Jan 3 11:08 mysql-test -rw-r--r-- 1 root mysql 108813 Feb 24 2014 README drwxr-xr-x 2 root mysql 4096 Jan 3 11:08 scripts drwxr-xr-x 27 root mysql 4096 Jan 3 11:08 share drwxr-xr-x 4 root mysql 4096 Jan 3 11:08 sql-bench drwxr-xr-x 4 root mysql 4096 Jan 3 11:08 support-files
5、通常应将mariadb(mysql)数据存储于逻辑卷上,易于扩展
先创建两个分区/dev/sda3,4
创建pv:
pvcreate /dev/sda{3,4}
创建vg:
vgcreate myvg /dev/sda{3,4}
创建lv:
lvcreate -L 20G -n mydata myvg
格式化:
mke2fs -t ext4 -L MYDATA -b 4096 -m 3 /dev/myvg/mydata
修改/etc/fstab文件,使其能够自动挂载
LABEL=MYDATA(或UUID或/dev/mapper/myvg-lvdata) /mydata ext4 defaults 0 0
创建挂载点
mkdir /mydata
mount -a
在/mydata下创建data目录,并修改其属主属组
mkdir /mydata/data
chown -R mysql.mysql /mydata/data
这样,mariadb的数据目录就创建好了
[root@node1 mysql]# 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): p Disk /dev/sda: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 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: 0x000f3804 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 1332 10485760 83 Linux /dev/sda3 1332 1593 2097152 82 Linux swap / Solaris Command (m for help): n Command action e extended p primary partition (1-4) e Selected partition 4 First cylinder (1593-3916, default 1593): Using default value 1593 Last cylinder, +cylinders or +size{K,M,G} (1593-3916, default 3916): Using default value 3916 Command (m for help): n First cylinder (1593-3916, default 1593): Using default value 1593 Last cylinder, +cylinders or +size{K,M,G} (1593-3916, default 3916): +10G Command (m for help): t Partition number (1-5): 5 Hex code (type L to list codes): 8e Changed system type of partition 5 to 8e (Linux LVM) Command (m for help): p Disk /dev/sda: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 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: 0x000f3804 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 1332 10485760 83 Linux /dev/sda3 1332 1593 2097152 82 Linux swap / Solaris /dev/sda4 1593 3916 18666534 5 Extended /dev/sda5 1593 2898 10489417+ 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@node1 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 [root@node1 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@node1 mysql]# pvcreate /dev/sda5 Physical volume "/dev/sda5" successfully created [root@node1 mysql]# vgcreate myvg /dev/sda5 Volume group "myvg" successfully created [root@node1 mysql]# lvcreate -L 5G -n mydata myvg Logical volume "mydata" created [root@node1 mysql]# mke2fs -t ext4 -L MYDATA -b 4096 -m 3 /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 327680 inodes, 1310720 blocks 39321 blocks (3.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1342177280 40 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 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 34 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@node1 mysql]# vim /etc/fstab ... LABEL=MYDATA /mydata ext4 defaults 0 0 [root@node1 mysql]# mkdir -p /mydata/data [root@node1 mysql]# mount -a [root@node1 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) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) /dev/mapper/myvg-mydata on /mydata type ext4 (rw) [root@node1 mysql]# chown -R mysql.mysql /mydata/data [root@node1 mysql]# ls -ld /mydata/data drwxr-xr-x 2 mysql mysql 4096 Jan 3 11:36 /mydata/data
6、配置文件
mv /etc/my.cnf /etc/my.cnf.bak(若存在其它版本的配置文件,则将其屏蔽)
cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
[root@node1 mysql]# ls support-files/ #support-files目录下存放着适用于各种内存大小的配置文件及服务脚本等 binary-configure config.medium.ini magic my-innodb-heavy-4G.cnf my-medium.cnf mysqld_multi.server mysql.server SELinux config.huge.ini config.small.ini my-huge.cnf my-large.cnf my-small.cnf mysql-log-rotate ndb-config-2-node.ini solaris [root@node1 mysql]# cp support-files/my-large.cnf /etc/my.cnf
7、修改数据目录
vim /etc/my.cnf
其中datadir = /mydata/data(你所指定的数据目录)
[root@node1 mysql]# vim /etc/my.cnf ... # The MariaDB server [mysqld] port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 256M max_allowed_packet = 1M table_open_cache = 256 sort_buffer_size = 1M read_buffer_size = 1M read_rnd_buffer_size = 4M myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size= 16M datadir = /mydata/data #添加这一项
8、初始化数据库
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
[root@node1 mysql]# ls scripts/ mysql_install_db [root@node1 mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data Installing MariaDB/MySQL system tables in '/mydata/data' ... 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 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 node1 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='/mydata/data' 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@node1 mysql]# ls /mydata/data/ aria_log.00000001 aria_log_control mysql mysql-bin.000001 mysql-bin.000002 mysql-bin.index performance_schema test
9、服务脚本
cp support-files/mysql.server /etc/rc.d/init.d/mysqld (服务脚本)
chkconfig --add mysqld
chkconfig mysqld on
[root@node1 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [root@node1 mysql]# chkconfig --add mysqld [root@node1 mysql]# chkconfig mysql on [root@node1 mysql]# chkconfig --list mysqld mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
10、启动mysqld服务,并查看3306端口是否已处于监听状态
service mysqld start
ss -tnl
[root@node1 mysql]# service mysqld start Starting MySQL... SUCCESS! [root@node1 mysql]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 :::58351 :::* LISTEN 0 128 :::111 :::* LISTEN 0 128 *:111 *:* LISTEN 0 128 :::22 :::* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 128 ::1:631 :::* LISTEN 0 128 *:50903 *:* LISTEN 0 10 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:6011 *:* LISTEN 0 128 ::1:6011 :::* LISTEN 0 50 *:3306 *:*
11、设置PATH环境变量
vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
[root@node1 mysql]# vim /etc/profile.d/mysql.sh export PATH=/usr/local/mysql/bin:$PATH [root@node1 mysql]# source !$ source /etc/profile.d/mysql.sh
12、导出帮助文件
vim /etc/man.config
MANPATH /usr/local/mysql/man
[root@node1 mysql]# vim /etc/man.config MANPATH /usr/local/mysql/man
13、导出头文件
ln -sv /usr/local/mysql/include /usr/include/mysql
[root@node1 mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql
14、导出lib库
vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@node1 mysql]# vim /etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib