Chinaunix首页 | 论坛 | 博客
  • 博客访问: 623709
  • 博文数量: 244
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-27 09:53
个人简介

记录学习,记录成长

文章分类

全部博文(244)

我的朋友

分类: LINUX

2015-08-20 21:56:36

此次编译安装的是二进制格式的:
[root@www lamp]# ll | grep mysql
-rw-r--r--  1 root  root  177267332 Aug 19 13:50 mysql-5.5.44-linux2.6-i686.tar.gz
mysql的通用二进制格式的包在解压缩后是直接可以用的,但是要求的是必须解压在安装路径下且目录名称还需要是MYSQL才行;
1.解压至/usr/local下
[root@www lamp]# tar xf mysql-5.5.44-linux2.6-i686.tar.gz -C /usr/local
在/usr/local中最好为mysql-5.5.44-linux2.6-i686创建一个链接叫mysql而不要重命名
[root@www local]# ll | grep mysql
drwxr-xr-x  13 root root 4096 Aug 20 01:58 mysql-5.5.44-linux2.6-i686
[root@www local]# ln -sv mysql-5.5.44-linux2.6-i686 mysql
`mysql' -> `mysql-5.5.44-linux2.6-i686'
[root@www local]# ll | grep mysql
lrwxrwxrwx   1 root root   26 Aug 20 02:01 mysql -> mysql-5.5.44-linux2.6-i686
drwxr-xr-x  13 root root 4096 Aug 20 01:58 mysql-5.5.44-linux2.6-i686
这样以后通过mysql也可以找到mysql-5.5.44-linux2.6-i686
2.  创建mysql用户mysql组
[root@www mysql]# ll
drwxr-xr-x  2 root root    4096 Aug 20 01:58 bin
-rw-r--r--  1 7161 wheel  17987 May  4 05:16 COPYING
drwxr-xr-x  3 root root    4096 Aug 20 01:57 data
drwxr-xr-x  2 root root    4096 Aug 20 01:58 docs
drwxr-xr-x  3 root root    4096 Aug 20 01:58 include
-rw-r--r--  1 7161 wheel 149724 May  4 05:16 INSTALL-BINARY
drwxr-xr-x  3 root root    4096 Aug 20 01:58 lib
drwxr-xr-x  4 root root    4096 Aug 20 01:58 man
drwxr-xr-x 10 root root    4096 Aug 20 01:58 mysql-test
-rw-r--r--  1 7161 wheel   2496 May  4 05:16 README
drwxr-xr-x  2 root root    4096 Aug 20 01:58 scripts
drwxr-xr-x 27 root root    4096 Aug 20 01:58 share
drwxr-xr-x  4 root root    4096 Aug 20 01:58 sql-bench
drwxr-xr-x  2 root root    4096 Aug 20 01:58 support-files
此时mysql的属主属组并不是mysql,所以要初始化安装mysql需要mysql用户mysql组,所以接下来要创建mysql用户mysql组
[root@www mysql]# useradd -r mysql
[root@www mysql]# id mysql
uid=496(mysql) gid=493(mysql) groups=493(mysql)
创建系统用户mysql不能登录系统只是为了运行mysqld服务的;
也可以手动创建
[root@www mysql]# groupadd -r -g 493  mysql
[root@www mysql]# useradd -g 493 -r -u 493 mysql
[root@www mysql]# id mysql
uid=493(mysql) gid=493(mysql) groups=493(mysql)
而且ls /home并没用mysql的家目录,然后
[root@www mysql]# chown mysql.mysql /usr/local/mysql/*
[root@www mysql]# ll
drwxr-xr-x  2 mysql mysql   4096 Aug 20 01:58 bin
-rw-r--r--  1 mysql mysql  17987 May  4 05:16 COPYING
drwxr-xr-x  3 mysql mysql   4096 Aug 20 01:57 data
drwxr-xr-x  2 mysql mysql   4096 Aug 20 01:58 docs
drwxr-xr-x  3 mysql mysql   4096 Aug 20 01:58 include
-rw-r--r--  1 mysql mysql 149724 May  4 05:16 INSTALL-BINARY
drwxr-xr-x  3 mysql mysql   4096 Aug 20 01:58 lib
drwxr-xr-x  4 mysql mysql   4096 Aug 20 01:58 man
drwxr-xr-x 10 mysql mysql   4096 Aug 20 01:58 mysql-test
-rw-r--r--  1 mysql mysql   2496 May  4 05:16 README
drwxr-xr-x  2 mysql mysql   4096 Aug 20 01:58 scripts
drwxr-xr-x 27 mysql mysql   4096 Aug 20 01:58 share
drwxr-xr-x  4 mysql mysql   4096 Aug 20 01:58 sql-bench
drwxr-xr-x  2 mysql mysql   4096 Aug 20 01:58 support-files
其实INSTALL-BINARY文件中有安装方法可以看
3.  用mysql_install_db文件手动初始化mysql
[root@www mysql]# ll scripts/
-rwxr-xr-x 1 7161 wheel 14764 May  4 06:37 mysql_install_db
[root@www mysql]# scripts/mysql_install_db --help | less
Usage: scripts/mysql_install_db [OPTIONS]
  --basedir=path       
  --builddir=path                           
  --cross-bootstrap    
  --datadir=path   #数据存放路径,默认在./mysql/data下;或者是其他目录,一般最好存放到一个独立的逻辑卷上,可以更好的管理数据
  --defaults-extra-file=name
  --defaults-file=name  
  --force            
  --help 
  --ldata=path 
  --no-defaults 
  --rpm   
  --skip-name-resolve 
  --srcdir=path   
  --user=user_name #以那个用户的身份运行mysql
