1. 创建LVM用于存放mysql的数据库,并挂载到/data 目录下
- [root@www ~]# fdisk -l
- Disk /dev/sda: 128.8 GB, 128849018880 bytes
- 255 heads, 63 sectors/track, 15665 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /dev/sda1 * 1 13 104391 83 Linux
- /dev/sda2 14 5235 41945715 8e Linux LVM
- /dev/sda3 5236 5366 1052257+ 82 Linux swap / Solaris
- Disk /dev/sdb: 21.4 GB, 21474836480 bytes
- 255 heads, 63 sectors/track, 2610 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Disk /dev/sdb doesn't contain a valid partition table
- [root@www ~]# fdisk /dev/sdb
- Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
- Building a new DOS disklabel. Changes will remain in memory only,
- until you decide to write them. After that, of course, the previous
- content won't be recoverable.
- The number of cylinders for this disk is set to 2610.
- There is nothing wrong with that, but this is larger than 1024,
- and could in certain setups cause problems with:
- 1) software that runs at boot time (e.g., old versions of LILO)
- 2) booting and partitioning software from other OSs
- (e.g., DOS FDISK, OS/2 FDISK)
- Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
- Command (m for help): n
- Command action
- e extended
- p primary partition (1-4)
- p
- Partition number (1-4): 1
- First cylinder (1-2610, default 1):
- Using default value 1
- Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): +5G
- Command (m for help): t
- Selected partition 1
- Hex code (type L to list codes): 8e
- Changed system type of partition 1 to 8e (Linux LVM)
- Command (m for help): p
- Disk /dev/sdb: 21.4 GB, 21474836480 bytes
- 255 heads, 63 sectors/track, 2610 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /dev/sdb1 1 609 4891761 8e Linux LVM
- Command (m for help): w
- The partition table has been altered!
- Calling ioctl() to re-read partition table.
- Syncing disks.
- [root@www ~]# partprobe
- [root@www ~]# pvs
- /dev/cdrom: open failed: No medium found
- PV VG Fmt Attr PSize PFree
- /dev/sda2 vol0 lvm2 a-- 40.00G 5.84G
- [root@www ~]# pvcreate /dev/sdb1
- Writing physical volume data to disk "/dev/sdb1"
- Physical volume "/dev/sdb1" successfully created
- [root@www ~]# pvs
- /dev/cdrom: open failed: No medium found
- PV VG Fmt Attr PSize PFree
- /dev/sda2 vol0 lvm2 a-- 40.00G 5.84G
- /dev/sdb1 lvm2 a-- 4.67G 4.67G
- [root@www ~]# vgs
- VG #PV #LV #SN Attr VSize VFree
- vol0 1 2 0 wz--n- 40.00G 5.84G
- [root@www ~]# vgcreate myvg /dev/sdb1
- Volume group "myvg" successfully created
- [root@www ~]# vgs
- VG #PV #LV #SN Attr VSize VFree
- myvg 1 0 0 wz--n- 4.66G 4.66G
- vol0 1 2 0 wz--n- 40.00G 5.84G
- [root@www ~]# lvs
- LV VG Attr LSize Origin Snap% Move Log Copy% Convert
- home vol0 -wi-ao 4.88G
- root vol0 -wi-ao 29.28G
- [root@www ~]# lvcreate -L 2G -n mylv /dev/myvg
- Logical volume "mylv" created
- [root@www ~]# lvs
- LV VG Attr LSize Origin Snap% Move Log Copy% Convert
- mylv myvg -wi-a- 2.00G
- home vol0 -wi-ao 4.88G
- root vol0 -wi-ao 29.28G
- [root@www ~]# mkfs -t ext3 /dev/myvg/mylv
- mke2fs 1.39 (29-May-2006)
- Filesystem label=
- OS type: Linux
- Block size=4096 (log=2)
- Fragment size=4096 (log=2)
- 262144 inodes, 524288 blocks
- 26214 blocks (5.00%) reserved for the super user
- First data block=0
- Maximum filesystem blocks=536870912
- 16 block groups
- 32768 blocks per group, 32768 fragments per group
- 16384 inodes per group
- Superblock backups stored on blocks:
- 32768, 98304, 163840, 229376, 294912
- Writing inode tables: done
- Creating journal (16384 blocks): done
- Writing superblocks and filesystem accounting information: done
- This filesystem will be automatically checked every 29 mounts or
- 180 days, whichever comes first. Use tune2fs -c or -i to override.
- [root@www ~]# mkdir /data
- [root@www ~]# vi /etc/fstab
- [root@www ~]# mount -a
- mount: No medium found
- [root@www ~]# df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/vol0-root
- 29G 2.8G 25G 11% /
- /dev/mapper/vol0-home
- 4.8G 138M 4.4G 4% /home
- /dev/sda1 99M 25M 69M 27% /boot
- tmpfs 252M 0 252M 0% /dev/shm
- /dev/mapper/myvg-mylv
- 2.0G 68M 1.9G 4% /data
1. 新建mysql用户:
# groupadd -r mysql
# useradd -r -g mysql -M -s /sbin/nologin mysql
2. 解压:
# tar xf mysql-5.5.24-linux2.6-i686.tar.gz -C /usr/local
3. 把mysql的数据库文件放在LVM上
# mkdir /data/mysql --> (mysql用户对此目录要有读写权限)
# chown mysql:mysql /data/mysql
4. # cd /usr/local
# ln -s mysql-5.5.24-linux2.6-i686 mysql 创建链接(尽量不要更改原文件名,方便以后升级)
5. 更改属主、属组
# cd mysql
# chown -R mysql:mysql .
6.mysql初始化
# scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql
7. 提供mysql的主配置文件
# cd /usr/local/mysql
# cp support-files/my-large.cnf /etc/my.cnf --> This is for a large system with memory = 512M where the system runs mainly
# vi /etc/my.cnf
在[mysqld]段添加 datadir=/mydata/mysql --> 指定数据库文件存放的目录(文件)
并修改此文件中thread_concurrency的值为你的CPU个数乘以2,
thread_concurrency = 2
8. 提供SysV控制脚本:
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
添加至服务列表:
# chkconfig --add mysqld
# chkconfig mysqld on
# chown -R root .
而后就可以启动服务测试使用了。
为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
9. 将/usr/local/mysql/bin 加入PATH变量的路径中
# vi /etc/profile
加入"PATH=/usr/local/mysql/bin:$PATH"
# export PATH=$PATH:/usr/local/mysql/bin
10.启动mysql
# mysql
>use mysql 设定默认表
>SELECT host,user,password FROM user; 查看表
>UPDATE user SET password=password('redhat') WHERE user='root'; --> 为所有的root用户更改密码
>DROP USER '' @localhost; 删除匿名用户
11. 添加man文档路径(输出mysql的man手册至man命令的查找路径)
# vi /etc/man.config
添加 MANPATH=/usr/local/mysql/man
12. 输出mysql的库文件给系统库查找路径:
在/etc/ld.so.conf.d 中建立指定mysql库文件路径(/usr/local/mysql/lib)的文件 --> mysql.conf
# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
# ldconfig -->通知系统重新载入系统库,生成/etc/ld.so.cache 文件
系统在启动时只到 /lib /usr/lib /usr/X11R6/lib 这三个目录中查找库文件 ,并将其缓存在/etc/ld.so.cache文件中
# ldconfig -v | grep mysql
13. 让其它程序可以访问 msyql的头文件
# ln -sv /usr/local/mysql/include/ /usr/include/mysql
关于mysql的基本设置
- [root@www ~]# mysql 第一次一登录时密码为空
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 1
- Server version: 5.5.24-log MySQL Community Server (GPL)
- Copyright (c) 2000, 2011, 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> use mysql;
- Database changed
- mysql> SHOW DATABASES;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | test |
- +--------------------+
- 4 rows in set (0.01 sec)
- mysql> SELECT user,host,password FROM user;
- +------+-------------+----------+
- | user | host | password |
- +------+-------------+----------+
- | root | localhost | |
- | root | www.yue.com | |
- | root | 127.0.0.1 | |
- | root | ::1 | |
- | | localhost | |
- | | www.yue.com | |
- +------+-------------+----------+
- 6 rows in set (0.00 sec)
- mysql> DROP USER ''@'localhost';
- Query OK, 0 rows affected (0.01 sec)
- mysql> DROP USER ''@'www.yue.com';
- Query OK, 0 rows affected (0.00 sec)
- mysql> DELETE FROM user WHERE HOST='::1';
- Query OK, 1 row affected (0.00 sec)
- mysql> SELECT user,host,password FROM user;
- +------+-------------+----------+
- | user | host | password |
- +------+-------------+----------+
- | root | localhost | |
- | root | www.yue.com | |
- | root | 127.0.0.1 | |
- +------+-------------+----------+
- 3 rows in set (0.00 sec)
- mysql> UPDATE user SET password=password('redhat') WHERE user='root';
- Query OK, 3 rows affected (0.05 sec)
- Rows matched: 3 Changed: 3 Warnings: 0
- mysql> SELECT user,host,password FROM user;
- +------+-------------+-------------------------------------------+
- | user | host | password |
- +------+-------------+-------------------------------------------+
- | root | localhost | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
- | root | www.yue.com | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
- | root | 127.0.0.1 | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
- +------+-------------+-------------------------------------------+
- 3 rows in set (0.00 sec)
- mysql> FLUSH PRIVILEGES;
- Query OK, 0 rows affected (0.00 sec)
- mysql> quit
- Bye
*************** mysql 绿色版 ***************
mysql-5.5.24-linux2.6-i686.tar.gz
(1). 解压后可直接使用
(2). 对解压位置有要求(/usr/local),要以mysql用户的身份运行
[root@www mysql_sa]# groupadd -r mysql
[root@www mysql_sa]# useradd -r -g mysql -s /sbin/nologin -M mysql
[root@www mysql_sa]# id mysql
uid=101(mysql) gid=157(mysql) groups=157(mysql) context=root:system_r:unconfined_t:SystemLow-SystemHigh
[root@www mysql_sa]# mkdir /data/mysql
[root@www mysql_sa]# chown -R mysql:mysql /data/mysql
[root@www mysql_sa]# tar xf mysql-5.5.24-linux2.6-i686.tar.gz -C /usr/local
[root@www mysql_sa]# cd /usr/local
[root@www local]# ln -sv mysql-5.5.24-linux2.6-i686/ mysql
create symbolic link `mysql' to `mysql-5.5.24-linux2.6-i686/'
[root@www local]# cd mysql
[root@www mysql]# chown -R mysql:mysql .
[root@www mysql]# scripts/mysql_install_db --datadir=/data/mysql --user=mysql
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 www.yue.com 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!
[root@www mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@www mysql]# vi /etc/my.cnf
[root@www mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@www mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@www mysql]# chkconfig --add mysqld
[root@www mysql]# chkconfig mysqld on
[root@www mysql]# chown -R root .
[root@www mysql]# vi /etc/profile
[root@www mysql]# export PATH=$PATH:/usr/local/mysql/bin
[root@www mysql]# vi /etc/man.config
[root@www mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
create symbolic link `/usr/include/mysql' to `/usr/local/mysql/include/'
[root@www mysql]# vi /etc/ld.so.conf.d/mysql.conf
[root@www mysql]# ldconfig
[root@www mysql]# ldconfig -v | grep mysql
/usr/local/mysql/lib:
libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0