CentOS6.4离线安装mysql5.6.22

来源:互联网 发布:导弹拦截 CSDN C语言 编辑:程序博客网 时间:2024/05/16 14:01

我们前面已经记录过一篇Linux系统有网的情况下在线安装的情况。

CentOS6.4安装mysql5.6.14


有一种情况是 linux系统没外网,但是需要安装MySQL,这种情况的话 我们需要把包用其他有外网的机子下载下来传到无外网的linux系统中安装。


详细步骤记录如下:

下载MySQL 安装包

1)http://dev.mysql.com/downloads/mysql/ 打开网址: Select Platform: 选择 Linux-Generic
选择选择 Linux - Generic (glibc 2.5) (x86, 64-bit), RPM   进行下载;
 linux 下下载: wget  http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-5.6.22-1.linux_glibc2.5.x86_64.rpm-bundle.tar
 
2)下载完传到需要离线安装的机子中解压缩并放到安装文件夹下:
tar -xf MySQL-5.6.22-1.linux_glibc2.5.x86_64.rpm-bundle.tar
其中里面要使用的是这两个:
MySQL数据库: MySQL-server-5.6.22-1.linux_glibc2.5.x86_64.rpm
MySQL客户端:MySQL-client-5.6.22-1.linux_glibc2.5.x86_64.rpm

 

MySql安装

1)检查安装
在安装MySQL之前,先检查CentOS系统中是否已经安装了一个MySQL,如果已经安装先卸载,不然会导致安装新的MySQL失败。 
rpm -qa | grep mysql   --查看系统之前是否已安装MySQL。 
mysql-libs-5.1.47-4.el6.i686  显示结果说明 CentOS6.0系统自带了一个MySQL,我们需要删除这个老版本,用root用户执行下面语句

su - 
密码:
rpm -e --nodeps mysql-libs-5.1.47-4.el6.i686  
先切换到"root"用户下,然后执行删除语句,删除之后,我们再次查看,发现已经成功删除了CentOS6.0自带的旧MySQL版本。
在删除MySQL的rpm后,还要进行一些扫尾操作,网上有两种操作。(备注:我在这里两种都没有用到,发现系统中并没有其他残余的MySQL信息。)
第一种善后处理:使用下面命令进行处理。
rm -rf /var/lib/mysql*
rm -rf /usr/share/mysql*
另一种善后处理:卸载后 /var/lib/mysql 中的  /etc/my.cnf 会重命名为 my.cnf.rpmsave,/var/log/mysqld.log 会重命名为 /var/log/mysqld.log.rpmsave,如果确定没用后就手工删除。
 