3.1  此次将数据放到其他目录下,所以要事先创建更好逻辑卷
创建逻辑分区
[root@www mysql]# fdisk /dev/sdb
Command (m for help): p
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1000     8032468+  83  Linux
/dev/sdb2            1001        1500     4016250   83  Linux
/dev/sdb3            1501        2000     4016250   83  Linux
/dev/sdb4            2001        4568    20627460    5  Extended
Command (m for help): n
First cylinder (2001-4568, default 2001): 
Using default value 2001
Last cylinder, +cylinders or +size{K,M,G} (2001-4568, default 4568): +4G    
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
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1000     8032468+  83  Linux
/dev/sdb2            1001        1500     4016250   83  Linux
/dev/sdb3            1501        2000     4016250   83  Linux
/dev/sdb4            2001        4568    20627460    5  Extended
/dev/sdb5            2001        2523     4200966   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 mysql]# partprobe /dev/sdb 
创建逻辑卷
[root@www ~]# pvcreate /dev/sdb5
  Physical volume "/dev/sdb5" successfully created
[root@www ~]# vgcreate myvg /dev/sdb5
  Volume group "myvg" successfully created
[root@www ~]# lvcreate -n mysqldata -L 2G myvg
  Logical volume "mysqldata" created
[root@www ~]# lvs
  LV        VG   Attr       LSize Pool Origin Data%  Move Log Cpy%Sync Convert
  mysqldata myvg -wi-a----- 2.00g                                             
