三、通用二进制包安装MySQL
1、准备数据存放的文件系统
创建一个分区
[root@soysauce ~]# fdisk /dev/hda
The number of cylinders for this disk is set to 44384.
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)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-44384, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-44384, default 44384): +10G
Command (m for help): p
Disk /dev/hda: 21.4 GB, 21474836480 bytes
15 heads, 63 sectors/track, 44384 cylinders
Units = cylinders of 945 * 512 = 483840 bytes
Device Boot Start End Blocks Id System
/dev/hda1 1 20669 9766071 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@soysauce ~]# partprobe /dev/hda
[root@soysauce ~]# cat /proc/partitions
major minor #blocks name
3 0 20971520 hda
3 1 9766071 hda1
8 0 20971520 sda
8 1 104391 sda1
8 2 20860402 sda2
253 0 18776064 dm-0
253 1 2064384 dm-1
格式化分区,创建文件系统
[root@soysauce ~]# mke2fs -j /dev/hda1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1221600 inodes, 2441517 blocks
122075 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2503999488
75 block groups
32768 blocks per group, 32768 fragments per group
16288 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 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
创建挂载目录,并挂载
[root@soysauce ~]# mkdir /mydata
[root@soysauce ~]# mount /dev/hda1 /mydata
[root@soysauce ~]# mkdir /mydata/data
[root@soysauce ~]# ls /mydata/
data lost+found
修改属主属组为mysql
[root@soysauce ~]# chown -R mysql.mysql /mydata/data/ 2、新建用户以安全方式运行进程
[root@soysauce ~]# groupadd -g 3306 mysql
[root@soysauce ~]# useradd -u 3306 -g mysql -M -s /sbin/nologin -d /mydata/data/ mysql 3、安装并初始化mysql-5.6.26
解压并初始化mysql
[root@soysauce ~]# cd /tmp/
[root@soysauce ~]# tar xf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
[root@soysauce ~]# cd /usr/local/
[root@soysauce local]# ln -sv mysql-5.6.26-linux-glibc2.5-x86_64 mysql
create symbolic link `mysql' to `mysql-5.6.26-linux-glibc2.5-x86_64'
[root@soysauce local]# cd mysql
[root@soysauce mysql]# chown -R root.mysql ./*
[root@soysauce mysql]# ll
total 240
drwxr-xr-x 2 root mysql 4096 Jan 16 12:48 bin
-rw-r--r-- 1 root mysql 17987 Jul 15 2015 COPYING
drwxr-xr-x 3 root mysql 4096 Jan 16 12:49 data
drwxr-xr-x 2 root mysql 4096 Jan 16 12:49 docs
drwxr-xr-x 3 root mysql 4096 Jan 16 12:48 include
-rw-r--r-- 1 root mysql 104897 Jul 15 2015 INSTALL-BINARY
drwxr-xr-x 3 root mysql 4096 Jan 16 12:49 lib
drwxr-xr-x 4 root mysql 4096 Jan 16 12:49 man
-rw-r--r-- 1 root root 1439 Jan 16 22:05 my.cnf
drwxr-xr-x 10 root mysql 4096 Jan 16 12:49 mysql-test
-rw-r--r-- 1 root mysql 2496 Jul 15 2015 README
drwxr-xr-x 2 root mysql 4096 Jan 16 12:49 scripts
drwxr-xr-x 28 root mysql 4096 Jan 16 12:49 share
drwxr-xr-x 4 root mysql 4096 Jan 16 12:49 sql-bench
drwxr-xr-x 2 root mysql 4096 Jan 16 12:49 support-files
初始化mysql
[root@soysauce mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
Installing MySQL system tables...2016-01-19 10:03:08 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-01-19 10:03:08 0 [Note] ./bin/mysqld (mysqld 5.6.26) starting as process 3958 ...
2016-01-19 10:03:09 3958 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-01-19 10:03:09 3958 [Note] InnoDB: The InnoDB memory heap is disabled
2016-01-19 10:03:09 3958 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-01-19 10:03:09 3958 [Note] InnoDB: Memory barrier is not used
2016-01-19 10:03:09 3958 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-01-19 10:03:09 3958 [Note] InnoDB: Using Linux native AIO
2016-01-19 10:03:09 3958 [Note] InnoDB: Not using CPU crc32 instructions
2016-01-19 10:03:09 3958 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-01-19 10:03:09 3958 [Note] InnoDB: Completed initialization of buffer pool
2016-01-19 10:03:09 3958 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2016-01-19 10:03:09 3958 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2016-01-19 10:03:09 3958 [Note] InnoDB: Database physically writes the file full: wait...
2016-01-19 10:03:10 3958 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2016-01-19 10:03:14 3958 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2016-01-19 10:03:17 3958 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2016-01-19 10:03:17 3958 [Warning] InnoDB: New log files created, LSN=45781
2016-01-19 10:03:17 3958 [Note] InnoDB: Doublewrite buffer not found: creating new
2016-01-19 10:03:17 3958 [Note] InnoDB: Doublewrite buffer created
2016-01-19 10:03:17 3958 [Note] InnoDB: 128 rollback segment(s) are active.
2016-01-19 10:03:17 3958 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-01-19 10:03:17 3958 [Note] InnoDB: Foreign key constraint system tables created
2016-01-19 10:03:17 3958 [Note] InnoDB: Creating tablespace and datafile system tables.
2016-01-19 10:03:17 3958 [Note] InnoDB: Tablespace and datafile system tables created.
2016-01-19 10:03:17 3958 [Note] InnoDB: Waiting for purge to start
2016-01-19 10:03:17 3958 [Note] InnoDB: 5.6.26 started; log sequence number 0
2016-01-19 10:03:19 3958 [Note] Binlog end
2016-01-19 10:03:19 3958 [Note] InnoDB: FTS optimize thread exiting.
2016-01-19 10:03:19 3958 [Note] InnoDB: Starting shutdown...
2016-01-19 10:03:20 3958 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2016-01-19 10:03:20 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-01-19 10:03:20 0 [Note] ./bin/mysqld (mysqld 5.6.26) starting as process 3980 ...
2016-01-19 10:03:20 3980 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-01-19 10:03:20 3980 [Note] InnoDB: The InnoDB memory heap is disabled
2016-01-19 10:03:20 3980 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-01-19 10:03:20 3980 [Note] InnoDB: Memory barrier is not used
2016-01-19 10:03:20 3980 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-01-19 10:03:20 3980 [Note] InnoDB: Using Linux native AIO
2016-01-19 10:03:20 3980 [Note] InnoDB: Not using CPU crc32 instructions
2016-01-19 10:03:20 3980 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-01-19 10:03:21 3980 [Note] InnoDB: Completed initialization of buffer pool
2016-01-19 10:03:21 3980 [Note] InnoDB: Highest supported file format is Barracuda.
2016-01-19 10:03:21 3980 [Note] InnoDB: 128 rollback segment(s) are active.
2016-01-19 10:03:21 3980 [Note] InnoDB: 5.6.26 started; log sequence number 1625977
2016-01-19 10:03:21 3980 [Note] Binlog end
2016-01-19 10:03:21 3980 [Note] InnoDB: FTS optimize thread exiting.
2016-01-19 10:03:21 3980 [Note] InnoDB: Starting shutdown...
2016-01-19 10:03:22 3980 [Note] InnoDB: Shutdown completed; log sequence number 1625987
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 soysauce 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 http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as ./my-new.cnf,
please compare it with your file and take the changes you need. 4、为mysql提供主配置文件
[root@soysauce mysql]# cp support-files/my-default.cnf /etc/my.cnf
[root@soysauce mysql]# vim /etc/my.cnf
[root@soysauce mysql]# tail -5 /etc/my.cnf
[mysqld]
datadir = /mydata/data
innodb_file_per_table = ON
log-bin = master-bin
socket = /tmp/mysql.sock 5、为mysql提供sysv服务脚本
[root@soysauce mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@soysauce mysql]# chkconfig --add mysqld
[root@soysauce mysql]# chkconfig mysqld on
[root@soysauce mysql]# chkconfig --list mysqld
mysqld 0:off1:off2:on3:on4:on5:on6:off 6、输出man文档路径、库文件路径、头文件路径、PATH环境变量
输出man文档路径
[root@soysauce ~]# vim /etc/man.config
MANPATH /usr/local/mysql/man
输出库文件路径
[root@soysauce ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@soysauce ~]# ldconfig
输出头文件路径
[root@soysauce ~]# ln -sv /usr/local/mysql/include /usr/include/mysql
输出PATH环境变量
[root@soysauce ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin/mysql' > /etc/profile.d/mysql.sh
[root@soysauce ~]# . /etc/profile.d/mysql.sh 7、启动mysql
[root@soysauce mysql]# service mysqld start
Starting MySQL........ [ OK ]
查看监听端口
[root@soysauce mysql]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:*LISTEN 2820/portmap
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3197/nginx
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 25126/sshd
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 24814/sshd
tcp 0 0 0.0.0.0:922 0.0.0.0:* LISTEN 2860/rpc.statd
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 24814/sshd
tcp 0 0 127.0.0.1:6012 0.0.0.0:* LISTEN 3461/sshd
tcp 0 0 :::3306 :::* LISTEN 5407/mysqld
tcp 0 0 :::22 :::* LISTEN 25126/sshd
tcp 0 0 ::1:6010 :::* LISTEN 24814/sshd
tcp 0 0 ::1:6011 :::* LISTEN 24814/sshd
tcp 0 0 ::1:6012 :::* LISTEN 3461/sshd
连接测试
[root@soysauce mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26-log MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (1.61 sec)
mysql> \q
Bye