2)安装MySql 服务端
rpm -ivh MySQL-server-5.6.22-1.linux_glibc2.5.x86_64.rpm 
Preparing... ########################################### [100%] 
1:MySQL-server ########################################### [100%] 
warning: user mysql does not exist - using root 
warning: group mysql does not exist - using root 
2014-08-10 22:43:44 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 
2014-08-10 22:43:44 23012 [Note] InnoDB: Using atomics to ref count buffer pool pages 
2014-08-10 22:43:44 23012 [Note] InnoDB: The InnoDB memory heap is disabled 
2014-08-10 22:43:44 23012 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 
2014-08-10 22:43:44 23012 [Note] InnoDB: Memory barrier is not used 
2014-08-10 22:43:44 23012 [Note] InnoDB: Compressed tables use zlib 1.2.3 
2014-08-10 22:43:44 23012 [Note] InnoDB: Using Linux native AIO 
2014-08-10 22:43:44 23012 [Note] InnoDB: Not using CPU crc32 instructions 
2014-08-10 22:43:44 23012 [Note] InnoDB: Initializing buffer pool, size = 128.0M 
2014-08-10 22:43:44 23012 [Note] InnoDB: Completed initialization of buffer pool 
2014-08-10 22:43:45 23012 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 
2014-08-10 22:43:45 23012 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 
2014-08-10 22:43:45 23012 [Note] InnoDB: Database physically writes the file full: wait... 
2014-08-10 22:43:45 23012 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 
2014-08-10 22:43:46 23012 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 
2014-08-10 22:43:46 23012 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 
2014-08-10 22:43:46 23012 [Warning] InnoDB: New log files created, LSN=45781 
2014-08-10 22:43:46 23012 [Note] InnoDB: Doublewrite buffer not found: creating new 
2014-08-10 22:43:46 23012 [Note] InnoDB: Doublewrite buffer created 
2014-08-10 22:43:46 23012 [Note] InnoDB: 128 rollback segment(s) are active. 
2014-08-10 22:43:46 23012 [Warning] InnoDB: Creating foreign key constraint system tables. 
2014-08-10 22:43:47 23012 [Note] InnoDB: Foreign key constraint system tables created 
2014-08-10 22:43:47 23012 [Note] InnoDB: Creating tablespace and datafile system tables. 
2014-08-10 22:43:47 23012 [Note] InnoDB: Tablespace and datafile system tables created. 
2014-08-10 22:43:47 23012 [Note] InnoDB: Waiting for purge to start 
2014-08-10 22:43:47 23012 [Note] InnoDB: 5.6.22 started; log sequence number 0 
A random root password has been set. You will find it in '/root/.mysql_secret'. 
2014-08-10 22:43:48 23012 [Note] Binlog end 
2014-08-10 22:43:48 23012 [Note] InnoDB: FTS optimize thread exiting. 
2014-08-10 22:43:48 23012 [Note] InnoDB: Starting shutdown... 
2014-08-10 22:43:50 23012 [Note] InnoDB: Shutdown completed; log sequence number 1625977 
2014-08-10 22:43:50 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 
2014-08-10 22:43:50 23039 [Note] InnoDB: Using atomics to ref count buffer pool pages 
2014-08-10 22:43:50 23039 [Note] InnoDB: The InnoDB memory heap is disabled 
2014-08-10 22:43:50 23039 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 
2014-08-10 22:43:50 23039 [Note] InnoDB: Memory barrier is not used 
2014-08-10 22:43:50 23039 [Note] InnoDB: Compressed tables use zlib 1.2.3 
2014-08-10 22:43:50 23039 [Note] InnoDB: Using Linux native AIO 
2014-08-10 22:43:50 23039 [Note] InnoDB: Not using CPU crc32 instructions 
2014-08-10 22:43:50 23039 [Note] InnoDB: Initializing buffer pool, size = 128.0M 
2014-08-10 22:43:50 23039 [Note] InnoDB: Completed initialization of buffer pool 
2014-08-10 22:43:50 23039 [Note] InnoDB: Highest supported file format is Barracuda. 
2014-08-10 22:43:50 23039 [Note] InnoDB: 128 rollback segment(s) are active. 
2014-08-10 22:43:50 23039 [Note] InnoDB: Waiting for purge to start 
2014-08-10 22:43:50 23039 [Note] InnoDB: 5.6.22 started; log sequence number 1625977 
2014-08-10 22:43:50 23039 [Note] Binlog end 
2014-08-10 22:43:50 23039 [Note] InnoDB: FTS optimize thread exiting. 
2014-08-10 22:43:50 23039 [Note] InnoDB: Starting shutdown... 
2014-08-10 22:43:52 23039 [Note] InnoDB: Shutdown completed; log sequence number 1625987 
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER ! 
You will find that password in '/root/.mysql_secret'. 
You must change that password on your first connect, 
no other statement but 'SET PASSWORD' will be accepted. 
See the manual for the semantics of the 'password expired' flag. 
Also, the account for the anonymous user has been removed. 
In addition, you can run: 
/usr/bin/mysql_secure_installation 
which will also give you the option of removing the test database. 

This is strongly recommended for production servers. 
See the manual for more instructions. 
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 
New default config file was created as /usr/my.cnf and 
will be used by default by the server when you start it. 
You may edit this file to change server settings 