格式化mysqldata
[root@www ~]# mke2fs -j /dev/myvg/mysqldata
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 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
8192 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 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.  
谁知开机自动挂载mysqldata
[root@www /]#mkdir /mysqldata
[root@www /]# vim /etc/fstab   添加
/dev/myvg/mysqldata     /mysqldata              ext3    defaults        0 0
[root@www /]# mount -a
[root@www /]# mount 
/dev/mapper/myvg-mysqldata on /mysqldata type ext3 (rw)
然而将所有的数据文件都放在/mysqldata下将来不便于管理,可以创建二级目录存放,并且赋予相应的权限
[root@www /]# mkdir /mysqldata/data
[root@www /]# ll /mysqldata/
drwxr-xr-x 2 root root  4096 Aug 20 04:10 data
[root@www /]# chown mysql.mysql /mysqldata/data/
[root@www /]# chmod 750 /mysqldata/data/
[root@www /]# ll /mysqldata/
drwxr-x--- 2 mysql mysql  4096 Aug 20 04:10 data
3.2  进行初始化
[root@www mysql]# scripts/mysql_install_db --user=mysql --datadir=/mysqldata/data/
Installing MySQL system tables...
150820  5:37:13 [Note] ./bin/mysqld (mysqld 5.5.44) starting as process 3085 ...
OK
Filling help tables...
150820  5:37:14 [Note] ./bin/mysqld (mysqld 5.5.44) starting as process 3092 ...
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 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 at /> 初始化安装mysql后,为了防止别人攻破了mysql进程获得/mysql的所有权限,所以保险起见,将/mysql下所有文件目录的属主改为root
[root@www mysql]# chown root /usr/local/mysql/*
补充:如果没有指定datadir路径,那么数据默认是放在/usr/local/mysql/data中的,而刚才那样做mysql用户对data没有写权限,但是此次因为不是放在/usr/local/mysql/data中所以不需要在改了;
4.  启动mysql服务
4.1 完成上述操作后还不能启动mysql服务,因为没有启动脚本,而mysql提供了启动脚本 
[root@www mysql]# ll support-files/mysql.server 
-rwxr-xr-x 1 7161 wheel 10880 May  4 06:37 support-files/mysql.server
[root@www mysql]# cp support-files//mysql.server /etc/init.d/mysqld
赋予执行权限(已经有了)并加到服务列表中
[root@www mysql]# chkconfig --add  mysqld 
[root@www mysql]# chkconfig --list | grep mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
4.2  为mysql提供配置文件
mysql服务寻找其配置文件是这样的
/etc/my.cnf-->/etc/mysql/my.cnf-->/$BASEDIR/my.cnf-->~/.my.cnf
其中$BASEDIR是mysql进程的运行目录,一般是安装目录,~/.my.cnf是用户家目录下的my.cnf文件而此次mysql没有家目录所以找不找的到没关系,它会一个一个的找,出现冲突的话后一个会覆盖前一个的配置;
[root@www mysql]# ll support-files/ | grep my-
-rw-r--r-- 1 7161 wheel  4691 May  4 06:37 my-huge.cnf #内存在1G-2G之间
-rw-r--r-- 1 7161 wheel 19759 May  4 06:37 my-innodb-heavy-4G.cnf
-rw-r--r-- 1 7161 wheel  4665 May  4 06:37 my-large.cnf #内存=512M
-rw-r--r-- 1 7161 wheel  4676 May  4 06:37 my-medium.cnf #内存处于32M-64M之间或者是128M
-rw-r--r-- 1 7161 wheel  2840 May  4 06:37 my-small.cnf #内存<=64M
可以根据内存选择合适的作为配置文件,这里我的内存是1G的所以选择my-huge.cnf
[root@www support-files]# cp my-huge.cnf /etc/my.cnf
4.3  修改此文件为
[root@www ~]# cat /etc/my.cnf | sed "/^#/d" | sed "/^$/d"
[client] #这里是对客户端程序生效的
port            = 3306
socket          = /tmp/mysql.sock
[mysqld] #这里是对服务器生效的
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
thread_concurrency = 2 #线程并发量=CPU个数*2
log-bin=mysql-bin
server-id       = 1
datadir = /mysqldata/data #添加项,添加数据存放目录,如果没有更改默认位置不需要加
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
启动服务
[root@www ~]# service mysqld start
Starting MySQL..... SUCCESS!
[root@www ~]# netstat -ntlp | grep :3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      3551/mysqld 
5.  运行mysql
[root@www ~]# mysql #命令未找到
-bash: mysql: command not found
[root@www ~]# vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
[root@www profile.d]# chmod +x mysql.sh
[root@www profile.d]# ./mysql.sh 
重新登陆再次测试
[root@www ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/apache/bin:/usr/local/mysql/bin:/root/bin
[root@www ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.44-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>  可以使用了
5.1  mysql基本语法
MYSQL服务器中:
1和2都支持正则表达式,_表示任意单字符,%表示任意长度任意字符;
1.服务器变量:用来定义MYSQL服务器运行特性;
show global variables [like '要查的字符串']; 
如:
mysql> show global variables like 'data%';
+---------------+------------------+
| Variable_name | Value            |
+---------------+------------------+
| datadir       | /mysqldata/data/ |
+---------------+------------------+
1 row in set (0.01 sec)
2.状态变量:保存了MYSQL服务器运行时的统计数据;
show global status [like '要查的字符串'];
如:
mysql> show global status like '%select%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| Com_insert_select      | 0     |
| Com_replace_select     | 0     |
| Com_select             | 1     |
| Select_full_join       | 0     |
| Select_full_range_join | 0     |
| Select_range           | 0     |
| Select_range_check     | 0     |
| Select_scan            | 13    |
+------------------------+-------+
8 rows in set (0.01 sec)
6.  为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤
6.1  输出mysql的man手册至man命令的查找路径:
[root@www mysql]# vim /etc/man.config   
添加一条
MANPATH  /usr/local/mysql/man
6.2 输出mysql的头文件至系统头文件路径/usr/include:
这可以通过创建链接实现:
[root@www mysql]# ln -sv /usr/local/mysql/include  /usr/include/mysql
`/usr/include/mysql' -> `/usr/local/mysql/include'
6.3  输出mysql的库文件给系统库查找路径
[root@www mysql]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
让系统重新读取库文件
[root@www mysql]# ldconfig -v

阅读(473) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~