第一步:首先找到Mysql安装包
[root@huangzhong ~]# ls
Desktop Public install.log
Documents Templates install.log.syslog
Downloads Videos mysql Music
anaconda-ks.cfg mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz
Pictures dir1 vsftpd-3.0.2.tar.gz
第二步:把压缩包解压到指定的文件目录下
[root@huangzhong ~]# tar -zxvf mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz -C /usr/local
mysql-5.6.15-linux-glibc2.5-x86_64/INSTALL-BINARY
mysql-5.6.15-linux-glibc2.5-x86_64/README
mysql-5.6.15-linux-glibc2.5-x86_64/data/test/db.opt
mysql-5.6.15-linux-glibc2.5-x86_64/lib/libmysqlclient.a
mysql-5.6.15-linux-glibc2.5-x86_64/lib/libmysqlclient.so.18
第三步:找到解压目录下进行查看是否有
[root@huangzhong local]# ll
total 44
drwxr-xr-x. 2 root root 4096 Sep 23 2011 bin
drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 games
drwxr-xr-x. 2 root root 4096 Sep 23 2011 include
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec
drwxr-xr-x. 13 root root 4096 Apr 5 17:12 mysql-5.6.15-linux-glibc2.5-x86_64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin
drwxr-xr-x. 5 root root 4096 Mar 29 01:55 share
drwxr-xr-x. 2 root root 4096 Sep 23 2011 src
此时我们我们已经看到了,此目录太长可以对此进行做一次链接:
[root@huangzhong local]# ln -s mysql-5.6.15-linux-glibc2.5-x86_64 mysql
此时在进行查看就可以看到链接符了
[root@huangzhong local]# ll
total 44
drwxr-xr-x. 2 root root 4096 Sep 23 2011 bin
drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 games
drwxr-xr-x. 2 root root 4096 Sep 23 2011 include
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec
lrwxrwxrwx. 1 root root 34 Apr 5 17:24 mysql -> mysql-5.6.15-linux-glibc2.5-x86_64
第四步:然后进入安装包目录下查看安装文件是源代码安装还是二进制安装
[root@huangzhong local]# cd mysql
[root@huangzhong mysql]# ll
total 156
-rw-r--r--. 1 7161 wheel 17987 Nov 18 02:02 COPYING
-rw-r--r--. 1 7161 wheel 88388 Nov 18 02:03 INSTALL-BINARY
-rw-r--r--. 1 7161 wheel 2496 Nov 18 02:02 README
drwxr-xr-x. 2 root root 4096 Apr 5 17:12 bin
drwxr-xr-x. 3 root root 4096 Apr 5 17:10 data
drwxr-xr-x. 2 root root 4096 Apr 5 17:12 docs
drwxr-xr-x. 3 root root 4096 Apr 5 17:12 include
drwxr-xr-x. 3 root root 4096 Apr 5 17:11 lib
drwxr-xr-x. 4 root root 4096 Apr 5 17:12 man
drwxr-xr-x. 10 root root 4096 Apr 5 17:12 mysql-test
drwxr-xr-x. 2 root root 4096 Apr 5 17:11 scripts
drwxr-xr-x. 28 root root 4096 Apr 5 17:11 share
drwxr-xr-x. 4 root root 4096 Apr 5 17:12 sql-bench
drwxr-xr-x. 3 root root 4096 Apr 5 17:11 support-files
通过以上我们可以看出时二进制安装
第五步:查看本机是否已安装过mysql
[root@huangzhong mysql]# rpm -qa |grep -i mysql
qt-mysql-4.6.2-25.el6.x86_64
mysql-5.1.66-2.el6_3.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
mysql-libs-5.1.66-2.el6_3.x86_64
mysql-server-5.1.66-2.el6_3.x86_64
这里我们可以看到本机已经安装过了,如果我们再按装新版本需要先卸载
第六步:由于MySQL卸载时有依赖关系,所以这里要用yum卸载
[root@huangzhong mysql]# yum --disablerepo=\* --enablerepo=c6-media remove mysql-server
Loaded plugins: fastestmirror, refresh-packagekit
Setting up Remove Process
Resolving Dependencies
-->Runningtransaction check
此时可以看到正在检查所依赖的的安装包,然后对此进行一并卸载
第七步:编辑INSTALL-BINARY进入查看安装说明
[root@huangzhong mysql]# vim INSTALL-BINARY
77 sequence looks like this:
78 shell> groupadd mysql
79 shell> useradd -r -g mysql mysql
80 shell> cd /usr/local
81 shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
82 shell> ln -s full-path-to-mysql-VERSION-OS mysql
83 shell> cd mysql
84 shell> chown -R mysql .
85 shell> chgrp -R mysql .
86 shell> scripts/mysql_install_db --user=mysql
87 shell> chown -R root .
88 shell> chown -R mysql data
89 shell> bin/mysqld_safe --user=mysql &
90 # Next command is optional
91 shell> cp support-files/mysql.server /etc/init.d/mysql.server
92
第八步:创立mysql组和mysql账号,并让mysql账号加入mysql组里
[root@huangzhong mysql]# groupadd mysql
[root@huangzhong mysql]# useradd -r -g mysql mysql
第九步:因为要使用mysql账号操作所以要改变操作权限
[root@huangzhong mysql]# chown -R mysql:mysql .
此时我们可以查看是否以改变
[root@huangzhong mysql]# ll
total 156
-rw-r--r--. 1 mysql mysql 17987 Nov 18 02:02 COPYING
-rw-r--r--. 1 mysql mysql 88388 Apr 5 17:39 INSTALL-BINARY
-rw-r--r--. 1 mysql mysql 2496 Nov 18 02:02 README
drwxr-xr-x. 2 mysql mysql 4096 Apr 5 17:12 bin
drwxr-xr-x. 3 mysql mysql 4096 Apr 5 17:10 data
drwxr-xr-x. 2 mysql mysql 4096 Apr 5 17:12 docs
drwxr-xr-x. 3 mysql mysql 4096 Apr 5 17:12 include
drwxr-xr-x. 3 mysql mysql 4096 Apr 5 17:11 lib
drwxr-xr-x. 4 mysql mysql 4096 Apr 5 17:12 man
drwxr-xr-x. 10 mysql mysql 4096 Apr 5 17:12 mysql-test
drwxr-xr-x. 2 mysql mysql 4096 Apr 5 17:11 scripts
drwxr-xr-x. 28 mysql mysql 4096 Apr 5 17:11 share
drwxr-xr-x. 4 mysql mysql 4096 Apr 5 17:12 sql-bench
drwxr-xr-x. 3 mysql mysql 4096 Apr 5 17:11 support-files
第十步:进行安装mysql
[root@huangzhong mysql]# ./scripts/mysql_install_db --user=mysql
WARNING: The host ‘huangzhong‘ could not be looked up with ./bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
此时我们可以看到安装过程中出现错误,说找不到libaio文件,这时我们就要到/media/cdrom/Packages/目录下查找看是否能够找到,此时可以看到如下:
[root@huangzhong mysql]# ll /media/cdrom/Packages/ |grep -i aio
-r--r--r--. 2 root root 21616 Jul 3 2011 libaio-0.3.107-10.el6.i686.rpm
-r--r--r--. 2 root root 21708 Jul 3 2011 libaio-0.3.107-10.el6.x86_64.rpm
-r--r--r--. 2 root root 13524 Jul 3 2011 libaio-devel-0.3.107-10.el6.i686.rpm
-r--r--r--. 2 root root 13468 Jul 3 2011 libaio-devel-0.3.107-10.el6.x86_64.rpm
-r--r--r--. 2 root root 86988 Feb 24 2013 libsane-hpaio-3.12.4-4.el6.x86_64.rpm
此时可以看到有这么多,当不知道安装那个的时候你可以先查看你的机器已经安装了那些,如下操作:
[root@huangzhong mysql]# rpm -qa |grep -i libaio
[root@huangzhong mysql]#
此时我们可以看到系统一个也没安装,所以这时我们就把他们一起安装了,安装代码如下:
[root@huangzhong mysql]# yum --disablerepo=\* --enablerepo=c6-media install libaio liaio-devel
完成以上操作后,再次再次执行安装命令:
[root@huangzhong mysql]# ./scripts/mysql_install_db --user=mysql
第十一步:安装完后我们可以查看目录下已产生的文件
[root@huangzhong mysql]# ll data/
total 110604
-rw-rw----. 1 mysql mysql 50331648 Apr 5 18:22 ib_logfile0
-rw-rw----. 1 mysql mysql 50331648 Apr 5 18:22 ib_logfile1
-rw-rw----. 1 mysql mysql 12582912 Apr 5 18:22 ibdata1
drwx------. 2 mysql mysql 4096 Apr 5 18:22 mysql
drwx------. 2 mysql mysql 4096 Apr 5 18:22 performance_schema
drwxr-xr-x. 2 mysql mysql 4096 Apr 5 17:10 test
[root@huangzhong mysql]# ll data/mysql/
第十二步:把对象的所有者改变为管理员,并查看
[root@huangzhong mysql]# chown -R root .
[root@huangzhong mysql]# ll
total 164
-rw-r--r--. 1 root mysql 17987 Nov 18 02:02 COPYING
-rw-r--r--. 1 root mysql 88388 Apr 5 17:39 INSTALL-BINARY
-rw-r--r--. 1 root mysql 2496 Nov 18 02:02 README
drwxr-xr-x. 2 root mysql 4096 Apr 5 17:12 bin
drwxr-xr-x. 5 root mysql 4096 Apr 5 18:22 data
drwxr-xr-x. 2 root mysql 4096 Apr 5 17:12 docs
drwxr-xr-x. 3 root mysql 4096 Apr 5 17:12 include
drwxr-xr-x. 3 root mysql 4096 Apr 5 17:11 lib
drwxr-xr-x. 4 root mysql 4096 Apr 5 17:12 man
从上面可以看到data目录也变为root,但是data目录下存放着数据表格为了能够执行操作,这里要把data对象权限改为mysql
[root@huangzhong mysql]# chown -R mysql data/
[root@huangzhong mysql]# ll
drwxr-xr-x. 2 root mysql 4096 Apr 5 17:12 bin
drwxr-xr-x. 5 mysql mysql 4096 Apr 5 18:22 data
第十三步:把安装生成的文件my.cnf拷贝到/etc/my.cnf,因为原来安装的有mysql,所以已经产生有一个所以这里要进行替换覆盖掉
[root@huangzhong mysql]# cp my.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf‘? Y
第十四步:进行配置控***务脚本
首先查看有一下没有控***务脚本文件,这个脚本文件一般在/etc/init.d/目录下名字叫mysqld
[root@huangzhong mysql]# ll /etc/init.d/mysqld
ls: cannot access /etc/init.d/mysqld: No such file or directory
此时发现没有此文件。然后我们去查找有关启动服务的脚本,这些一般在support-files/目录下,如下所示:
[root@huangzhong mysql]# cd support-files/
[root@huangzhong support-files]# grep start *
mysql.server:# MySQL daemon start/stop script.
mysql.server: ‘start‘)
mysql.server: ‘restart‘)
mysql.server: # running or not, start it again.
通过上面可以看到mysql.server是一个控***务脚本,现在可以打开看看
[root@huangzhong support-files]# vim mysql.server
ase "$mode" in
‘start‘)
# Start daemon
# Safeguard (relative paths, core dumps..)
cd $basedir
echo $echo_n "Starting MySQL"
此时可以确定mysql.server就是一个控***务脚本,然后把mysql.server控***务脚本拷贝到/etc/init.d目录下并改变其名字,操作如下:
[root@huangzhong support-files]# cp mysql.server /etc/init.d/mysqld
最后改变它的权限使其变为可执行的,操作如下:
[root@huangzhong support-files]# chmod a+x /etc/init.d/mysqld
第十五步:启动mysql服务
首先查看mysql服务端口是否启动,mysql服务端口是3306,操作如下:
[root@huangzhong support-files]# netstat -tupln |grep 3306
此时可以看服务端口没有启动。然后启动mysql服务:
[root@huangzhong support-files]# service mysqld start
Starting MySQL.............. SUCCESS!
此时可以看到已成功启动,再次查看端口:
[root@huangzhong support-files]# netstat -tupln |grep 3306
tcp 0 0 :::3306 :::* LISTEN 2851/mysqld 表明端口已启动
第十六步:进行mysql连接
首先,进行连接时用到mysql命令,此时发现没有,如下所示:
[root@huangzhong support-files]# mysql
-bash: mysql: command not found
但此命令还是存在且在mysql/bin目录下,用命可以看到如下所示:
[root@huangzhong mysql]# ll bin/
total 538572
-rwxr-xr-x. 1 root mysql 4693522 Nov 18 02:09 innochecksum
-rwxr-xr-x. 1 root mysql 1424 Nov 18 02:08 msql2mysql
-rwxr-xr-x. 1 root mysql 4633764 Nov 18 02:09 my_print_defaults
-rwxr-xr-x. 1 root mysql 6612649 Nov 18 02:09 myisamlog
-rwxr-xr-x. 1 root mysql 6791154 Nov 18 02:09 myisampack
-rwxr-xr-x. 1 root mysql 8952013 Nov 18 02:09 mysql
然后进行改变环境所在文件,进入编辑文件中找到以下:
[root@huangzhong mysql]# vim /etc/profile
52 export HISTCONTROL=ignoredups
53 fi
然后按i进行以下编辑
54 PATH=$PATH:/usr/local/mysql/bin 编辑后按:wq进行保存退出,然后让其重新读取一次,操作如下:
[root@huangzhong mysql]# . /etc/profile
最后进行重新连接,并查看数据库,操作如下:
[root@huangzhong mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.75 sec)
mysql> use mysql;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
28 rows in set (0.00 sec)
此时可以发现任何人都可以连上去,因此这里要设置口令
第十七步:设置口令
首先给管理员设置口令,操作如下:
[root@huangzhong mysql]# mysqladmin -u root -p password ‘123‘
Enter password: (旧密码没有,这里按回车键)
进行验证如下操作:
[root@huangzhong mysql]# mysql
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
通过上面可以看到不能直接进去了,这时就需要口令,如下所示:
[root@huangzhong mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
此时可一看到已经设置成功了。
我们要是其每次重启登陆都可以用,所以还要执行以下命令:
[root@huangzhong mysql]# chkconfig --add mysqld
此时可以进行查看是否加入成功,具体如下:
root@huangzhong mysql]# chkconfig --list |grep mysql
mysqld 0:off1:off2:on3:on4:on5:on6:off
这样整个mysql就安装完了。