mysql数据库的安装配置

mysql二进制包的安装过程
 
#解压二进制包到/usr/local
[root@station58 ~]# tar -vxf mysql-5.5.19-linux2.6-i686.tar.gz -C /usr/local
#为解压的包创建软链接
[root@station58 ~]# cd /usr/local
[root@station58 local]# ln -sv mysql-5.5.19-linux2.6-i686 mysql
 
#创建mysql组和用户
[root@station58 local]# groupadd mysql
[root@station58 local]# useradd -g mysql -s /sbin/nologin -M mysql
[root@station58 local]# id mysql
 
#更改mysql目录的属主和属组
[root@station58 local]# cd mysql
[root@station58 mysql]# chown -R mysql:mysql ./
[root@station58 mysql]# ll
 
#创建磁盘分区
[root@station58 mysql]# fdisk /dev/sdb
#查看磁盘分区情况
Command (m for help): p
#创建新分区大小为10G
Command (m for help): n
First cylinder (3652-15665, default 3652):
Using default value 3652
Last cylinder or +size or +sizeM or +sizeK (3652-15665, default 15665): +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): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#系统内核重读磁盘分区信息
[root@station58 mysql]# partprobe /dev/sdb
 
#创建物理卷
[root@station58 mysql]# pvcreate /dev/sdb5
  Physical volume "/dev/sdb5" successfully created           #此行表示物理卷创建成功

#创建逻辑卷组
[root@station58 mysql]# vgcreate myvg /dev/sdb5 
/dev/cdrom: open failed: Read-only file system
  Attempt to close device '/dev/cdrom' which is not open.
  Volume group "myvg" successfully created                         #此行表示逻辑卷组创建成功
[root@station58 mysql]# lvcreate -L 3G -n mydata myvg
  Logical volume "mydata" created
[root@station58 mysql]# lvs
  LV       VG         Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  LogVol00 VolGroup00 -wi-ao 118.88G                                     
  LogVol01 VolGroup00 -wi-ao   1.00G                                     
  mydata   myvg       -wi-a-   3.00G                                                 #此行表示逻辑卷创建成功
 
#格式化文件系统
[root@station58 mysql]# mke2fs -j -L MYDATA -b 2048 /dev/myvg/mydata
mke2fs 1.39 (29-May-2006)
Filesystem label=MYDATA
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
393216 inodes, 1572864 blocks
78643 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=538968064
96 block groups
16384 blocks per group, 16384 fragments per group
4096 inodes per group
Superblock backups stored on blocks:
 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
 
#创建挂载点
[root@station58 mysql]# mkdir /mydata
#在/etc/fstab中添加一行在开机自动挂载
[root@station58 mysql]# vim /etc/fstab
LABEL=MYDATA            /mydata                 ext3    defaults        0 0     
#手动挂载
[root@station58 mysql]# mount -a
#查看是否挂载
[root@station58 mysql]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /media/cdrom type iso9660 (ro)
/dev/mapper/myvg-mydata on /mydata type ext3 (rw)              #表示已经挂载上
 
#创建mysql服务的数据存放目录并修改属主属组
[root@station58 mysql]# mkdir /mydata/data
[root@station58 mysql]# chown -R mysql:mysql /mydata/data
[root@station58 mysql]# ll /mydata
total 20
drwxr-xr-x 2 mysql mysql  2048 Feb  4 17:55 data
 
#初始化mysql数据库并修改mysql目录的属主为ROOT用户
[root@station58 mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
[root@station58 mysql]# chown -R root ./
[root@station58 mysql]# ll
total 132
drwxr-xr-x  2 root mysql  4096 Feb  4 17:12 bin
-rw-r--r--  1 root mysql 17987 Nov 23 20:46 COPYING
drwxr-xr-x  4 root mysql  4096 Feb  4 17:13 data
drwxr-xr-x  2 root mysql  4096 Feb  4 17:12 docs
drwxr-xr-x  3 root mysql  4096 Feb  4 17:12 include
-rw-r--r--  1 root mysql  7370 Nov 23 20:46 INSTALL-BINARY
drwxr-xr-x  3 root mysql  4096 Feb  4 17:13 lib
drwxr-xr-x  4 root mysql  4096 Feb  4 17:12 man
drwxr-xr-x 10 root mysql  4096 Feb  4 17:12 mysql-test
-rw-r--r--  1 root mysql  2552 Nov 23 20:46 README
drwxr-xr-x  2 root mysql  4096 Feb  4 17:12 scripts
drwxr-xr-x 27 root mysql  4096 Feb  4 17:13 share
drwxr-xr-x  4 root mysql  4096 Feb  4 17:12 sql-bench
drwxr-xr-x  2 root mysql  4096 Feb  4 17:12 support-files
 
#为mysql服务添加主配置文件
[root@station58 mysql]# cd support-files/
[root@station58 support-files]# cp my-large.cnf /etc/my.cnf
[root@station58 support-files]# vim /etc/my.cnf
#在主配置文件中添加一行数据的存放位置
datadir = /mydata/data
 
 
#为mysql服务添加命令mysqld并使用命令启动服务
[root@station58 support-files]# cp mysql.server /etc/init.d/mysqld
[root@station58 support-files]# service mysqld start
Starting MySQL...........                                  [  OK  ]
 
#添加mysql为开机启动项
[root@station58 support-files]# chkconfig --add mysqld
[root@station58 support-files]# chkconfig --list mysqld
mysqld          0:off 1:off 2:on 3:on 4:on 5:on 6:off
 
#查看mysql服务的3306端口
[root@station58 support-files]# netstat -tnlp
tcp        0      0 :::3306                     :::*        LISTEN  13587/mysqld

#添加使用mysql命令来连接数据库并使用mysql命令连接验证是否成功
[root@station58 mysql]# vim /etc/profile
PATH=$PATH:/usr/local/mysql/bin
[root@station58 mysql]# . /etc/profile
[root@station58 mysql]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/ usr/local/mysql/bin
[root@station58 support-files]# mysql
mysql> \q;

#为mysql的头文件创建软链接
[root@station58 support-files]# cd ..
[root@station58 mysql]# ln -sv /usr/local/mysql/include /usr/include/mysql
#为系统添加mysql的库文件并查看是否添加成功
[root@station58 mysql]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@station58 mysql]# ldconfig -v | grep libmysql
  libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0
 
#为man命令加上mysql的帮助文档并查看mysqld的帮助信息
[root@station58 mysql]# vim /etc/man.config
MANPATH /usr/local/mysql/man
[root@station58 mysql]# man mysqld
 
到此mysql服务安装成功

本文出自 “成功每一天” 博客,请务必保留此出处http://1567045.blog.51cto.com/1557045/772367

你可能感兴趣的:(mysql,二进制,用户,包,local)