3)检测 MySQL 3306 端口是否安打开。测试是否成功可运行 netstat 看 MySQL 端口是否打开,如打开表示服务已经启动,安装成功。MySQL 默认的端口是3306。
[root@Hadoop Mysql]# netstat -nat  
Active Internet connections (servers and established) 
Proto Recv-Q Send-Q Local Address Foreign Address State 
tcp 0 0 0.0.0.0:50070 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:50010 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:50075 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:50020 0.0.0.0:* LISTEN 
tcp 0 0 192.168.128.129:9000 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:50090 0.0.0.0:* LISTEN 
tcp 1 0 192.168.128.129:35744 63.130.76.64:80 CLOSE_WAIT 
tcp 0 0 192.168.128.129:34847 192.168.128.129:9000 ESTABLISHED 
tcp 0 0 192.168.128.129:35770 192.168.128.129:9000 TIME_WAIT 
tcp 0 52 192.168.128.129:22 192.168.128.1:1297 ESTABLISHED 
tcp 0 0 192.168.128.129:50968 61.135.185.247:80 ESTABLISHED 
tcp 0 0 192.168.128.129:9000 192.168.128.129:34847 ESTABLISHED 
tcp 0 0 :::34803 :::* LISTEN 
tcp 0 0 :::22 :::* LISTEN 
tcp 0 0 ::1:631 :::* LISTEN 
tcp 0 0 :::8088 :::* LISTEN 
tcp 0 0 :::13562 :::* LISTEN 
tcp 0 0 :::8030 :::* LISTEN 
tcp 0 0 :::8031 :::* LISTEN 
tcp 0 0 :::8032 :::* LISTEN 
tcp 0 0 :::8033 :::* LISTEN 
tcp 0 0 :::8040 :::* LISTEN 
tcp 0 0 :::8042 :::* LISTEN 
tcp 0 0 ::ffff:192.168.128.129:8031 ::ffff:192.168.128.12:58051 ESTABLISHED 
tcp 0 0 ::ffff:192.168.128.12:58051 ::ffff:192.168.128.129:8031 ESTABLISHED 
 
4)启动MySql 服务
[root@hadoop Mysql]# service mysql start   
Starting MySQL.......... SUCCESS! 
 
5) 安装客户端
[root@hadoop Mysql]# rpm -ivh MySQL-client-5.6.22-1.linux_glibc2.5.x86_64.rpm
Preparing...                ########################################### [100%]
1:MySQL-client           ^C########################################### [100%]   安装完成

到这里就安装完成了。 



需要了解的信息和可能遇到的错误

5)MySQL的几个重要目录。
MySQL安装完成后不像 SQL Server 默认安装在一个目录,它的数据库文件、配置文件和命令文件分别在不同的目录,了解这些目录非常重要,尤其对于Linux的初学者,因为 Linux本身的目录结构就比较复杂,如果搞不清楚MySQL的安装目录那就无从谈起深入学习。
a、数据库目录     /var/lib/mysql/ 
b、配置文件     /usr/share/mysql(mysql.server命令及配置文件) 
c、相关命令    /usr/bin(mysqladmin mysqldump等命令) 
d、启动脚本   /etc/rc.d/init.d/(启动脚本文件mysql的目录) 
如:/etc/rc.d/init.d/mysql start/restart/stop/status
 
6)更改 MySQL 目录。由于MySQL数据库目录占用磁盘比较大,而MySQL默认的数据文件存储目录为 /"var/lib/mysql",也可以把要把数据目录移到 "/" 根目录下的 "mysql_data" 目录中(如果做测试用就不用移动了)。
 
停止 MySql 服务进程:service mysql stop  或者  mysqladmin -u root -p shutdown
MySQL默认用户名为"root",此处的"root"与Linux的最高权限用户"root"不是一会儿,而且默认的用户"root"的密码为空,所以上图中让输入密码,直接点击回车即可。
把 "/var/lib/mysql" 整个目录移到 "/mysql_data"
mv /var/lib/mysql /mysql_data
 
找到my.cnf配置文件
如果"/etc/"目录下没有my.cnf配置文件,请到 "/usr/share/mysql/" 下找到 my-default.cnf  文件,拷贝其中一个合适的配置文件到 "/etc/" 并改名为 "my.cnf" 中。命令如下:
cp /usr/share/mysql/my-medium.cnf  /etc/my.cnf
 
 
编辑MySQL的配置文件 "/etc/my.cnf" 为保证MySQL能够正常工作,需要指明"mysql.sock"文件的产生位置,以及默认编码修改为UTF-8。用下面命令:
vim /etc /my.cnf
[mysqld] #下添加以下命令
socket = /var/lib/mysql/mysql/mysql.sock
datadir=/mysql_data/mysql   #如果你的数据存储位置要改变的话需要在这里指定存储目录
character-set-server=utf8
 


lower_case_table_names=1  
#(注意linux下mysql安装完后是默认:区分表名的大小写,不区分列名的大小写;#  lower_case_table_names = 0    0:区分大小写,1:不区分大小写)
注意:
1)最后一行,我在本地安装的时候没有添加此设置也可以照样运行起来,加不加还要看你们自己了。
2)还有在此配置文件还有 [client] 的一下配置 其中也可以设置 socket ,datadir 两个选项,我这里也没有(此处不做配置,因为只是安装 MySql 测试用),不知道是版本的原因还是什么,如果大家需要弄清楚这个怎么使用,那就自己先百度一下吧;
3)如果你修改了数据的存储位置目录 ,则可以执行以下命令来修改MySQL启动脚本 "/etc/rc.d/init.d/mysql"  
最后,需要修改MySQL启动脚本 /etc/rc.d/init.d/mysql,修改 datadir=/mysql_data/mysql。 
vim /etc/rc.d/init.d/mysql
 
7)重新启动MySQL服务 
service mysql start
发生错误:Starting MySQL ERROR! The server quit without updataing PID file....
经百度后解决方法是:
vi  /etc/selinux/config
把 SELINUX=enforcing 改为 SELINUX=disabled 后存盘退出重启机器试试,必须要重启,很关键。
 
千辛万苦重启后盼望着能管用,结果 服务器启动不了了。。。。。
显示错误:Kernel panic - not syncing: Attempted to kill init  

 
经过百度又找到新的解决文案:解决办法 
系统启动的时候,按下 ‘e’ 键进入 grub 编辑界面,编辑 grub 菜单,选择 “kernel /vmlinuz-2.6.23.1-42.fc8 ro root=/dev/vogroup00/logvol00 rhgb quiet”  一栏,按‘e’键进入编辑,在末尾增加enforcing=0,即:
kernel /vmlinuz-2.6.23.1-42.fc8 ro root=/dev/vogroup00/logvol00 rhgb quiet enforcing=0
按‘b’键继续引导,OK顺利前进。
 
好吧终于顺利进入到 Linux 系统,启动MySQL 服务:
service mysql start
又提示错误:MySQL: Starting MySQL….. ERROR! The server quit without updating PID file解决办法
是因为 MySQL 没有初始化表
/usr/bin/mysql_install_db --user=mysql
service mysql start 就可以重启MySQL 服务了。
 

 
8)修改登录密码
MySQL默认没有密码,安装完毕增加密码的重要性是不言而喻的。修改前,直接登录
检查 MySql 端口是否开启:
[root@Hadoop ~]#netstat -ntlp  | grep 3306
tcp        0      0 :::3306                     :::*                        LISTEN      5052/mysqld  
 
$:mysql
报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
发现 与设置 MySql 服务器的 socket 位置不一样。改一下 /etc/my.cn
修改 
socket = /var/lib/mysql/mysql.sock   --保存;
 
再次进入:
[root@hadoop init.d]# mysql 
又报错。。。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
百度一下解决方法:
[root@hadoop ~]#mysqld_safe --user=mysql --skip-grant-tables --skip-networking &  mysql -u root mysql
 
再次进入:
[root@hadoop ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.22 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2014, 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> 
OK 了总算安装成功了。。。
 
在没有添加密码前,直接输入"mysql"就能登录到MySQL数据库里。 修改登录密码:
[root@hadoop ~]mysqladmin -u root password 'root'
格式:mysqladmin -u用户名 -p旧密码 password 新密码 
 
如果已经连接上了 MySql 可以使用下面语句 :
mysql> use mysql; 
mysql> UPDATE user SET Password=PASSWORD('root') where USER='root';
Query OK, 4 rows affected (0.04 sec)
Rows matched: 4  Changed: 4  Warnings: 0

修改成功


mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决方法:

首先停掉mysql服务器

[root@DB-Server init.d]# /etc/rc.d/init.d/mysql stop
 
 Shutting down MySQL..[ OK ]
 

然后使用mysqld_safe命令在启动mysql,更新root账号的密码

--skip-grant-tables:不启动grant-tables(授权表),跳过权限控制。

--skip-networking :跳过TCP/IP协议,只在本机访问(从网上有些资料看,这个选项不是必须的。可以不用)

[root@DB-Server init.d]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[2] 9396
[root@DB-Server init.d]# 140722 14:59:46 mysqld_safe Logging to '/var/lib/mysql/DB-Server.err'.
140722 14:59:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

执行上面命令后,此会话窗口会出现无反应的状态,需要使用CTRL+C中断会话,检查/var/lib/mysql/DB-Server.err日志,发现也无其它异常信息。没有弄明白该会话窗口为啥会出现无响应状态。

tail -200 /var/lib/mysql/DB-Server.err | more
 
2014-07-22 14:59:41 9346 [Note] Shutting down plugin 'binlog'
2014-07-22 14:59:41 9346 [Note] /usr/sbin/mysqld: Shutdown complete
 
140722 14:59:41 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended
140722 14:59:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2014-07-22 14:59:47 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timesta
mp server option (see documentation for more details).
2014-07-22 14:59:47 9516 [Note] Plugin 'FEDERATED' is disabled.
2014-07-22 14:59:47 9516 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-07-22 14:59:47 9516 [Note] InnoDB: The InnoDB memory heap is disabled
2014-07-22 14:59:47 9516 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-07-22 14:59:47 9516 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-07-22 14:59:47 9516 [Note] InnoDB: Using Linux native AIO
2014-07-22 14:59:47 9516 [Note] InnoDB: Using CPU crc32 instructions
2014-07-22 14:59:47 9516 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-07-22 14:59:47 9516 [Note] InnoDB: Completed initialization of buffer pool
2014-07-22 14:59:47 9516 [Note] InnoDB: Highest supported file format is Barracuda.
2014-07-22 14:59:47 9516 [Note] InnoDB: 128 rollback segment(s) are active.
2014-07-22 14:59:47 9516 [Note] InnoDB: Waiting for purge to start
2014-07-22 14:59:47 9516 [Note] InnoDB: 5.6.19 started; log sequence number 1626087
2014-07-22 14:59:47 9516 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.6.19'  socket: '/var/lib/mysql/mysql.sock'  port: 0  MySQL Community Server (GPL)

clip_image002

[root@DB-Server init.d]# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.19 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2014, 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> select Host, User, Password,password_expired
    -> from user
    -> where user='root' and host='root' or host='localhost';
+-----------+------+-------------------------------------------+------------------+
| Host      | User | Password                                  | password_expired |
+-----------+------+-------------------------------------------+------------------+
| localhost | root | *A848DE7CCD839E924921BEE41711991DDA0D529E | Y                |
+-----------+------+-------------------------------------------+------------------+
1 row in set (0.00 sec)
 
mysql> update user set password=PASSWORD('p12#456')
    -> where user='root' and host='root' or host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效。

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> quit
Bye
[root@DB-Server init.d]# /etc/rc.d/init.d/mysql restart
Shutting down MySQL..140722 15:02:27 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended
[  OK  ]
Starting MySQL.[  OK  ]
[2]-  Done                    mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[root@DB-Server init.d]# mysql -u root p
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@DB-Server init.d]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.19
 
Copyright (c) 2000, 2014, 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> 

另外,如果登录mysql数据库后执行脚本遭遇 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement,可以使用重新设置一次密码即可解决问题.

mysql>set password = password('p12#456'); 


原创粉丝点击